Skip to content

Instantly share code, notes, and snippets.

View thokra's full-sized avatar

Thomas Krampl thokra

View GitHub Profile
@thokra
thokra / easy_way.rb
Created September 2, 2012 11:55 — forked from mislav/easy_way.rb
RESOLVE SHORT URLS before storing. Short URLs are for microblogging; you should never actually keep them around.
require 'net/http'
# WARNING do not use this; it works but is very limited
def resolve url
res = Net::HTTP.get_response URI(url)
if res.code == '301' then res['location']
else url.to_s
end
end