Max Brunsfeld's blog
Ask for Help
"Is Juggernaut still the best library to use for websockets, long-polling etc?"
The last commit on master was about 2 months ago. One pivotal project is using it, and they approve of it. If you're on Heroku, you might try their pusher service.
Ask for Help
- "Anybody know of good short-to-medium-term housing in SF? Try airbnb, 'vacation rentals by owner', or homeaway.
Interesting Things
If you're setting up a postgres database using ActiveRecord, and you see an error that looks like this:
new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
then the problem may be that your template1 database (the default database that postgres copies from when you CREATE DATABASE) is configured to use ASCII, rather than UTF8. Try adding this option to the relevant section of your database.yml:
template: template0
More information about Template Databases in postgres
- If you donate to Travis CI, then you will receive free stickers.
Inheritance in Backbone
Backbone.js comes with a minimalist OO inheritance framework similar to the one employed by CoffeeScript. Each base class has a static method called extend that is used to create a subclass, like this:
User = Backbone.Model.extend({
// instance methods
},
{
// class methods
});
extend returns a constructor whose prototype inherits from Backbone.Model.prototype. References to all of Backbone.Model's static methods and properties (including extend) are copied to the new constructor.
Calling 'super'
The constructor also receives a __super__ property, which references its superclass.
User.__super__ === Backbone.Model.prototype
This makes it possible to call super inside of a class or and instance method:
User.prototype.save = function(attrs) {
this.beforeSave(attrs);
User.__super__.save.apply(this, arguments);
};
CoffeeScript has a super keyword that compiles to the line above, but when using Backbone with plain javascript, its a little grating to have to type that out.
A small layer of convenience
I wrote this little super method (test-driven using jasmine) which saves me having to repeat the constructor's name all over the place. You call it like this:
User.prototype.save = function(attrs) {
this.beforeSave(attrs);
this._super("save", arguments);
};
The second parameter to _super is the array of arguments to pass to the overridden method. This is to optimize for the common case of passing the arguments object straight through.
There's no way to avoid having to repeat the method name like that, unless you wrap every method definition with a helper function that either passes the overridden method as a parameter (a la Prototype.js) or reassigns a hidden super property behind the scenes (like JS.Class or John Resig's approach). These approaches won't work with Backbone's ultra-minimalist inheritance system.
Interesting Things
- Radio buttons behave strangely when they have no 'value' attribute. If you had a form containing a tag like this:
<input type="radio" name="foo" /> (no value attribute),
and you selected that radio button, then the POST data will contain foo=on. The default value is not an empty string, but the word "on".
You might run into this problem using rails form helpers. If you pass a nil value to ActionView's radio_button_tag method, it will render a tag without a 'value' attribute, so the string "on" might show up in your params.
Ask for Help
Cocoa applications can be made scriptable with AppleScript. Unfortunately, nobody at the office this morning had experience with this.
Interesting Things
SF Pivots should check out the free PCs in the ops area. These were cutting edge linux development machines several years back, and now they and there parts are up for grabs!
Ask for Help
"Is there a Ruby Gem that will take a string of code and identify what programming language it's written in?"
Github has a gem called Linguist, but it doesn't identify the language by parsing it. It uses file extensions, hash bang lines, and looks for the presence of certain keywords in the code.
"Should Akamai be used with, or as a replacement for varnish?"
