This file contains hidden or 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
def Object.const_get_or_set_class klass_name | |
klass_name = klass_name.gsub(/(^|_)(.)/) { $2.upcase } | |
const_defined?(klass_name) ? const_get(klass_name) : const_set(klass_name, Class.new) | |
end | |
module Foo; end | |
def Foo.de(bar) | |
Object.const_get_or_set_class "foo_de_#{bar}" | |
end |
This file contains hidden or 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
if (!$.isFunction(Array.prototype.rand)) { | |
Array.prototype.rand = function() { | |
function rand(n) { return Math.floor(Math.random() * n); } | |
return this[rand(this.length)]; | |
}; | |
} | |
$.konamiAdrian = (function() { | |
var fns = [], konami = function() { fns.rand()(); }; | |
$.konami(konami); |
This file contains hidden or 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
Transform /^\$[.\d]+$/ do |dollars| | |
dollars.to_money | |
end | |
Transform /^card "([\d\s]*)"$/ do |cc_number| | |
ActiveMerchant::Billing::CreditCard.new :number => cc_number.gsub(/\D/, '') | |
end | |
Then /^the (card "[\d\s]*") should be charged (\$[.\d]+)$/ do |credit_card, price| | |
credit_card.class # => ActiveMerchant::Billing::CreditCard |
This file contains hidden or 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
<% for person in @people %> | |
<%= render :partial => 'person', :locals => { :person => person } %> | |
<% end %> | |
<% for person in @people %> | |
<%= render :partial => 'person', :object => person %> | |
<% end %> | |
<%= render :partial => 'person', :collection => @people %> |
This file contains hidden or 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
Talk.all # SELECT * FROM "talks" | |
Talk.last # SELECT * FROM "talks" ORDER BY talks.id DESC LIMIT 1 | |
# Rails 2 | |
Presenter.all :conditions => { :name => "Amiel Martin" }, :order => 'created_at ASC' | |
# Rails 3 | |
Presenter.where(:name => "Amiel Martin").order("created_at ASC").all | |
amiel = Presenter.find_by_name("Amiel Martin") | |
# SELECT * FROM "presenters" |
This file contains hidden or 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
<title>Equal Heights Test</title> | |
<style type="text/css" media="screen"> | |
#container{ width: 960px; margin: 20px auto; } |
This file contains hidden or 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 curry_timer_func(text) { | |
var local_var = text.toUpperCase(); // local variable will be bound to the function that is returned | |
return function() { window.console.log(text, local_var); }; | |
} | |
window.setTimeout(curry_timer_func("Curried Timer 1"), 1000); | |
window.setTimeout(curry_timer_func("Curried Timer 2"), 2000); | |
function setup_another_timer(text, time) { |
This file contains hidden or 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
def possessivize(owner) | |
owner.ends_with?('s') ? owner + "’" : owner + "’s" | |
end |
This file contains hidden or 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
$.konami(function() { | |
// This will get run when the konami code is completed | |
// Some examples: | |
document.location = "http://someawesomelyfunnysite.com"; | |
$("p").each(function() { | |
$(this).text("Something else really funny"); | |
}); |
This file contains hidden or 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
$.konami = (function() { | |
var cheatPos = 0, | |
konami_event = 'konami', | |
konami = function(fn) { | |
$(window).bind(konami_event, fn); | |
}; | |
konami.cheat = [38,38,40,40,37,39,37,39,66,65]; | |