Skip to content

Instantly share code, notes, and snippets.

View ehrenmurdick's full-sized avatar

Ehren Murdick ehrenmurdick

View GitHub Profile
module ActiveRecord::Associations::Builder
class HasAndBelongsToMany < CollectionAssociation #:nodoc:
def define_destroy_hook
name = self.name
model.send(:include, Module.new {
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def destroy_associations
association(#{name.to_sym.inspect}).delete_all_on_destroy
super
end
internet () {
if (
ping -c 3 -t 3 google.com > /dev/null 2>&1
)
then
echo 'yep'
else
echo 'nope'
fi
}
@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
@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 / 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 / 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 / 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
class SuperClass
def some_method
puts "foo"
end
end
class BabyClass << SuperClass
def some_method
super
puts "bar"
$.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) {
#!/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'