Vim: Inserting Blank Line, Preserving AutoIndent

This is the I way do it in my .vimrc file:

nmap <C-L> o<SPACE><BS><ESC>

So if you are in normal mode, type <C-L> a couple of times. You end up staying in normal mode, allowing you other commands like 'p', 'a', etc.

I avoid 'o' + <CR> because they don't preserve autoindent space after you hit <ESC> or <CTRL-O>. I also could not get <CTRL-\ CTRL-O> to work the way I wanted to.

Filed under  //  vim  
Comments (0)
Posted 2 days ago

Using Ruby 1.8.7 features on Heroku

As of today, you can only use Ruby 1.8.6 on Heroku. However...

You can use Ruby 1.8.7 features on heroku by requiring 'backports' (see http://github.com/marcandre/backports ). It also enables many of Ruby 1.9 features.

 

Filed under  //  heroku  
Comments (0)
Posted 10 days ago

Ruby 1.9: Understanding M17n, Unicode, $KCODE, jcode, Character Encodings, etc...

[The] start of a new series of blog articles designed to explain the character encoding support in Ruby 1.9. I'm going to assume you know absolutely nothing about character encodings though and begin by explaining in detail what they are and why we have them.

Read the entire series at: http://blog.grayproductions.net/articles/understanding_m17n

UPDATE:

The series is fantastic. Even if you don't use Ruby, it's still a great introduction to Unicode, character sets, and character encodings. Here is a shortcut in case you get stuck: Once you know the difference between "character sets" vs. "character encodings", everything else is super-simple to understand.

Comments (0)
Posted 12 days ago

Reloading Ruby Rack Apps (using Unicorn + Rush)

First, learn and use Unicorn to run your Rack apps.

Then, install the Rush gem:

gem install rush

Then, in a Rake task (or something similar):

require 'rush'
Rush.processes.filter( :cmdline=>/unicorn worker/ ).kill

 

Comments (0)
Posted 21 days ago

Sockets vs. HTTP

I was trying to get Nginx to work with Unicorn. This question popped up: Why not let Nginx communicate with Unicorn using HTTP instead of a socket?

The answer: Because a socket has less overhead than HTTP.  Anyways, here is more info. if you are new to UNIX sockets and the HTTP protocol:

HTTP is a protocol that runs on a socket.
A socket is what is used to transport data between systems.
...
basicaly creating your own socket the application is more pure... no web server stuff... less to fail

From: http://www.phpfreaks.com/forums/index.php/topic,258737.msg1217516.html#msg1217516

Here is another comment from the same forum that sounded like something fun to know:

But using HTTP as a protocol in your application would be absurd unless
you are making a web server. It is by far easier to make your *own*
protocol, believe me this is *not* hard, I'm actually making a set of
classes for VB.NET at the moment which make designing your own protocol a
piece of cake. Get into Netlinx, AMX and Crestron then you will understand
all about protocols, including how to rip them off.

From: http://www.phpfreaks.com/forums/index.php?topic=258737.msg1217532#msg1217532

No wonder why Zed Shaw recommends playing with protocols for fun, educational purposes.

 

Filed under  //  http   sockets  
Comments (0)
Posted 1 month ago

Getting CouchDB 0.10 to work for web dev. on Ubuntu "Karmic" 9.10

Even though Ubuntu Karmic Koala comes with the couchdb executable already installed, you still have to do "sudo aptitude install" to install the full package to use it for web development. You also have to create a special dir as a workaround for a bug. Here are the full steps:

sudo aptitude install couchdb
sudo su
mkdir /var/log/couchdb/0.10.0
chown couchdb:couchdb /var/log/couchdb/0.10.0
exit
sudo -i -u couchdb couchdb -b

The last line is to run couchdb as a special user role called, "couchdb", which has limited privileges.  The second part of the line, "couchdb -b", is the actual command being executed by the user, "couchdb", to run CouchDB in a background process. You kill the CouchDB process by using "-d" instead of "-b":

sudo -i -u couchdb couchdb -d

After all that, open your brower to: http://127.0.0.1:5984/

You should see:

{"couchdb":"Welcome","version":"0.10.0"}

Full info. at: https://bugs.launchpad.net/ubuntu/+source/couchdb/+bug/453049

Sidenote:  Looking to see how amazing CouchDB really is? Take a look at some examples: http://www.jasondavies.com/blog/tags/couchdb/

Filed under  //  couchdb  
Comments (0)
Posted 1 month ago

Reduce and Rereduce for beginning CouchDB users.

If you are reading the chapter on views in "CouchDB: The Definitive Guide" and get confused with reduce/rereduce, read the CouchDB docs instead to understand:

http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#reduce_functions

(Thanks to Chris Strom for this tip.)

Filed under  //  couchdb  
Comments (0)
Posted 1 month ago

Vim: Display commands as you type them (in command mode)

I have no idea why it took me so long to find this in Google. Anyways, here it is.

From: http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl#19.11

19.11. How do I configure Vim to show pending/partial commands on the
status line?

You can set the 'showcmd' option to display pending/partial commands in the
status line:

:set showcmd

For more information, read

:help 'showcmd'

 

Comments (0)
Posted 2 months ago

Markdown vs. Textile

There are good uses for each. Markdown is great for plain text documents that are to be read as plain text and might be converted to HTML, but Textile works better for me as a shortcut to HTML (not published plain-text). I have my reasons for preferring Textile but I can see both sides.

Try out Textile formatting online. No install required: http://www.textism.com/tools/textile/

For Ruby users, try out RedCloth.org. :

RedCloth 4 was a total rewrite that brought it back to its Textile roots, fixed a lot of bugs, and made it roughly 40x faster.

However, it will never be 100% compatible with the PHP implementation. Try it out online, no install: http://redcloth.org/try-redcloth/
One of the differences RedCloth has is that it does not add width/height HTML attributes to IMG elements the way the Textism/PHP does automatically.

Comments (0)
Posted 2 months ago

When capturing $stderr (and $stdout) does not work.

This blog post is excellent: http://tech.natemurray.com/2007/03/ruby-shell-commands.html

It describes all the different ways to execute code in a sub-process. It also goes into the Open4 gem which should be Win32 compatible.

More examples:

The docs for Open3: http://www.ruby-doc.org/stdlib/libdoc/open3/rdoc/classes/Open3.html

However, another option is using the gem, "Rush":

box = Rush::Box.new
begin
    box.bash "git commit -m 'changes'"
rescue Rush::BashFailed => e
    puts "Failed to commit, reason: #{e.message}"
end

(For some reason it fails using "git status" in a valid git repository. )
More info.: http://rush.heroku.com/handbook/bash

Comments (0)
Posted 2 months ago