Skip to content

Instantly share code, notes, and snippets.

// Usage:
//
// $('#the-select').choose('Some Option');
//
// It'll throw an error if the option doesn't exist.
$.fn.choose = function(name) {
var elem = $(this);
if (elem.is(':not(select)')) { return elem; }
var option = elem.find('option').filter(function() {

This is a new version file /usr/bin/rails generated on my system by installing the Rails 3 Gem. The problem with this executable is that the ‘rails’ command no longer provided a way to execute the executables from Rails 2, because the bin had moved from Rails to Railties. A few more details in the related blog post.

Call a version of Rails 2 like so (after putting the following code in /usr/bin/rails):

rails _2.3.5_ myapp

The second file can be put in /usr/bin/rails2 as a convenience path to run the latest available Rails 2 version easily.

@jhuston
jhuston / truncateAtWord.js
Created January 27, 2012 23:00
truncate a word at a word break. optimized for naturally occurring word breaks. with optional length argument.
truncateAtWord = function(str){
var tail = "...",
len = arguments[1] || 10;
if(str.length <= len){
return str;
}
if(str.charAt(len) === " "){
return str.slice(0,len)+tail;
}
return str.slice(0,len).split(" ").slice(0,-1).join(" ")+tail;