Skip to content

Instantly share code, notes, and snippets.

View ehrenmurdick's full-sized avatar

Ehren Murdick ehrenmurdick

View GitHub Profile
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|
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
#!/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'
$.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) {
class SuperClass
def some_method
puts "foo"
end
end
class BabyClass << SuperClass
def some_method
super
puts "bar"
@ehrenmurdick
ehrenmurdick / person.rb
Created February 14, 2012 19:11 — forked from jlsuttles/person.rb
state machines confuse me
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
@ehrenmurdick
ehrenmurdick / r.rb
Created February 21, 2012 00:28
test
TESTS = 10_000
Benchmark.bmbm do |results|
end
TESTS = 10_000
Benchmark.bmbm do |results|
end
@ehrenmurdick
ehrenmurdick / activities_helper.rb
Created February 27, 2012 22:47
activity_sequence
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
@ehrenmurdick
ehrenmurdick / activities_helper.rb
Created February 27, 2012 22:56 — forked from jlsuttles/activities_helper.rb
activity_sequence
# 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)
@ehrenmurdick
ehrenmurdick / gist:2638892
Created May 8, 2012 20:03
state_machine module
module Foobar
def self.included(klass)
klass.instance_eval do
state_machine :foo, :initial => :bar do
# etc etc etc
end
end
end