Ruby’s Hash#default=

July 21, 2011

If Ruby’s Hash#default= returned the Hash instead of the default object, you could write:

TRANSLATION = { ‘hello’ => ‘bonjour’ }.default=(’unknown’)

Read the full article →

Use of the word “bind” in JavaScript libraries

July 21, 2011

I’ve been looking at some patterns for the use of backbone.js, which leverages underscore.js.
In view code, you’ll see a sequence like this:

var ThingyItem = Backbone.View.extend({
tagName: "li",

initialize: function() {
_.bindAll(this, ‘render’, ‘elementClass’);
this.model.bind("change", this.render);
},

events: {
"change .complete input": "toggleComplete"
[...]

Read the full article →

Another reason to dislike the Ruby 1.9 Hash syntax

July 9, 2011

I’m not religious about the old or new Ruby Hash syntax, but it is interesting that if you inspect a Hash in 1.9, you get the old syntax:

ruby-1.9.2-p180 :001 > { foo: ‘bar’ }
=> {:foo=>"bar"}

If the new syntax is so ding-dang good, then I think inspect should use it, when it can.

Read the full article →

Helpful Rails book: Rails AntiPatterns, by Pytel and Saleh

May 24, 2011

So I’m reading Chad Pytel and Tammer Saleh’s book Rails AntiPatterns: Best Practice Ruby on Rails Refactoring, and it’s a good one. Oops, but I got the title wrong: It’s RailsTM AntiPatterns: Best Practice Ruby on RailsTM Refactoring. (I don’t want to get sued for leaving out those TMs.)
I’ve been writing RailsTM code for a [...]

Read the full article →

When I Want Ads to Know More About Me

March 26, 2011

So . . . I’ve logged in to netflix.com recently so I’ve been cookied by them. Now I read boston.com, and it launches one of those damn “pop under” NetFlix ads. Eh? Hey, guys, how about detecting that I’m a NetFlix subscriber and not showing me that stupid ad!?
Ditto, New York Times. I subscribe to [...]

Read the full article →

Setting expires headers via Rack

March 25, 2011

For future reference:
To set expires headers on responses coming from your /assets path:
Add rack-contrib to your Gemfile
In config.ru, before your “run”:

require ‘rack/contrib’
use Rack::StaticCache, :urls => [ '/assets', '/images', '/javascripts' ], :root => ‘public’

The default is one year. For two, add :duration => 2 after the :urls specification.
That is all.

Read the full article →

Russ Olsen’s Eloquent Ruby, and the teaching of Ruby

March 5, 2011

Russ Olsen has just come out with a wonderful book on Ruby called Eloquent Ruby. If you’re a Rubyist, you should get it. What’s great about it is that it combines a breezy, even sometimes funny, style that is “teacherly” but also accurate in matter of detail.

There are a couple of things that really make [...]

Read the full article →

Rapid software development with my 8-year-old

February 28, 2011

So my 8-year-old daughter has been increasingly interested in what computers can do, and how to make them do things. We’ve done some Scratch (http://scratch.mit.edu/) together, and we’ve done some Lego/software integration with MIT’s kit (not Mindstorms — we used the earlier kit MIT made that doesn’t have Lego branding and so forth). That was [...]

Read the full article →

Page numbers for the Kindle – Thank god

February 13, 2011

Finally, page numbers are coming to the Kindle.
I expressed concern about this in March of 2010. I can’t imagine how you’d teach with an electronic reader without being able to coordinate students to the same position in the text (the Kindle locations are subject to font size).

Read the full article →

Application delivery on mobile devices: App Store/Native vs. Browser/HTML5

February 3, 2011

I was noting to an entrepreneur friend Facebook’s recent decision to deliver their mobile apps via HTML5 (http://blogs.wsj.com/venturecapital/2011/01/25/with-plenty-of-cash-facebook-targets-growing-mobile-market/):

“Mobile is the primary focus for our platform this year,” [CTO Bret Taylor] said, noting that 200 million people are currently accessing Facebook on mobile devices. Not only is that group twice as active as their desktop counterparts, [...]

Read the full article →