Skip to content

Instantly share code, notes, and snippets.

@momo-lab
momo-lab / open_uri.rb
Created May 9, 2012 07:00
HTTP_PROXY環境変数にProxy認証用のUser/Passの定義がある場合はそれを使用するようにする。(要open-uri)
def open_uri(uri, options = {}, &block)
uri = URI.parse(uri) until URI === uri
proxy = uri.find_proxy
unless proxy.nil?
if proxy.user.nil?
options[:proxy] = proxy
else
options[:proxy_http_basic_authentication] = [proxy, proxy.user, proxy.password]
end
end
@momo-lab
momo-lab / gist:2642521
Created May 9, 2012 06:49
Luhnアルゴリズムの実装サンプル
module Luhn
CODE_0 = "0".ord
CODE_9 = "9".ord
CODE_A = "A".ord
CODE_Z = "Z".ord
def self.add(data)
return data + get_char(data)
end