Ruby
- https://github.com/github/gollum
- A simple, Git-powered wiki with a sweet API and local frontend.
短址產生程式
# -*- encoding : utf-8 -*-
require 'digest/md5'
module UrlShorter
ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
def self.short!(url)
hex = Digest::MD5.hexdigest(url)
hexlen = hex.length
subhexlen = hexlen / 8
output = []
for i in 0..subhexlen-1
subhex = hex[i*8,8]
int = 0x3FFFFFFF & ("0x#{subhex}".to_i(16))
out = ""
for j in 0..5
val = 0x0000001F & int
int = int >> 5
out += ALPHABET[val]
end
output << out
end
return output[0]
end
end
page revision: 0, last edited: 04 Nov 2012 00:37