If you want to use Backbone.js’s extend function on your own class, all you have to do is this:

var LightModel = function(attributes, options) {
  this.attributes = _.extend({}, attributes);
}

_.extend(LightModel.prototype, Backbone.Events, {
  get: function(key) { return this.attributes[key]; },
  set: function(key_or_values, value) {
    if (typeof key_or_values == 'string') {
      this.attributes[key_or_values] = value;
    } else {
      _.extend(this.attributes, key_or_values);
    }
  }
});

LightModel.extend = Backbone.extend;

Backbone’s extend function is the same between Backbone’s classes. It just uses the prototype it was called with. MyModel1 and MyModel2 in the following example would be equivalent:

var MyModel1 = Backbone.Model.extend({});
var MyModel2 = Backbone.View.extend.call(Backbone.Model, {});

Steve Klabnik wrote a great article called Rails has Two Default Stacks. This is the best mental model I’ve found for the major factions within the rails community.

It breaks down if you start considering various deployment options, but I realized that it’s better not to. Deployment stacks can change more rapidly, and have more reasons for needing to change, than development stacks. It is worth just thinking about the development stack, of which testing is a major part. It is the development stack that plays the biggest role in programmer happiness.

If you work on a large project, thinking about just the development side of things will probably make your (Dev)Ops people happy, too.

George Carlin:

It looked pretty good. It was pristine. Paradise. Have you seen it lately? Have you taken a good look at it lately? It’s fucking embarrassing. Only a nation of unenlightened halfwits could have taken this beautiful place and turned it into what it is today: a shopping mall. A big fuckin’ shopping mall. You know that? That’s all you’ve got. That’s all you’ve got here folks. Mile after mile of mall after mall. Many, many malls. Major malls and mini malls. They put the mini malls in between the major malls. And in between the mini malls they put the mini marts. And in between the mini marts you got the car lots, gas stations, muffler shops, laundromats, cheap hotels, fast food joints, strip clubs, and dirty bookstores. America the beautiful: one big transcontinental commercial cesspool.

I started following Aaron Swartz back in 2005, when I was trying to learn all I could from Paul Graham. I read Graham’s essays and went to the first ever Startup School for Hackers. Aaron Swartz was there, having applied and been selected as one of the first participants in Y Combinator. I immediately found him intriguing and endearing, and started reading his blog.

Aaron Swartz is known for having a wide variety of interests, but they’re all connected. He wanted to make the world better through the power of openness. The first thing that he’s famous for is co-creating RSS, which is a tool that allows anyone to publish their thoughts, so they can easily be read by anyone with access to the Internet, with any tool that supports the standard. He used his blog, Raw Thought, to share his. I subscribed to it with my RSS reader, and also used a feed that Aaron created to read Paul Graham’s blog. Aaron created a tool called Infogami to enable others to share their thoughts. He became involved in reddit, which made the Internet more connected, even hyperconnected. These were great achievements, to be sure, but his sense of duty required him to do so much more.

His political activism was impressive, and will live on. Cory Doctorow’s post on Boing Boing is a good summary of it, but to understand where he was coming from, you need to read what he wrote and listen to what he said. His blog, which I expect will remain online, has a nice archive page. Read it.

Aaron, you have inspired me, and I’m going to miss you immensely. Thank you for your work to make the world a better place, and may you rest in peace.

Today I upgraded to rails 2.3.5 on a server that had an old version of Ubuntu. This is with an old version of ruby 1.9 that was installed using the Ubuntu packages rather than rvm. Here’s what I had to do:

1. Change the rails version

I changed the version in config/environment.rb to 2.3.15.

RAILS_GEM_VERSION = '2.3.15' unless defined? RAILS_GEM_VERSION

More information here.

2. Turn off yaml and symbol deserialization

Add this to config/environment.rb, just before the last end statement (at the end of the configuration block):

  ActiveSupport::CoreExtensions::Hash::Conversions::XML_PARSING.delete('symbol')
  ActiveSupport::CoreExtensions::Hash::Conversions::XML_PARSING.delete('yaml')

More information here. This is apparently also solved by the rails update above, but since this flaw is so harmful I’m glad to have it fixed in more than one place.

3. Require thread

I got this from a StackOverflow post. I added this to the top of config/boot.rb:

require 'thread'

# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb

It says not to change the file, but in this case I am not changing the file to customize my rails app but to make it work with a newer version. I’m not sure this step was necessary.

3. Upgrade rubygems

I had an old version of rubygems. It was installed with apt-get, so I couldn’t upgrade it with gem update --system. Furthermore, since I was running an old version of Ubuntu, apt-get upgrades weren’t working for me. So instead I uninstalled rubygems and installed it from source.

