Ruby

http://s.erious.ly

Rail Spikes

Rails 2.3.3 upgrade notes: rack, mocha, and _ids

I upgraded two apps to Rails 2.3.3 today. It’s a minor release, and there’s not much to report. But I did run into three minor problems. Mocha Mocha 0.9.5 started throwing an exception: NameError: uninitialized constant Mocha:...

validates_length_of byte counting gotcha

Watch out for validates_length_of if you need to make sure a string is a certain number of bytes long. For example, SMS messages can be no longer than 160 bytes in length. I recently got bit by this because some unicode “curly” quotes...

FutureRuby!

Jon and I will be at FutureRuby this weekend (actually, I will be there, and Jon will be speaking). Say “hi” if you see us. I’m flying into Toronto Thursday for FAILcamp.

Testing HTTP Authentication

If you ever need to test HTTP Authentication in your functional tests, here is how you do it: 1 2 3 4 5 6 def test_http_auth @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(&quo...

Adding Routes for Tests

I like to be extremely judicious with use of routes. Fewer routes means less memory consumption and fewer confusing magical methods. I always delete the default route map.connect ':controller/:action/:id' (you should too, otherwise all ...

JavaScript gotcha: storing objects in an associative array

I just ran into a tricky gotcha in JavaScript. I was trying to store some objects in an associative array. Based on my experience with Java, Ruby, and other languages, I expected that given code like this: 1 2 3 4 5 6 7 var dict...

Sprinkle: the provisioning tool for people who don’t have huge server clusters

I’ve recently been trying to find a good server automation tool that meets my needs. I looked at Chef and Puppet. They are both awesome for what they do, but what I don’t like is all the infrastructure I have to maintain to run...

Estimating software: a rule of thumb

Estimating software is hard, but most of us have to do it – whether we’re estimating an entire project for a client, or a new feature for a boss, or a change to one of our own projects. I’ve found the following rule...

Announcing VeloTweets, Pulse of the Peloton

I’m pleased to announce VeloTweets, the pulse of the peloton, a curated collection of professional cycling Twitter activity. The idea and driving force came from Jamie Thingelstad. I did most of the development, and Norm Orstad designed...

Music and programming: interviews with Chad Fowler and Dave Thomas

I’ll be speaking at RailsConf 2009 this year on music and software development (Five musical patterns for programmers). The basic premise is that software development and music actually have quite a bit in common. This may be surprising ...

Anonymize sensitive data with rake

When troubleshooting a nasty bug, it’s often useful to take a look actual production or staging data, or even pull it down into your development database. But this is a huge potential privacy and security concern. Your local environment ...

Benchmarking your Rails tests (updated)

Update: stubbing a single integration point shaved 22 seconds off of my unit tests, reducing test time from 35 seconds to 13. See below. The first step to faster tests is knowing what is slow. Fortunately, this is dead simple with the t...