Skip to content

Instantly share code, notes, and snippets.

@urara
urara / URL_Shortener.rb
Last active August 29, 2015 14:00 — forked from taichi/Rx.java
Rubyで書いた、もっと行けるはず
require 'webrick'
h, s, o = {}, WEBrick::HTTPServer.new(:Port => URI.parse('http://localhost:3333/').port), [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
for url in ARGV
h[(0...5).map { o[rand(o.length)] }.join] = url
end
p h
s.mount_proc('/'){|req, res| res.set_redirect(WEBrick::HTTPStatus::Found, h[req.unparsed_uri[1..-1]]) }
s.start