5. Install the gems

I installed the gems for rails with gem install rails --version 2.3.15 and also installed thin and mysql.

6. Restart the web server

Finally I restarted the web server.

Now, this is just one system configuration and chances are most are different so this may not help you. The uninstalling of rubygems and reinstallation from source took quite a while to figure out so I thought I’d share. If this doesn’t solve your problem, you may leave a comment and if I have time I’ll try to help you figure out what went wrong with yours.

Long ago I realized that it’s often better not to quit a suspected bad idea, but to explore it and learn from it. @substack just gave me more insight into this:

Don’t unpublish your bad ideas. The best argument against a bad idea is to implement it well.

James Halliday (@substack)

The last sentence is key, and applies to more than published bad ideas. In web development, if it is indeed a bad idea, you’re more likely to learn from it, than to cause harm. If it’s a good idea that seems like it’s a bad idea, which turns out to be a good idea, it might be a really good idea.

There are a lot of rails 2.3.x apps that have slipped out of maintenance but are still used. When it comes time to add a feature to them, the original developer may be unavailable or may not have the same configuration for running it in development mode. I found myself in that situation and here’s what I did to run it:

  1. Start a new vagrant instance with Ubuntu. This makes things easy to install.
  2. Install rvm and the same ruby version. The project I received had a .rvmrc which specified a version of 1.8.7. The first time I told rvm to install the old version of ruby, I exited after rvm game me a list of packages to install, and installed those packages. Then I told rvm to install ruby again and it worked.
  3. Install the version of rails. It’s in config/environment.rb. Mine was 2.3.5. I ran “gem install rails -v 2.3.5”.
  4. Install dependencies specified in config/environment.rb. On this project it was just prawn, the pdf generator.
  5. Set up the database. This was the usual drill on this project. Nothing different from a new version of rails, except it was mysql instead of mysql2. I installed the Ubuntu database packages (libmysqlclient-devel and mysql-server), set up the database according to config/database.yml, and tried running rake db:migrate and after that failed ran rake db:schema:load.
  6. Go back to an old version of rubygems. I ran “gem update –system 1.5.3”
  7. Go back to an old version of rake. The breaking changes in rake were pretty much the worst thing ever. Switch to the global gemset and uninstall rake, and install rake again with “gem install rake –version=0.8.7”. If you’re having trouble with rake, 0.8.7 is probably the version you’ll want.

After that you’ll hopefully be able to run commands in script/ as well as rake commands.

In my experience it’s enough of a pain to go from 2.3.5 to 2.3.14 that it might be better to just go from 2.3.5 to the latest 3.x version. This will require a lot of changes but it will make the app ready to be worked on by most rails developers again.

Trans fats are harmful. Most people in the creative class know it and avoid trans fats. What, in my experience, fewer of us know is that it turns up in smaller quantities in food that says it has 0g of trans fats. That’s right. If food has less than 0.5g of trans fats, they’re allowed by the FDA to say that it has 0g of trans fats.

Normally this might be understandable, but trans fats are unhealthy in any quantity. So avoid them. This article by Vintage Savoire Faire says it best:

If a product contains hydrogenated or partially hydrogenated oils of any kind, it contains trans fats.  Don’t eat it.

Two brands that are accepted indulgences by many people who try to eat a healthy diet are Krispy Kreme and Snickers. These both contain hydrogenated oils, and therefore, small amounts of trans fats. Avoid!

But even if a particular product doesn’t have trans fats, do you really want to eat food from an industry that sneaks trans fats into their products? I don’t. I tend to buy a lot of produce, beans, oats, nuts, and seeds from Sprouts, Costco, and Whole Foods. It feels good to be buying real food instead of filth.

I’m a bit of a software terminology buff. One of the favorite terms that I’ve heard over the years is Plain Old Java Objects, or POJO. It rhymes with pogo, as in pogo stick.

After thinking about a case where a Backbone.js Model might not make the most sense, due to overhead for communicating with servers and publish/subscribe, I came up with the term PODO, or Plain Old Domain Object. I see that a few people have already thought of it.

To me a Plain Old Domain Object is an object which doesn’t also have the responsibility of persisting itself, which Backbone Model objects and ActiveRecord objects are designed to do.

There are reasons why I find myself wanting to use a model object with persistence built in for complex models, but I think if I had the right storage middleware object I’d be comfortable without them. I’d want it to be based on patching rather than full updates. That way I could trigger only the behavior necessary in my PODOs for a given state change.