- The only way to go fast is to go well.
- Keep functions as short, single function as possible
- Function is small enough when it can't get any smaller
- Keep argument collection small
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 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
. |
It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media
This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.
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
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9" | |
module Kernel | |
alias :__at_exit :at_exit | |
def at_exit(&block) | |
__at_exit do | |
exit_status = $!.status if $!.is_a?(SystemExit) | |
block.call | |
exit exit_status if exit_status | |
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
echo "##teamcity[setParameter name='env.SEED_NUMBER' value='$(git rev-parse HEAD | tr -d 'a-z' | cut -b 1-5)']" | |
echo "To replicate the order on your machine:" | |
echo "rake spec SPEC_OPTS=\"--order random:$(git rev-parse HEAD | tr -d 'a-z' | cut -b 1-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
[18:48:01][Step 3/6] To replicate the order on your machine: | |
[18:48:01][Step 3/6] rake spec SPEC_OPTS=“–order random:84847” |
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
input = "If you are self-motivated, wow, this world is tailored for you. The boundaries are all gone. But if you're not self-motivated, this world will be a challenge because the walls, ceilings and floors that protected people are also disappearing. That is what I mean when I say \"it is a 401(k) world.\" Government will do less for you. Companies will do less for you. Unions can do less for you. There will be fewer limits, but also fewer guarantees. Your specific contribution will define your specific benefits much more. Just showing up will not cut it. - T. Friedman".downcase | |
pair = "ou" | |
third = "r" | |
pairs = (0..input.length-2).inject({}) do |h,i| | |
key, val = input[i,2], input[i + 2] | |
h[key] = {} unless h[key] | |
h[key][val] = (h[key][val] || 0) + 1 if val | |
h | |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
namespace :site do | |
desc "Middleman build" | |
task :build do | |
puts "Building site..." | |
puts `bundle exec middleman build --verbose` | |
end | |
desc "Build, deploy, bust cache" | |
task :deploy => ["site:build", "s3:deploy", "fastly:bust_cache"] |
OlderNewer