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
[1,2,3].inject([]) {|new_array, incoming_item| new_array << "item#{incoming_item}"} | |
# => ["item1", "item2", "item3"] |
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
# stops once it finds a match | |
@users.detect { |u| u.gender == 'm' } |
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 checkout master | |
git merge --squash private_feature_branch | |
git commit -v |
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
# remember to add "devise :token_authenticatable" to user.rb | |
# and uncomment "config.token_authentication_key = :auth_token" from devise.rb | |
class AddTokenAuthenticatableToUsers < ActiveRecord::Migration | |
def self.up | |
change_table(:users) do |t| | |
t.token_authenticatable | |
end | |
User.reset_column_information | |
User.all.each do |user| |
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
days = ["Friday", "Saturday", "Sunday", "Monday", "Friday", "Saturday", "Friday"] | |
days.inject({}) {|h,day| h[day] = h.include?(day) ? h[day]+1 : 1; h }.sort_by{|k,v|v}.reverse.each{|k,v| puts [k,v].join(",")} | |
#Friday,3 | |
#Saturday,2 | |
#Sunday,1 | |
#Monday,1 |
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
[*1..5] # => [1, 2, 3, 4, 5] |
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 1.9.2 | |
Random.new.rand(10..15) # 10, 11, 12, 13, 14, 15 | |
Random.new.rand(10...15) # 10, 11, 12, 13, 14 | |
# Ruby >1.9.2 | |
rand(10..15) |
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
Get the previous commit hash from the last line of .git/logs/HEAD | |
Replace .git/refs/heads/yourbranch with it | |
"git status" should now work. Note the files changed (you will copy them later) | |
Push this repo elsewhere (a different branch on origin) | |
Remove the .git directory | |
Pull that repo back out to a different directory | |
Copy over the noted files to that directory | |
Commit them |
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
Latency Comparison Numbers Time Light Distance Approximate Light Distance | |
-------------------------- ---- -------------- -------------------------- | |
L1 cache reference 0.5 ns 0.15 m Diagonal across your smartphone | |
Branch mispredict 5 ns 1.5 m Height of Natalie Portman | |
L2 cache reference 7 ns 2.1 m Height of Shaq | |
Mutex lock/unlock 25 ns 7.5 m Height of a school flag pole | |
Main memory reference 100 ns 30 m Half a Manhattan city block (North/South) | |
Compress 1K bytes with Zippy 3,000 ns 900 m Width of Central Park | |
Send 1K bytes over 1 Gbps network 10,000 ns 3,000 m Width of Manhattan | |
Read 4K randomly from SSD* 150,000 ns 45,000 m NYC to Hempstead on Long Island |
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 "console" do | |
it "should run" do | |
binding.pry | |
end | |
end | |
#> spork | |
#> rspec --drb spec/models/console_spec.rb |