Rankitize

December 26th, 2009 No Comment

Have you ever been working on a big awesome website using Ruby on Rails and MySQL and had the need to rank your models by an attribute without loading them all into memory? I know I have.

Unfortunately, unlike Postgres and some other SQL flavors, MySQL lacks a built-in ranking function. After some cursory googling, I found Arjen Lentz’s solution which Chadwick Wood put into use in Rails. However, it’s a little clunky to put all that code in your model for every category you might want to rank, so I DRY’d it up and put together a quick little ActiveRecord plugin to do just that.

It’s easy to use, in your model just declare the columns you want to be able to fetch ranks for:

class User < ActiveRecord::Base
    rank_by :score
end

… and with a little dynamic business you can call a method like this:

@user.score_ranking

So there you go.

I’m willing to bet that this won’t perform well on extremely large datasets, but I haven’t found a better solution for MySQL. For the time being, you probably will want to cache this value somewhere.

You can find out how to install the plugin by visiting Rankitize on GitHub.

Behind the Murder of Murder on a Helicopter

October 10th, 2009 One Comment

Murder on a Helicopter

“Morning Breath” host James Ramsay sits down with the geniuses behind Murder on a Helicopter to discuss the show.

Listen OnlineSubscribe in iTunesBecome a Fan on Facebook

Why National Health Insurance is Good

July 16th, 2009 One Comment

Somehow, somebody on Digg said something that was not stupid. In a reply to Glenn Beck proving once again he is out of his goddamned mind and making the movie Network all the more prophetic, intrepid Digger nanosec makes a great point:

Here’s an example, if there are 2 car washes, where one charges a nominal fee to get your car washed and the other charges $90,000, which one do you think is going to have a queue? If you remove the cheap one, then you’re going to have people driving around in dirty cars because they cannot afford to have their car washed.

Of course, the horror-stories about long lines in countries with national health insurance are mostly lobbyist scare tactics anyway.

Spent the Last Five Days Crying in Argentina

June 28th, 2009 No Comment

Noah and I put together a little music video inspired by South Carolina governor Mark Sanford’s “I spent the last five days crying in Argentina” speech.

You can also download the song if you want.

Murder on a Helicopter #9 – “Erratica”

April 23rd, 2009 No Comment

Murder on a Helicopter

The secret of who shot down Gwendolyn is indirectly revealed, and an old friend pays a new visit.

Listen OnlineSubscribe in iTunesBecome a Fan on Facebook

Murder on a Helicopter #8 – “Another Date With Murder”

April 15th, 2009 No Comment

Murder on a Helicopter

Xaviera makes a stunning discovery, and Colonel Mustard is along for the ride.

Listen OnlineSubscribe in iTunesBecome a Fan on Facebook

Formula For Mac Community Success

April 4th, 2009 No Comment

1. Mention John Gruber
2. Profit