View observer_example.js
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 observer = { | |
addSubscriber: function(callback) { | |
this.subscribers[this.subscribers.length] = callback; | |
}, | |
removeSubscriber: function(callback) { | |
for (var i = 0; i < this.subscribers.length; i++) { | |
if (this.subscribers[i] === callback) { | |
delete (this.subscribers[i]); | |
} |
View inheritance.js
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
// From the book - Javascript: The Good Parts. | |
// Differential Inheritance | |
var myMammal = { | |
name: 'Herb the Mammal', | |
getName: function() { | |
return this.name; | |
}, | |
says: function() { | |
return this.saying || ''; |
View stubbing_with_arguments_spec.rb
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 GivesCreditToPreferredCustomers | |
LOOK_BACK_PERIOD = 3 | |
def self.for_large_orders(sales_amount, added_credit) | |
# the has_large_purchases scope now takes two arguments | |
preferred_customers = Customer.has_large_purchases(sales_amount, LOOK_BACK_PERIOD) | |
preferred_customers.each do |customer| | |
customer.add_credit added_credit | |
end | |
end | |
end |
View .gitconfig
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
... | |
[merge] | |
summary = true | |
tool = p4 | |
[mergetool "p4"] | |
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "$PWD/$BASE" "$PWD/$LOCAL" "$PWD/$REMOTE" "$PWD/$MERGED" | |
keepBackup = false | |
trustExitCode = false | |
[mergetool] | |
keepBackup = false |
View ScoreBoard.coffee
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 App.ScoreBoard | |
permutations = | |
[['A_1', 'B_1', 'C_1'], | |
['A_2', 'B_2', 'C_2'], | |
['A_3', 'B_3', 'C_3'], | |
['A_1', 'A_2', 'A_3'], | |
['B_1', 'B_2', 'B_3'], | |
['C_1', 'C_2', 'C_3'], |
View sort_with_other.rb
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 'ostruct' | |
module SortWithOther | |
def <=>(other) | |
if self.send(sort_field).downcase == "Other".downcase | |
1 | |
elsif other.send(sort_field).downcase == "Other".downcase | |
-1 | |
else | |
self.send(sort_field) <=> other.send(sort_field) |
View string_calculator_spec.coffee
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 StringCalculator | |
calculate: (input) -> | |
@validateArgument(input) | |
result = 0 | |
result += parseInt(splitValue) for splitValue in @splitValues(input) | |
result | |
validateArgument: (input) -> |
View tracks_controller.rb
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 TracksController < ApplicationController | |
def index | |
signed_in_user | |
end | |
def new | |
@track = Track.new | |
end | |
def create |
View Error Publisher in Haml
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 ApplicationHelper | |
def error_publisher(model) | |
# Thanks Joe! | |
return unless model.errors.any? | |
item_errors = '' | |
model.errors.full_messages.each do |e| | |
item_errors += "<li>#{e}</li>" | |
end |
View JavaScript Calculator with Closure
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 Calculator() { | |
this.add = function(input) { | |
var result = 0; | |
for(i = 0; i<input.length; ++i) { | |
result += input[i]; | |
} | |
return result; | |
} |