🏳️⚧️
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
| def foo(d=[]): | |
| d.append('a') | |
| return d | |
| print foo() # => ['a'] | |
| print foo() # => ['a', 'a'] | |
| print foo() # => ['a', 'a', 'a'] |
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
| I'm putting this up here so that I can see that the GitHub Gist CLI tool works properly. |
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
| #! /bin/bash | |
| find vim/bundle -name "config" | grep .git | while read d; do echo "submodule add " $(grep "url = " $d | awk '{print $3}') $(echo $d | sed -e "s/\.git\/config//") | xargs git; done |
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
| image_a = Image.make | |
| stub(image_a).migrated? { false } | |
| stub(image_a).local_filename { 'spec/fixtures/backdrop.jpg' } | |
| image_b = Image.make | |
| stub(image_b).migrated? { false } | |
| stub(image_b).local_filename { 'spec/fixtures/backdrop.jpg' } | |
| document = Movie.new(:title => 'Test Movie', :images => [image_a, image_b]) |
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
| // Operational | |
| { | |
| "operational": true, | |
| "message": null | |
| } | |
| // Failing | |
| { | |
| "operational": false, | |
| "message": "We'll be right back." |
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
| x = 129 | |
| a = (0...x).map { |n| (n % x) }.uniq | |
| puts a.size == x # true | |
| x = 129 | |
| a = (0...(x-1)).map { |n| (n % x) }.uniq | |
| puts a.size == x # false |
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
| class Post | |
| def self.find_by_id(id) | |
| self.new | |
| end | |
| def comments | |
| CommentCollection.new | |
| end | |
| 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
| # As illustrated in http://confreaks.net/videos/427-rubyconf2010-zomg-why-is-this-code-so-slow | |
| Person = Struct.new(:name) | |
| people = [Person.new('steve'), Person.new('bill'), Person.new('larry')] | |
| puts people.inject({}) { |table,person| table[person.name] = person; table } | |
| puts Hash[people.map { |person| [person.name, person] }] | |
| # {"steve"=>#<struct Person name="steve">, "bill"=>#<struct Person name="bill">, "larry"=>#<struct Person name="larry">} |
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
| describe "validations" do | |
| context "birthday" do | |
| ["bad format","2100-01-01","1800-01-01","2000-13-01","2000-00-01","2000-01-32","2000-01-00"].each do |bday| | |
| it "errors with invalid date - #{bday}" do | |
| person = Person.create(:name => "not blank", :birthday => bday) | |
| person.errors.messages[:birthday].first.should == "is invalid" | |
| end | |
| end | |
| ["2099-12-31", nil].each do |bday| |
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
| class Order < ActiveModel::Base | |
| module States | |
| UNPAID = 'unpaid'.freeze | |
| PAID = 'paid'.freeze | |
| end | |
| attr_accessor :state | |
| validates :state, :inclusion => { :in => [States::UNPAID, States::PAID] } | |
| end |