I made one for Tipjoy where I mapped a content ID to short string, and loaded a frame like the Digg Bar where people could donate to the site and view the content. For example:
http://tipjoy.com/2w/Here is the python code I used to "shrink" and unshrink the content ID.
def shrink( id ):
validCharacters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-~"
base = len(validCharacters)
characterArray = ""
d = id
while d > 0:
ind = d % base
characterArray = validCharacters[ind] + characterArray
d = d / base
return characterArray
def unshrink( code ):
validCharacters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-~"
base = len(validCharacters)
val = 0
revCode = code[::-1]
power = 0
for r in revCode:
i = validCharacters.find(r)
if i==-1:
raise
val += i * (base**power)
power += 1
return val
If you think this code is bad for some reason, please tell me in the comments. I spent little time reviewing it when I wrote it about a year ago.