Speaking of trying really hard:

Here’s the “making of” video

Could they have done this with a green screen? Could they have gotten some fancy animation software for those jelly beans? Could they have phoned it in?

Yes. Yes. And yes.

Today I was reminded of something that was probably one of the most enduringly useful tricks I learned in all of my music education. In a piano lesson, my teacher pointed out that if I have a repeated note to play quickly, pressing that same key on the keyboard with the same finger is slow and inefficient. Instead, use two fingers alternating to press the same key in a kind of walking motion. I use this all the time now even though I never play piano. I use it with my computer keyboard. Navigating a text file in vim? Tapping out six or seven J‘s in a row and watching the cursor move is more efficient than counting lines for a 7j or waiting while my system decides to send the repeated event to MacVim while I hold down the J key.

Sometimes, it really is about the journey. The journey is where you encounter the people and experiences that will stick with you. But you don’t use the journey for what you get out of it. The journey gives you its gifts freely because you were along for the ride.

Patrick Rhone

I’m willing to pay far more for an item if I know it will last a lifetime and, even more importantly to me, I will never have to spend the mental energy making a choice again.

This is such an unbelievably huge power move. I agree that big ticket items should be carefully considered. Right now, I’m in the midst of just this process with my needing to buy new clothes. I plan to buy things that will wear well and for a long long time. I discovered this benefit initially after receiving a Levenger Circa notebook as a gift a few years back. I still have, use, and love that notebook and foresee having it for many more.

While Patrick is spot on about final choices, I would add that it also goes for things you buy on a more frequent basis as well. For instance, I never think about what pencil I’m going to buy and use. I know I use Uniball Kuru Toga pencils. (Thanks to Patrick for turning me on to these as well.) If I lose, break, or for some other reason find myself needing to buy a pencil, I don’t go to Staples and gawk for an hour at the wall of mechanical pencils. I hop on the Amazon app on my iPhone while I’m waiting in line at Starbucks and order a couple to show up at my door step in two days.

This is something that I’ve termed “sensible defaults.” It’s a phrase I’ve picked up from studying UI design principles, but it’s something I’ve been able to work into other areas of my life as well. For instance, by picking sensible defaults at the eateries we frequent I was able to lose 50 pounds last year.

Is it a little neurotic? Absolutely. Does it mean you might spend a few weeks or months on a quest for the perfect bag to carry around your kit? Boy, ask my wife. Does it mean you might miss out trying the hot new dish at Pei Wei or the new exercise craze? Indubitably. But, in my opinion, the tranquility is well worth that opportunity cost. And the potential for doing something awesome with the saved time and neurocycles is priceless.

I’ve been working on making the Javascript for a pretty big Rails app unobtrusive. Chucking everything into application.js as shown in many screencasts with trivial apps has proven to be problematic to say the least. It’s brittle code that could very well infiltrate unintended areas of the site that happen to use the same classes or id’s. Bad juju.

What I find amazing is that Rails hasn’t developed a convention for Javascript.1 I’ll describe some approaches I’ve seen and then the approach I developed.

Namespaces 2

This approach still chucks everything into just one or maybe a few big js files, but uses namespacing to get around the potential conflicts. As far as I can tell, though, this approach requires that the user use the next approach via a helper method.

content_for

This is old news and we use it to great effect, but it has drawbacks because it does not rely on convention over configuration. Also, if you have a few <%= yield :foo %> areas, your actions become a muddle of template code and actual action code. Currently we’re using content_for for a few different areas of the page, and it’s already becoming messy in the actions.

Convention over Configuration 3

# application_controller.rb
before_filter :instantiate_action_javascript
def instantiate_action_javascript
    js_path = File.join(controller_path, "#{action_name}.js")
    @current_action_javascript_path = File.exist?(File.join(RAILS_ROOT, 'public', 'javascripts', js_path)) ? js_path : nil
end

# layout.html.erb
<%= @current_action_javascript_path ? javascript_include_tag(@current_action_javascript_path) : "" %>

The code should speak for itself, but I think that mimicking the structure of the views directory makes the most sense here. With this code, I can create javascript files for each action and have them automatically included in the template. Checking for the existence of the file prevents an unnecessary HTTP request and corresponding 404 error in the Javascript console.


  1. We’re still on Rails 2.3.10, so if this is in Rails 3 (or I’ve simply missed it in Rails 2) please let me know. 
  2. First found this at Toby Hede’s blog via this SO post 
  3. I haven’t seen this anywhere else, but I’m certainly not so clever that I think no one else has thought of it.