May 25, 2012
Git SVN integration quick tip

When you’re using git-svn integration, it’s common that you need to ignore a lot of files, so you might think of using .gitignore.

That’s fine, but you shouldn’t push the .gitignore itself into the original repository, so you shouldn’t include it in your commits. The solutions I found for this are:

  1. Include .gitignore in .gitignore itself! That works, and feels awkward at the same time.

    .gitignores down

  2. Use .git/info/exclude that works like a .gitignore that isn’t versioned, for the local repository only.

The second solution is a lot better. I heard about it here and here.

May 11, 2012
Separate letters of a String in an Array of chars in Ruby

In order to separate the letters of a String and create an Array of chars in Ruby I usually used split(//). The empty regular expression does the trick of matching each letter, as following:

1.9.3-head :002 > 'hello, world'.split(//)
 => ["h", "e", "l", "l", "o", ",", " ", "w", "o", "r", "l", "d"]

Today, I thought about using each_char.to_a to achieve the same goal:

1.9.3-head :003 > 'hello, world'.each_char.to_a
 => ["h", "e", "l", "l", "o", ",", " ", "w", "o", "r", "l", "d"] 

The result is the same, but which is faster? Probably the later, because it doesn’t invoke the regular expression engine.

After a quick test, this intuition was quickly proved true.


I used split(//) all over the place! Good to know that the alternative each_char.to_a is faster, even though it’s more verbose. I’ll prefer it whenever I’m not golfing.

May 10, 2012
Rubeque

Rubueque is a great place to practice your Ruby skills. It’s a website with small problems that one can solve online.

It’s a kind of Ruby Koans for the lazy :P

Rubeque

May 4, 2012
Have multiple hosts files and change between them!

I’ve just polished and released a solution I’ve made to manage multiple hosts files.

You should have a look at it here.

May 4, 2012
Using nginx to serve development app on real domain

When running an app on localhost, usually it’s served in developer mode, using ports such as 9393 or 3000. Then, to test on the browser, one has to access http://localhost:9393 or http://localhost:3000.

This is fine, but what if you want to test the application using the real domain and port, such as http://your-web-site.com? Maybe because it follows bad practices and hard code the url (it’s legacy code, you wouldn’t do that, of course!), or you’re just felling like it.

The trick can easily be achieved using nginx or Apache to proxy the requests. nginx is faster and lately it’s being preferred by developers, so I’ll use it in examples.

Three simple steps

  1. Install nginx. If you’re in an Ubuntu box: sudo apt-get install nginx.
  2. Configure nginx to respond on port 80 (which is http default) and proxy to your app.

    • Install the new configuration:

    • Enable it: sudo ln -sf /etc/nginx/sites-available/your-web-site.com /etc/nginx/sites-enabled/your-web-site.com

    • Then restart nginx with: sudo service nginx restart.

  3. Configure your hosts file to point to the domain to your own machine, so that your browser reaches the nginx instance running on your machine:

Of course, remember to change both domain and port numbers in these examples.


Now you’re good to go, try it out pointing your browser to http://your-web-site.com!

You can always run more than one app at a time, just keep adding rules to your nginx instance and hosts file.

You should comment the lines in the hosts file in case you want to use again the real app in production.


Update

Managing multiple hosts files and cycle between them can be a pain. So I just open-sourced my solution to this issue.

Check it out here.

April 30, 2012
Great presentation on extending Ruby with Ruby itself

April 24, 2012
GitHub ❤ ~/

April 24, 2012
Vim plugin of the day: Ctrlp (Command-t replacement)

ctrlp

One thing that bothered me on my dotfiles was the install steps for Command-t. It was a great plugin, but ultimately I had to install Ruby 1.8.7 only to satisfy it’s needs.

That’s no longer the case, I just find out about ctrlp. The switch was easy and pleasant, you should take a look right now. If for no other reason, because it’s fast and entirely written in Vimscript, no separate compilation is needed!

Neat :)

April 24, 2012
Nice idea

April 24, 2012

Liked posts on Tumblr: More liked posts »