Friday, May 22, 2009

Gem to send mails through Gmail

I made this little gem, gmail_sender that I find useful to log things when I'm running some script in my VPS, I use it for things like this:

require 'rubygems'
require 'gmail_sender'

g = GmailSender.new("gmail_account", "password")
begin
#Some interesting script that returns some interesting results in script_results
g.send("dcadenas@gmail.com", "It worked!", script_results.to_yaml)
rescue => e
g.send("dcadenas@gmail.com", "It didn't work :(", "#{e.message}\n#{e.backtrace}")
raise e
end


So all you need to pass to the send method is an email address, the subject and the email content.


Source code is here and you can install it with sudo gem install dcadenas-gmail_sender (remember to add github to your rubygems sources).

Some useful bash functions

I use this bash functions to open vim with splits for each file in which grep or rak find the pattern I'm searching for:

grepvim(){
grep -rl "$1" $2| xargs mvim -o +/"$1"
}

rakvim(){
rak -l "$1" $2| xargs mvim -o +/"$1"
}

Monday, April 20, 2009

Tunneling through SSH

To tunnel through ssh do:
ssh -v -nNT4 -R :4007:localhost:3000 linode


which maps the remote port 4007 to the local port 3000.linode is the host you want to connect to which should be properly configured in your ssh config.

Tuesday, March 10, 2009

Joined ENTP!

Oh I just realized that I never wrote a post about me joining ENTP 4 months ago!!
I'm thrilled about this great chance I'm having working with some of the most talented Ruby developers the world has to offer and I wish that osmosis does its magic and maybe I get at least some tiny part of their mojo. I'm really happy!

RSpec fun

So I was there, running a huge and slow rspec test suite on my Mac and thought "god, I wish I could make it run faster just by tilting my laptop right and make those damn dots fall" so... the most awesome rspec optimization was born :p

Friday, December 12, 2008

Capistrano and Git problems

If you get this error when deploying with Capistrano:

ERROR:gitosis.serve.main:Repository read access denied

You may solve it with:

ssh-add ~/.ssh/id_rsa


This is needed because my ssh config is configured to forward my identity to the deployment machine (with ForwardAgent yes) so the ssh agent must know my private key.

Sunday, October 19, 2008

Recursively replace all files with tabs in Linux

Ok I don't want to forget this ever again so I will write it here.

sed 's/ //g' `find -type f`

  • Note I'm using both the grave accent "`" and the apostrophe "'". "`" is used to create a special kind of shell escape that substitutes each line of the output in the place you inserted it. So sed will be called once for each file found by find.
    It's the same as doing manually:

    sed 's/ //g' ./file1.txt
    sed 's/ //g' ./file2.txt
    sed 's/ //g' ./dir/file2.txt
    .
    .
    .

  • To type the tab inside the sed regexp hit ctrl-v and then the tab key.
  • find -type f will show in each line the path of each file recursively.