The Blog

Posts from May 2010

May 25

My Rails dev environment

By Brian Corrigan

I love reading about the way people set up their development environments. I recently started working on a new project at work and had to set everything up from scratch. Here’s my setup.

First, install some gems.

# On all systems
sudo gem install ZenTest
sudo gem install redgreen
sudo gem install autotest-rails
sudo gem install shoulda
sudo gem install factory_girl

# Only on my OSX machine
sudo gem install autotest-growl
sudo gem install autotest-fsevent

# Only on my Ubuntu machine
sudo gem install test_notifier
sudo apt-get install libnotify-bin

Next, I setup my ~/.autotest file:

require 'redgreen/autotest'
require 'autotest/timestamp'
require "autotest/restart"

#Only Ubuntu
require "test_notifier/autotest"

#Only OSX
require "autotest/growl"
require 'autotest/fsevent'

# All machines
Autotest.add_hook :initialize do |autotest|
  %w{.git .svn .hg .DS_Store ._\* vendor tmp log doc}.each do |exception|

Also, I really like git instaweb. I sent it to G, our brilliant (ex)intern and he likes it too. To start it I use:

git instaweb -d webrick --start

You can automate this by adding the following to your ~/.gitconfig:


You can also add a port option (port=8000) if you want.

Also, to stop instaweb, from the git repo that you started instaweb from run:

git instaweb stop

Finally, I tend to branch a lot and store them server-side. I like tracking branches to automatically push/pull changes to a branch from a remote repository. All this really does is add a few lines to your .gitconfig, but hey, who doesn’t like a shortcut.

git branch --track branch remote

Last but not least, the Cheat gem is awesome. It’s like man, but distilled to the things you’ll actually use. (It’s actually where I read about instaweb) Use it!

sudo gem install cheat

So in general, that’s the interesting bits of my environment. How about yours?

May 17

Browsers and Status: 204

By Jason LaPorte

Trivia: The HTTP RFC asks browsers to NOT update the browser page when 204 status codes are received.

Holy crap is this visually confusing; even Firebug returns nothing! That said, it’s a perfect example of why performing only in-browser testing fails miserably. Functional tests.. use em!

May 13

Ruby Reversible Encryption

By An Engineer

It’s been awhile since I had to do anything with reversible encryption. Here’s a working sample using AES.

require 'openssl'
require "base64"
require 'uri'

# First lets encrypt the string!
plaintext = 'Super secret message'

# Create the cipher
cipher ="aes-256-cbc")
cipher.encrypt # Tell OpenSSL to operate in encrypt mode
puts "Cipher wants a key that is #{cipher.key_len}"
key = '01234567890123456789012345678901'
cipher.key = key

puts "Cipher wants an initialization vector that is #{cipher.iv_len}"
cipher.iv = iv = cipher.random_iv # Create and set a random initialization vector

# Encrypted
encrypted = cipher.update(plaintext) +
encrypted = iv + encrypted # Send along the IV

# Lets pretty up the encrypted string
encrypted = Base64.encode64(encrypted)
#encrypted = URI.escape(encrypted,"[^#{URI::PATTERN::UNRESERVED}]"))
encrypted = URI.escape(encrypted)

# Now lets unencrypt it, first start with a new cipher
cipher ="aes-256-cbc")
cipher.decrypt # Use SSL in decrypt mode
cipher.key = key
encrypted = URI.unescape(encrypted)
encrypted = Base64.decode64(encrypted)
cipher.iv = encrypted.slice!(0,16) # Remove the IV from the encrypted data
decrypted = cipher.update(encrypted) +

# Test
puts 'The original was '+ plaintext
puts 'Encrypted that was ' + encrypted
puts 'Decrypted we have ' + decrypted