Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
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
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);
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
<% 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 %>
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"
<!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; }
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) {
def possessivize(owner)
owner.ends_with?('s') ? owner + "&rsquo;" : owner + "&rsquo;s"
end
$.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");
});
$.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];