Tweak your Spotlight Settings to Double OSX Battery Life

My Spotlight indexer process was consistently using 75-150% CPU. Since I *never* use Spotlight for document content searches, and *only* use it for app launching (really, Alfred ( on top of Spotlight), I added ALL hard drive directories except for my Applications directory to Spotlight’s Privacy tab (System Preferences > Spotlight > Privacy).

The Spotlight indexer process is now silent, and my battery life has doubled.

How to speed up gem installs 10x

Answer: Turn off ri and rdoc installation. Sure, you can do this on the commandline, like so:

sudo gem install fastercsv --no-ri --no-rdoc

Better, though, is to set this up as the default in your ~/.gemrc file.

:verbose: true
:update_sources: true
:backtrace: false
:bulk_threshold: 1000
:benchmark: false
gem: --no-ri --no-rdoc

Just add that last line and your gem installations will complete in no time.

Posted in ruby. 31 Comments »

alias_method_chaining your AR associations (for fun and profit?)

I’ve used alias_method_chain on top of ActiveRecord associations in a couple of situations lately.  It has emerged as kind of a neat pattern, imho.

For Caching
Let’s say that you’ve got some Users who have Roles.  These roles don’t change frequently at all, so they are prime candidates for caching.

class User < ActiveRecord::Base

  has_many :roles

  def roles_with_cache
    Rails.cache.fetch("user_roles/#{}", :expires_in => 15.minutes) do
  alias_method_chain :roles, :cache


When calling User#roles, the aliased method will try to fetch them from the cache first.  If they don’t exist there, they’ll be pulled from the database.

For Sharding
If you’re using the excellent DataFabric gem to shard your database, you know that your access (finders, etc.) to the sharded tables is done within a block.  We can use the same pattern from above to auto-shard access to these associated objects.

class User < ActiveRecord::Base

  has_many :tweets

  def tweets_with_shard
    self.in_shard { tweets_without_shard }
  alias_method_chain :tweets, :shard

  def in_shard(&block)
    DataFabric.activate_shard(:store => shard, &block)


Fun.  What other interesting uses for alias_method_chain on top of ActiveRecord associations have you seen?

Posted in ruby. Tags: . 1 Comment »

A Change in Protocol: Exploring XMPP in Ruby

I gave a talk on XMPP at Austin on Rails this past Tuesday (Sept 23, 2008).  Many thanks to all who attended. I’ve finally gotten around to cleaning up my slide deck and most of the code I showed.

You can find the slides HERE on SlideShare.

You can grab the code HERE on GitHub.

CampTweet 0.8.4 Released

A while ago, I wrote a post on the FiveRuns blog about the first public release of the CampTweet gem.  In short, this gem enables you to pipe Twitter statuses, Twitter search results, and content from RSS feeds into a Campfire room.

It’s awesome.  Well, it *was* awesome.

And then came the throttling.  Twitter throttling, that is, of unauthenticated GET requests against users’ public timelines.  This change meant that, if CampTweet polled Twitter more than 100 times in an hour for your teammates’ statuses, all subsequent requests from that IP received an error: Twitter REST Error (Bad Request).

Well…although it’s not a completely ideal solution, I’ve updated the camptweet gem to adjust its polling interval to keep it under the 100 reqs/hour limit.  After using this for a couple of weeks now at FiveRuns, the number of ‘Bad Request’ responses from Twitter has dropped dramatically and the turnaround on getting tweets into Campfire has greatly improved.

If you’re using CampTweet, I highly recommend that you get this update.  If you’re not using CampTweet, well…you should be.

sudo gem install camptweet


Posted in ruby. 4 Comments »

Oh wait, I meant to assign you to something

While doing some exploratory surgery via script/console the other day, I got clued into a neat little feature of irb: the underscore.  In short, it’s a special variable tied to the previous result.

>> Team.find(:all, :conditions => 'games_played > 500')
=> # [...a bunch of teams here...]

Oops.  I need to do a couple of operations on this set of teams.  Instead of retyping the above or going up/back in my irb history and changing the start of the line, I’ll just use the underscore. 

>> teams = _

Now, I can do what I originally wanted. 

>> winners = { |team| team.winning_percentage > 0.80 }.map(&:name)
>> losers = { |team| team.winning_percentage < 0.20 }.map(&:name)




Posted in ruby. Tags: , . 2 Comments »

A Peek into Daily Development at FiveRuns

I wrote a post today for the FiveRuns corporate blog entitled ‘Beyond Continuous Integration: Continuous Information‘.  It’s a quick look at some of the tools and practices we use daily on the development team.


Get every new post delivered to your Inbox.