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
arr = (0...20).to_a | |
p0 = 0 | |
(0..8).each do |x| | |
p0 += 0.475 ** x * 0.525 ** (20 - x) * arr.combination(x).count | |
end | |
p1 = 0.475 ** 9 * 0.525 ** 11 * arr.combination(9).count | |
p2 = 0 |
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
raise "Usage: ruby #{__FILE__} <roughing file> <finishing file>" unless ARGV.length == 2 | |
X_SIZE = 34.0 # leave 2" for mounting to spoil board | |
Y_SIZE = 3.5 | |
Z_SIZE = 3.5 | |
X_INCR = 0.001 | |
STUB_WIDTH = 1.625 | |
STUB_HEIGHT = 1.5625 |
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
describe "#my_method" do | |
before do | |
@blog_post = FactoryGirl.create(:blog_post) | |
end | |
it "should do something" do | |
@blog_post.title.should == 'mytitle' | |
end | |
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
# This patch enables access to the records being preloaded when eager loading | |
# an association whose conditions use interpolation to call class methods. | |
module ActiveRecord::AssociationPreload::ClassMethods | |
[:has_and_belongs_to_many, :has_one, :has_many, :belongs_to].each do |type| | |
define_method "preload_#{type}_association_with_access_to_records" do |records, reflection, *args| | |
@records_to_preload_for_reflection ||= {} | |
@records_to_preload_for_reflection[reflection] = records | |
send "preload_#{type}_association_without_access_to_records", records, reflection, *args | |
@records_to_preload_for_reflection.delete reflection |
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
class TabsController < ApplicationController | |
def index | |
@tabs = Tab.all :include => :available_balance | |
end | |
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
# spec/lint/database_schema_spec.rb | |
describe 'db/schema.rb' do | |
it 'includes the changes from all migrations' do | |
if checksum_line = File.read('db/schema.rb').split("\n").detect {|line| line.match /^# Checksum: \w+$/} | |
checksum = checksum_line.match(/^# Checksum: (\w+)$/)[1] | |
checksum.should == Digest::MD5.hexdigest(Dir.glob('db/migrate/*').sort.map {|path| File.read path}.join "\n") | |
else | |
fail 'db/schema.rb does not contain a migration directory checksum! Please run rake db:migrate' | |
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
$ bundle exec script/console | |
Loading development environment (Rails 2.3.14) | |
>> {:a => :b} == {:a => :b}.with_indifferent_access | |
=> false | |
>> {:a => :b} == {'a' => :b}.with_indifferent_access | |
=> false | |
>> {'a' => :b} == {:a => :b}.with_indifferent_access | |
=> true | |
>> {'a' => :b} == {'a' => :b}.with_indifferent_access |
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
# contain_array checks to see if one array contains all of the elements from another array in the same relative order | |
# | |
# Any elements that are hashes are matched using contain_hash | |
# Any elements that are arrays are matched using contain_array | |
# | |
# Examples: | |
# | |
# describe 'something' do | |
# subject do | |
# [:a, {:b => [:c, :d, :e]}] |
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
require 'fastercsv' | |
require 'mrscake' | |
require 'open-uri' | |
def download_loans | |
open 'https://www.lendingclub.com/info/download.action?file=LoanStats.csv' do |source| | |
open 'LoanStats.csv', 'w' do |destination| | |
destination.write source.read | |
end | |
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
# Git completion | |
if [[ -f "$HOME/.git-completion.bash" ]]; then | |
source "$HOME/.git-completion.bash" | |
__has_gitdir=true | |
elif [[ -n $(which brew) && -f "`brew --prefix`/etc/bash_completion.d/git-completion.bash" ]]; then | |
. `brew --prefix`/etc/bash_completion.d/git-completion.bash | |
__has_gitdir=true | |
else | |
function __git_ps1() { | |
printf "" |
NewerOlder