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
| # source: http://stackoverflow.com/questions/3002650/parsing-dictionary-entries-with-regex | |
| # | |
| # example_url: http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1ZUJ%E5%85%88%E7%94%9F | |
| # output: | |
| # 先生 [せんせい] /(n) (1) teacher/master/doctor/(suf) (2) with names of teachers, etc. as an honorific/(P)/ | |
| # 先生に就く [せんせいにつく] /(exp,v5k) to study under (a teacher)/ | |
| # 先生の述 [せんせいのじゅつ] /(n) teachers statement (expounding)/ | |
| # 先生方 [せんせいがた] /(n) doctors/teachers/ | |
| # regexp |
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