This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do you prefer... | |
if (a) { | |
doA(); | |
} else if (b) { | |
doB(); | |
} else { | |
doC(); | |
} | |
// or... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("pressing the done button", function() { | |
var container, input, button, welcome; | |
beforeEach(function() { | |
container = $("div"); | |
input = $("<input>", {"class": "name"}); | |
button = $("<button>", {"class": "done"}); | |
welcome = $("<div>", {"id": "welcome"}); | |
container.append(input, button, welcome); | |
$("body").append(container); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Conundrum = { | |
doIt: function() {return "did it"; }, | |
doItCopy: function() {return this.doIt(); } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SavingWithoutCallbacks | |
def save_without_callbacks | |
raise "Only works for saved records" if new_record? | |
updates = {} | |
changes.each {|key, tuple| updates[key] = tuple.last} | |
self.class.update_all(updates, {:id => self.id}, {:limit => 1}) | |
end | |
end | |
ActiveRecord::Base.send :include, SavingWithoutCallbacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
def hello | |
"hello from A" | |
end | |
end | |
class B | |
def hello | |
"hello from B" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example taken from the CouchDB Pages app (though they used this inside a show page, | |
// while I'm using it on a list page -- could be part of the problem?). | |
// | |
// I get this same error any time that I return an object (rather than just a body string) | |
// inside a list function. | |
function(head, req) { | |
return { | |
code : 301, | |
headers : { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'chronic' | |
# This has historically worked, but today, not so much | |
Chronic.parse "next Monday 4:00am" #=> nil | |
# Though it works fine in the afternoon | |
Chronic.parse "next Monday 4:00pm" #=> Mon Nov 08 16:00:00 -0600 2010 | |
# Doesn't work on Tuesday either |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function returns a new function that will run | |
// the given function in the context of the given scope | |
// ie 'this' will be whatever you pass in as 'scope' | |
function scoped(fn, scope) { | |
return function () { | |
return fn.apply(scope, arguments); | |
} | |
} | |
var Obj = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AutoAssetsHelper | |
# Outputs script and link tags for js/css based on | |
# the current action, controller and layout. This | |
# should be preferred over adding assets within a | |
# view file for specific views/layouts/controllers. | |
# | |
# Example: If UsersController#dashboard is requested | |
# and it uses the 'front' layout, these files will be | |
# included if they exist: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function do_something(num, callback) { | |
// arbitrary logic here | |
num += 1; | |
// end arbitrary logic | |
return callback(num); // or you could do callback.call(this, num) | |
} | |
do_something(5, function(new_num) { | |
alert("After complex arbitrary logic, num is " + new_num); | |
}); |
NewerOlder