This file contains 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
cars = 20000.0 | |
avg_salary_per_hr = 40.0 | |
accident_visible_hrs_without_chinook = 1.5 | |
accident_visible_hrs_with_chinook = 0.3 | |
idle_gas_gallons_per_hr = 0.25 | |
gas_cost_per_gal = 4.0 | |
total_cost_of_accident_without_chinook = (cars * avg_salary_per_hr * accident_visible_hrs_without_chinook) + | |
(idle_gas_gallons_per_hr * gas_cost_per_gal * accident_visible_hrs_without_chinook) |
This file contains 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
# Voilà. A way to detect monkeypatches in Ruby. | |
class Module | |
@@_class_instance_method_map = {} | |
@@_class_singleton_method_map = {} | |
def self.object_space_snapshot | |
@@_class_instance_method_map = {} | |
@@_class_singleton_method_map = {} | |
ObjectSpace.each_object(Module) do |o| | |
@@_class_instance_method_map[o] = o.instance_methods(false).map{|m| [m, o.instance_method(m).hash] } |
This file contains 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
- facebook_post = FacebookPost.new({:site_id => feed.site_id, | |
- :facebook_feed_id => feed.id, | |
- :facebook_user_id => facebook_user.id, | |
- :facebook_id => post.post_id, | |
- :sender_user_id => nil, | |
- :from_id => facebook_user.uid, | |
- :from_name => fb_actor.name, | |
- :message => (message ? CGI.unescapeHTML(message) : ""), | |
- :sent_at => Time.at(post.created_time), | |
- :data => (post.attachment ? post.attachment.to_json : nil), |
This file contains 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
def with_caching(on = true) | |
existing, Rails.application.config.action_controller.perform_caching = Rails.application.config.action_controller.perform_caching, on | |
yield | |
ensure | |
Rails.application.config.action_controller.perform_caching = existing | |
end |
This file contains 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
# automated git bisecting. because I hate remembering how to use this. | |
# ex. usage: git_wtf_happened <ruby testfile> <how many commits back, default 10> | |
function git_wtf_happened { | |
git bisect start HEAD HEAD~${2:-10}; | |
git bisect run ruby $1; | |
git bisect view; | |
git bisect reset; | |
} |
This file contains 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
# Make to_i on a string return nil if there are no actual valid numbers | |
# or if it doesn't at least start with a number. | |
String.class_eval do | |
unless instance_methods.include?(:to_i_without_nil) | |
alias to_i_without_nil to_i | |
def to_i_with_nil(base=10) | |
if (r=self.to_i_without_nil(base))==0 | |
if /^[0-9]+/ =~ self | |
r |
This file contains 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 | |
# | |
# File: git_solution_generator.rb | |
# Created by Peter Marreck on 2012-08-03. | |
class GitSolutionGenerator | |
def solutions(n=1, sep=" ") | |
(1..n).inject(""){|total,x| total+"#{solution}#{sep}"} | |
end |
This file contains 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
# Some code that lets you quickly erect objects and their attributes with a params hash | |
class InvalidAutoInitializeParamError < StandardError; end | |
class Object | |
class << self | |
alias new_without_auto_initialize new | |
def new_with_auto_initialize(*args,&block) | |
a1 = args.first |
This file contains 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
# So you want to find out what is messing with your object somewhere deep in your stack... | |
# Behold, your on-the-fly tracer... | |
module NotifyWhen | |
def notify_when(*meths, &callback) | |
class << self; self; end.instance_eval do | |
meths.each do |meth| | |
alias_method "unnotified_#{meth}".to_sym, meth | |
define_method(meth) do |*args, &block| | |
callback.yield(*([meth, args, self][0..callback.arity])) |
This file contains 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
cat /Users/pmarreck/.rvm/log/ruby-1.9.3-p327/make.log | |
[2012-11-26 15:21:42] make | |
CC = /usr/local/bin/gcc-4.2 | |
LD = ld | |
LDSHARED = /usr/local/bin/gcc-4.2 -dynamiclib | |
CFLAGS = -O3 -fno-common -pipe | |
XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT | |
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/Users/pmarreck/.rvm/usr/include -I. -I.ext/include/x86_64-darwin11.4.2 -I./include -I. | |
DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -install_name /Users/pmarreck/.rvm/rubies/ruby-1.9.3-p327/lib/libruby.1.9.1.dylib -current_version 1.9.1 -compatibility_version 1.9.1 -Wl,-u,_objc_msgSend | |
SOLIBS = |