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
# spec/acceptance/support/javascript.rb | |
RSpec.configure do |config| | |
config.use_transactional_fixtures = false | |
config.before :each do | |
Capybara.current_driver = :selenium if example.metadata[:js] | |
if Capybara.current_driver == :rack_test | |
DatabaseCleaner.strategy = :transaction | |
else | |
DatabaseCleaner.strategy = :truncation |
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
wget -w 1 -r -k -K -H -N -l 2 http://example.com # pause 1 second between requests, go 2 levels deep |
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
# ActiveSupport::TimeWithZone is a rails construct. Always use it for querying and creating. | |
# DateTime is an old class and is very Ruby specific (not Rails). Don't use it. | |
# If you put .utc on the end of something other than a DateTime, it's converted to a Time. | |
# <class> <to_s> | |
Time.now # Time Sun Apr 24 13:00:00 -0400 2011 | |
Time.now.utc # Time Sun Apr 24 17:00:00 UTC 2011 | |
Time.now.in_time_zone('UTC') # ActiveSupport::TimeWithZone 2011-04-24 17:00:00 UTC | |
Time.zone.now # ActiveSupport::TimeWithZone 2011-04-24 17:00:00 UTC | |
Time.zone.now.utc # Time Sun Apr 24 17:00:00 UTC 2011 |
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
/** | |
* Find a longest common subsenquence. | |
* | |
* Note: this is not necessarily the only possible longest common subsequence though! | |
*/ | |
function lcs(listX, listY) { | |
return lcsBackTrack( | |
lcsLengths(listX, listY), | |
listX, listY, | |
listX.length, listY.length); |
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
# Browse your local git repository | |
# If you prefer not to use webrick, you could install lighttpd and then just run git instaweb. | |
git instaweb --httpd webrick # view at http://localhost:1234 | |
# Browse your local Mercurial repository | |
hg serve # view at http://localhost:8000 | |
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
# "and" and && are not synonymous in Ruby | |
# "and" and "or" have a much lower precedence | |
# "and" and "or" are more like control flow operators than boolean operators | |
do_this() or raise "Failure" | |
assign_me = 10 and assign_me / 2 # (assign_me = 10) and assign_me / 2 ... => 5 | |
#vs | |
assign_me = 10 && assign_me / 2 # assign_me = (10 && assign_me) / 2 ... => undefined |
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
v &= v - 1; // clear the least significant bit set | |
((x ^ y) < 0); // true iff x and y have opposite signs | |
//more here http://graphics.stanford.edu/~seander/bithacks.html |
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
# make a quick backup | |
cp file{,.bak} | |
# access files with the same name in different directories | |
git add app/views/{users,roles}/{index,new}.html |
NewerOlder