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 'net/http' | |
require 'json' | |
require 'uri' | |
require 'pp' | |
uri = URI(ARGV[0]) | |
pp JSON.parse(Net::HTTP.get_response(uri).body) |
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 'active_record' | |
require 'sqlite3' | |
require 'minitest/autorun' | |
puts "ActiveRecord: #{ActiveRecord::VERSION::STRING}" | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:database => ":memory:" | |
) |
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
$ ./ruby -I. -Ilib/ -w map_symbol_bench.rb | |
Rehearsal -------------------------------------------- | |
nil 0.050000 0.000000 0.050000 ( 0.046891) | |
identity 0.880000 0.000000 0.880000 ( 0.887874) | |
block 1.080000 0.000000 1.080000 ( 1.078556) | |
to_proc 0.990000 0.000000 0.990000 ( 0.996956) | |
----------------------------------- total: 3.000000sec | |
user system total real | |
nil 0.040000 0.000000 0.040000 ( 0.045237) |
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
Hello ruby friends, | |
Next Tuesday night is Seattle.rb's monthly talkie meetup! Things will be going as planned with one big exception: | |
Ryan, Aja and I will all be travelling to Mountain West Ruby Conf that night. Don't worry though, two of my Substantial | |
coworkers have offered to host in my stead. Cassie Schmitz and Shawn Dempsey will be the ones who will let you in the door, | |
tell you the wifi password, direct you towards the restrooms and urge you to leave at the end. Everything else will be the | |
same, although I cannot promise you'll hear another of Aaron's thrilling tales of candy purchasing. | |
Let me know if you have questions or concerns! |
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 'rubygems' | |
require 'benchmark/ips' | |
class ExampleClass | |
def foo; 42; end | |
end | |
non_dci_object = ExampleClass.new | |
module ExampleMixin |
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
pete@balloon:~/projects/rspec-expectations$ rspec rspec_test.rb | |
FF | |
Failures: | |
1) Hash #=~ displays confusing error message when hashes are equal | |
Failure/Error: actual.should =~ actual | |
expected: {:foo=>"bar"} | |
got: {:foo=>"bar"} (using =~) | |
Diff:{:foo=>"bar"}.==({:foo=>"bar"}) returned false even though the diff between {:foo=>"bar"} and {:foo=>"bar"} is empty. Check the implementation of {:foo=>"bar"}.==. |
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
Organization.where("name != 'national'") | |
email = "[email protected]" | |
User.where(email: email).destroy_all | |
def sql_queries(title, verbose=false) | |
queries = Hash.new(0) | |
callback = lambda {|*args| | |
sql = args.last[:sql] |
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
One that seems to surprise a lot of people is Hash.from_xml: | |
> hash = {:foo => 'bar', :baz => 'qux'} | |
=> {:foo=>"bar", :baz=>"qux"} | |
> hash.to_xml | |
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n | |
<foo>bar</foo>\n <baz>qux</baz>\n</hash>\n" | |
> Hash.from_xml(hash.to_xml) | |
=> {"hash"=>{"foo"=>"bar", "baz"=>"qux"}} |
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 'ostruct' | |
module Awesome | |
def self.config | |
@config | |
end | |
def self.configure | |
yield(config) | |
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
module Awesome | |
@config = {} | |
def self.configure | |
yield(self) | |
end | |
def self.method_missing method, *args, &block | |
if method.to_s[-1] == '=' | |
@config[method[0..-2].to_sym] = args.first |