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
require 'active_support' | |
require 'enumerator' | |
require 'abbrev' | |
Letters = [[], []] + ('a'..'z').enum_for(:each_slice, 3).to_a | |
class Array | |
def sequence(i = 0, *a) | |
return [a] if i == size | |
self[i].map {|x| |
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
class FooController | |
FanlinePaths = process_view_path("somewhere") | |
RingadocPaths = process_view_path("somewhere else") | |
before_filter do | |
case request.host | |
when 'fanline' | |
prepend_view_path FanlinePaths | |
when 'ringadoc' | |
prepend_view_path RingadocPaths |
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
#!/usr/bin/env ruby | |
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} | |
require 'rubygems' unless ENV['NO_RUBYGEMS'] | |
else | |
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
end | |
require 'spec/autorun' |
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
$.extend(Array.prototype, { | |
inject: function(aggregate, iterator) { | |
$(this).each(function() { | |
aggregate = iterator(aggregate, this); | |
}); | |
return aggregate; | |
}, | |
sum: function() { | |
return this.inject(0, function(aggregate, item) { |
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
class SuperClass | |
def some_method | |
puts "foo" | |
end | |
end | |
class BabyClass << SuperClass | |
def some_method | |
super | |
puts "bar" |
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
class Person < ActiveRecord::Base | |
validates :name, :presence: true, :if: :authed? | |
validates :name, :presence: true, :if: :unaccepted? | |
validates :name, :presence: true, :if: :accepted? | |
state_machine :state, :initial => :authed do | |
event :filled_out_profile do | |
transition :authed => :unaccepted | |
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
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
end | |
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
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
Actions = [PersonalValues, PersonActions, SomeOther] | |
Locations = [first_action_path, second_action_path, third_action_path] | |
def next_activity(thing) | |
Locations[Actions.index(thing.class) + 1] | |
end | |
def prev_activity(thing) | |
Locations[Actions.index(thing.class) - 1] | |
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
# config/initializers/activity_order.rb | |
ACTIVITIES = [PersonalValues, PersonActions, SomeOther] | |
# config/initializer/array.rb | |
class Array | |
def relative_index(item, idx) | |
self[index(item) + idx] | |
end | |
def next(item) |
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
module Foobar | |
def self.included(klass) | |
klass.instance_eval do | |
state_machine :foo, :initial => :bar do | |
# etc etc etc | |
end | |
end | |
end |