This file contains hidden or 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 Time | |
def self.random(years_back=5) | |
year = Time.now.year - rand(years_back) - 1 | |
month = rand(12) + 1 | |
day = rand(31) + 1 | |
Time.local(year, month, day) | |
end | |
end |
This file contains hidden or 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
# from http://snippets.dzone.com/posts/show/4638 | |
require 'rubygems' | |
require 'open-uri' | |
require 'net/http' | |
def remote_file_exists?(url) | |
url = URI.parse(url) | |
Net::HTTP.start(url.host, url.port) do |http| | |
return http.head(url.request_uri).code == "200" |
This file contains hidden or 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
# extension for array class | |
class Array | |
# select array items with index | |
# give a block both the item with index of array | |
# filtered by a select statement | |
def select_with_index | |
index = -1 | |
select { |x| index += 1; yield(x, index) } | |
end | |
# return indices array of array item |
This file contains hidden or 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
# extension for string class | |
class String | |
# return character array of string with indices | |
def each_char_with_index | |
i = 0 | |
split(//).each do |c| | |
yield i, c | |
i += 1 | |
end | |
end |
NewerOlder