So then, let’s suppose you were able, every night, to dream any dream you wanted to dream. And that you could, for example, have the power within one night to dream 75 years of time. Or any length of time you wanted to have. And you would, naturally, as you began on this adventure of dreams you would fulfill all your wishes. You would have every kind of pleasure you could conceive. And after several nights of 75 years of total pleasure each, you would say, “Well that was pretty great. But now let’s, um, have a surprise. Let’s have a dream that isn’t under control. Where something is gonna happen to me where I don’t know what’s it’s gonna be.” And you would dig that. And come out of that and say, “Well that was a close shave, wasn’t it.” And then you would get more and more adventurous. And you would make further and further out gambles about what you would dream. And finally, you would dream, where you are now.

You would dream the dream of living the life that you are actually living today.

Alan Watts: The Dream of Life

Rails Model Template

Model files can get pretty big with a lot of stuff going on. We’ve standardized on an organized layout amongst all our projects to keep things clean and consistent. We keep this layout as a template file in our models directory that we use for creating new models.

I’ve shared this template file as a Gist in case others find it useful as a starting place for their next model.

Rails Mailer’s Subject Inference

Turns out you can leave out the :subject key when sending mail in Rails 3, so long as you have the proper keys / translation in your en.yml (or other language files):

 Notifications < ActionMailer::Base; def new_user( user ); mail :to =>; end 

Will map to:

 en: notifications: new_referral: subject: "Welcome to the app!" 
Failure is the opportunity to begin again more intelligently.
Henry Ford
Thanks for being here. Let’s make great things.

A quote from the Preface of Valve Software’s New Employee Handbook. EVERY COMPANY SHOULD BE RUN LIKE THIS.

The full handbook can (and should) be read here:

I decided to bite the bullet, and finally build a portfolio site for myself. I had always had one for my past company, Carbon Media Design. But now here’s my chance to toot my own horn.

Programmers should have a visceral aversion to complexity.

The site is ugly as sin, but the message rings clear.

Rdio Missing Some of Your Favourite Albums?

I’ll admit it, I’m a bit of an Rdio addict. Sometimes tunes are either missing or they disappear over time. If you find this happening, fill out this super terrific help form.

And yes, it works. I managed to coax Rdio staff to recover all the Four Tet albums that went astray.

Getting the end of the month with Ruby

It’s as simple as specifying a negative one for the month value., 2, -1)

Awesome to avoid manually trying to calculate the end of the month.

You have to use `get(0)` to compare equality of jQuery objects.

This stumped me for a little while because it’s not intuitive.

In CoffeeScript.


$previous_link.hide if $previous_link isnt $(this)


$previous_link.hide if $previous_link.get(0) isnt $(this).get(0)


$previous_link.hide if $previous_link[0] isnt $(this)[0]

OR ( Just updated this thanks to Eric's input. )

$previous_link.hide unless $ $(this) )

Removing leading zeros with strftime in Ruby

I had no idea you could do this, so I figured I’d share it. You can remove leading zeros when formatting datetimes with strftime() simply by putting a dash / subtraction sign in front of the format specifier. For example:

Date.parse("June 7th 2012").strftime("%A %B %-d %Y")


"Thursday June 7 2012"

You can do the same thing with leading zeros in time format specifiers as well. It all depends on your version of strftime you have installed though, so I would run some code and see if your current version is capable of it.

Gotcha: Rails after_validation is ALWAYS called, even if the model validation fails

You may be tempted to think that after_validation model callbacks are called only if validation passes, however, it always gets called, regardless of whether the model passes validation or not.

If you want to ensure that your callback method’s code is only called if the model is valid, you need to check manually. That said, DO NOT use self.valid? as it will begin an infinite loop.

This *Is* The Ruby Money Gem You Are Looking For.

It’s amazingly difficult to find this.

There is out-dated documentation floating around and a fork from CollectiveIdea that you’ll first wind up at.

This is the official repo of the Ruby Money gem.

Edit This Rails

This is the bash alias Josh mentioned in his blog post last week about Textmate hanging.

alias etr="mate app config db Gemfile* lib Rakefile README test vendor/assets"

"etr" stands for "Edit This (Directory) Rails", and it’ll open Textmate with only the specific directories you want in your project sidebar. Swap mate with "subl" for Sublime, or whatever your editor of choice is.

Note: Looks like I picked it up from Peepcode years ago. Here’s a slew of useful aliases found on Github (pick and choose with a grain of salt):