Skip to content

Instantly share code, notes, and snippets.

def luhn?n;s=0;n.size.times{|i|x=n[-i-1,1].to_i*(i%2+1);s+=x>9?x+1:x};s%10==0;end
def ccexp?d;d[-2,2].to_i<=10&&d[0,2].to_i<7 end
def fibsum _;_<3?_:1+fibsum(_-1)+fibsum(_-2)end
def ccexp?d;d[-2,2].to_i<=10&&d[0,2].to_i<7 end
def morse s;26.times{|i|s.gsub!(/#{(97+i).chr}/i,"$be5 J8G#T6P'&9Sl/,!-H0cfk".split('').map{|x|(x[0]-31).to_s(3).tr('12','.-')}[i])};s;end
def ccexp?d;m=d[-2,2].to_i;m<10||m==10&&d[0,2].to_i<7;end
@tpope
tpope / morse.rb
Created June 11, 2010 03:50 — forked from ryanb/morse.rb
def morse s;s.upcase.gsub(/\S/){|x|("CF+(514M )DGL"[x[0]-65]).to_s(3).tr("12",".-")};end
{:name => "John"}.factorbate :user do |parent|
activate!
{:body => "Your mom!"}.factorbate :comments, self
end
@tpope
tpope / .gitattributes
Created October 24, 2010 20:38
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundlelock
db/schema.rb merge=railsschema
class SettingsController < ApplicationController
expose(:setting)
def update
setting.save
respond_with setting, :location => settings_path
end
end