Skip to content

Instantly share code, notes, and snippets.

View dingsdax's full-sized avatar
🔭

Johannes Daxböck dingsdax

🔭
  • Vienna
View GitHub Profile
@dingsdax
dingsdax / gist:1140739
Created August 11, 2011 20:51
Jim Breen's WWWJDIC regexp
# 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
@dingsdax
dingsdax / random_time.rb
Created August 7, 2011 13:28
ruby random data generation
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
@dingsdax
dingsdax / gist:1118528
Created August 1, 2011 17:04
Ruby remote file checker
# 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"
@dingsdax
dingsdax / gist:1080272
Created July 13, 2011 13:13
Jaro–Winkler distance in Ruby
# 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
@dingsdax
dingsdax / damerau_levenshtein.rb
Created January 9, 2011 19:42
string similarity metrics in ruby
# 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