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 self.get_response_following_redirects orig_uri, requests_limit = 15 | |
raise "Input must be an absolute URI." unless orig_uri.is_a?(URI::Generic) && orig_uri.absolute? | |
uri = orig_uri | |
requests_made = 0 | |
while requests_made <= requests_limit | |
response = Net::HTTP.get_response uri | |
requests_made += 1 | |
case response | |
when Net::HTTPSuccess |
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 'uri' | |
require 'net/http' | |
# From http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-get_response | |
# Does not fully work! | |
def fetch(uri_str, limit = 10) | |
# You should choose a better exception. | |
raise ArgumentError, 'too many HTTP redirects' if limit == 0 | |
response = Net::HTTP.get_response(URI(uri_str)) |
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
LETTERS = (65..90).collect{|char_code| char_code.chr} | |
def letter_combos length, accum = nil | |
return accum if length == 0 | |
return accum || LETTERS if length == 1 | |
combos = (accum || LETTERS).product(LETTERS).inject([]) {|combos, product| | |
combos << product.first + product.last} | |
letter_combos(length - 1, combos) | |
end |
NewerOlder