Archive for September, 2008

The sublime joy of bug-fixing

Friday, September 26th, 2008

Find a bug. Write a test to reproduce it. Fix it. Watch the test pass. Check in the changes.

Realize you’re one step closer to perfection.

How to reload a class in irb

Tuesday, September 16th, 2008

I’m working interactively in irb, and I tweak the class to make changes. The changes won’t be reflected in the irb session unless you reload the class.


irb >> load 'document.rb'

Make sure to add the file extension. Unlike require, load needs the full filename.

Stack Overflow is pretty impressive

Tuesday, September 16th, 2008

Jeff Atwood and team have built a new product called Stack Overflow, a question and answer site for programmers. It’s very early, but I think it will be successful. It’s certainly been useful for me.

For Serendeputy, I’m building an index of articles relevant to me, and I need to be able to generate a unique id based on the url. I experimented with (what appeared to be) the obvious solution, but it wasn’t working. So, I asked the question: “What’s the best way to hash a url in Ruby?” Within three minutes, I got a useful answer. By morning, I received three answers, with the best answer sorted to the top.

This is incredibly useful. I have a stack of Ruby books at my desk, and I’m often flipping through them trying to find a specific answer. I generally know *what* I’m trying to accomplish; I’m just lost on the syntax and the proper Ruby idiom to use. If my experience is typical, then Stack Overflow is a very useful supplement to these references.

Stack Overflow has a ton of Google juice already. My question is number one for the relevant search query: hash a url ruby. Most of the time when I do a Google search for specific questions, I get links to the Ruby documentation (which I already have) and a decent amount of off-topic spam. If Stack Overflow gets a critical mass of specific questions with canonical answers, then Google will become much more useful for everyone.

I’m very impressed with how they’ve focused on the customer experience. I’m trying to keep the same ideals with my project. Unlike those folks at that annoying site, they have everything open and clean. They have advertising, but it’s inobtrusive. And, the value of the product was so high that I actually made a point of looking at the advertising, seeing that an advertiser who’s associating with this useful an application is probably worth checking out. It’s amazing what optimizing for the customer experience will do for you.

It reminds me of how I felt in 1999 when I switched from Alta Vista to Google.

One quibble: Requiring people to get an OpenId is a mistake. Everyone in their target market has a simple throwaway handle/password combination that they use on all these sites. Unless it’s a pragmatic choice — they don’t have to program the authentication module — I think it’s a mistake to go against the grain of what people expect for these sites. Requiring an OpenId dissuaded me from registering; I just posted as a guest.

Progress update - 9/15/08

Monday, September 15th, 2008

It’s been a productive couple of weeks here at Serendeputy world headquarters. I have been heads-down trying to build the private alpha version of the site — i.e., get it running end to end on my own machine.

I hope to be able to have the private alpha done by the end of September, with an incredibly limited wider alpha by October 15th or so. I hope that it doesn’t take me two weeks to get the deployment and hosting issues squared away, but this is the weakest part of my game, so I’m trying to give myself plenty of time to get that part right.

The rails application is largely built, and the catalog application is coming along quickly. The hard part is maintaining the discipline to keep writing the tests and automating the admin pieces of the application. I keep wanting to jump ahead and build out some of the sexier features. It’s sometimes not a lot of fun being a grown up.

If you’re interested in taking an early look at the application, drop me a line, and I’ll make sure I send you the information when it’s somewhere publicly accessible.

The blog will probably be dark for a couple more weeks as I finish this sprint. The world grieves.

How to test tag attributes using assert_select

Wednesday, September 10th, 2008

There’s undoubtedly a smarter way to do this, but I couldn’t figure it out. I’m doing a functional (controller) test for one of my rails pages. I want to make sure that the picture coming back is exactly 224 pixels high.

I couldn’t find a way to do this using the assert_select syntax, but this workaround seems to work:


  def test_picture_height
    assert_select "div.secondary div.lead_picture img[height]" do |height|
      # pull the tag -- this gives you the whole img tag
      @h = height.to_s
      # extract the height
      @h.gsub!(/.*height="(.*?)".*$/, '\1')
      #run the test
      assert_equal @h, "224"
    end
  end

This can be tightened up, but I left it explicit so that I could understand what I was going. The assert select makes sure that I’m setting the height. The block makes sure that it’s equal to 224.

Are there easier ways to do this?

How to get Subversion to ignore your Rails log files

Friday, September 5th, 2008

Rails puts the log files in the same part of the tree that ends up under source control. If you don’t tell Subversion to ignore them, you’ll end up with all the log files under source control, which will drive you nuts.

If you already have them in the system:


cd YOUR_RAILS_APP/log
ls -l # Make sure you're in the right directory
svn --force rm * # Force Subversion to kill those files
cd .. # Move back to the rails root level
svn propset svn:ignore "*.log" log

Hope this helps.