Skip to content

Instantly share code, notes, and snippets.

source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'hike', :git => 'git://github.com/sstephenson/hike.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'rack-ssl', :git => 'git://github.com/josh/rack-ssl.git'
gem 'rack-cache', :git => 'git://github.com/rtomayko/rack-cache.git'
ActionDispatch::Routing::PolymorphicRoutes.module_eval do
def polymorphic_url_with_hierarchy(record, options={})
record = record.hierarchy if record.respond_to?(:hierarchy)
polymorphic_url_without_hierarchy(record, options)
end
alias_method_chain :polymorphic_url, :hierarchy
end
ActionView::Helpers::FormHelper.module_eval do
def form_for_with_hierarchy(object, *args, &block)
class SettingsController < ApplicationController
expose(:setting)
def update
setting.save
respond_with setting, :location => settings_path
end
end
grading_period = @context.courses.map do |course|
GradingPeriod.context_find(course, params[:grading_period_id])
end.compact.first
@tpope
tpope / find_first_or_nil.rb
Last active September 14, 2015 23:34 — forked from johana-star/find_first_or_nil.rb
A way to fing the first thing that matches or set to nil
grading_period = @context.courses.detect do |course|
gp = GradingPeriod.context_find(course, params[:grading_period_id]) and break gp
end
{:name => "John"}.factorbate :user do |parent|
activate!
{:body => "Your mom!"}.factorbate :comments, self
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
def ccexp?d;m=d[-2,2].to_i;m<10||m==10&&d[0,2].to_i<7;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