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
| wesbailey@feynman:~/playground> irb -r neverwritecodelikethis | |
| ruby-1.9.2-p0 > space = Hash.new(0) | |
| => {} | |
| ruby-1.9.2-p0 > ObjectSpace.each_object(self.class) {|o| space[o.class] += 1} | |
| => 10349 | |
| ruby-1.9.2-p0 > space.keys | |
| => [String, RubyToken::TkIDENTIFIER,..., NeverWriteCodeLikeThis, ... , RubyToken::TkNL, RubyToken::TkRBRACE, ArgumentError] | |
| ruby-1.9.2-p0 > |
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
| drop table if exists schema_migrations; |
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 'yaml' | |
| require 'logger' | |
| require 'active_record' | |
| namespace :db do | |
| def create_database config | |
| options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'} | |
| create_db = lambda do |config| | |
| ActiveRecord::Base.establish_connection config.merge('database' => nil) |
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
| # usage: array_merge.rb --data_file=filename --limits=10,20,30 | |
| require 'rubygems' | |
| require 'vr_script' | |
| require 'benchmark' | |
| include Benchmark | |
| class Array | |
| def to_hash_using_inject_push( use_array ) | |
| Hash[*(0 .. self.size).inject( [] ) { |r,i| r.push( self[i], use_array[i] ) }] |
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
| ruby-1.9.2-p136 > 'asdf asdf--asdf asdf-asdf'.gsub(/( |-)( |-)?/, '_') | |
| => "asdf_asdf_asdf_asdf_asdf" | |
| ruby-1.9.2-p136 > 'asdf asdf--asdf asdf-asdf'.gsub(/( |-)\1?/, '_') | |
| => "asdf_asdf_asdf_asdf_asdf" |
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
| wesbailey@feynman:~/tmp/code_katas> bundle install | |
| Using ZenTest (4.4.2) | |
| ... | |
| Using bundler (1.0.10) | |
| Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. |
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
| kata "Awesome Exercise" do | |
| [...] | |
| 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
| wesbailey@feynman:~/code_katas> kata take sample.rb | |
| Awesome Exercise Kata |
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 Kata | |
| module Base | |
| describe "DSL" do | |
| before :each do | |
| @summary = 'sample summary' | |
| [...] | |
| end | |
| describe "#kata" do | |
| [...] |
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 'stringio' | |
| def capture_stdout | |
| $stdout = StringIO.new | |
| $stdin = StringIO.new("y\n") | |
| yield | |
| $stdout.string.strip | |
| ensure | |
| $stdout = STDOUT | |
| $stdin = STDIN |