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
def bond | |
agent = Mechanize.new | |
agent.log = Logger.new(log_path) | |
agent | |
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
def bond | |
Mechanize.new.tap{|a| a.log = Logger.new(log_path)} | |
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
def top_three_scores | |
[2,1,4,3].tap{|a| a.sort! }.tap{|a| a.reverse! }.tap{|a| a.select!{|s| s > 1}} # => [4,3,2] | |
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
def top_three_scores | |
player_scores = [2,1,4,3].sort | |
player_scores.reverse! | |
player_scores.tap{|a| a.pop } | |
end | |
top_three_scores # => [4,3,2] |
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
class Foo | |
class << self | |
def one(val) | |
tap { @one = val } | |
end | |
def two(val) | |
tap { @two = val } | |
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
require 'delegate' | |
class Router | |
def match(path, &block) | |
puts "match: #{path}" | |
puts instance_eval(&block) if block_given? | |
end | |
def resource(name, &block) | |
puts "resource: #{name}" |
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
path_loader = Rerouter.setup(self) | |
path_loader.load do |loader| | |
# Updating the defaults | |
loader.match_strategy :end # only applies to strings [:fullname, :beginning, :end] | |
loader.pattern "Raout" # "" or /something/ | |
loader.extension [:rb, :route] | |
isolated_routes_path = File.join(Rails.root, 'config', 'routes') | |
# Loading something out of band |
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
#!/usr/bin/env ruby | |
require 'colorize' | |
puts <<-HDOC | |
#{"2.hours.ago".green} # => Fri, 02 Mar 2012 14:02:42 CET +01:00 | |
#{"1.day.from_now".green} # => Fri, 02 Mar 2012 22:04:47 JST +09:00 | |
#{"Date.today.to_time_in_current_zone".green} # => Fri, 02 Mar 2012 00:00:00 JST +09:00 | |
#{"Time.zone.parse(\"2012-03-02 16:05:37\")".green} # => Fri, 02 Mar 2012 16:05:37 JST +09:00 | |
#{"Time.zone.now".green} # => Sat, 03 Mar 2012 00:07:37 JST +09:00 | |
#{"Time.zone.today".green} # If you really can't have a Time or DateTime for some reason |
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
#!/usr/bin/env ruby | |
require 'gems' | |
%w{buildem dbuilder}.each do |gem| | |
puts "#{gem} downloaded: #{Gems.total_downloads(gem)[:total_downloads]}" | |
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
#!/usr/bin/env ruby | |
require 'gems' | |
gem_name = ARGV[0] | |
results = Gems.versions(gem_name) | |
if results.instance_of? Array | |
puts (results.first)["number"] | |
else | |
puts "Could not find any versions for #{gem_name}" | |
end |