Created
March 26, 2012 12:06
-
-
Save amontalenti/2204671 to your computer and use it in GitHub Desktop.
basic shortener implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_base(q, alphabet): | |
if q < 0: raise ValueError, "must supply a positive integer" | |
l = len(alphabet) | |
converted = [] | |
while q != 0: | |
q, r = divmod(q, l) | |
converted.insert(0, alphabet[r]) | |
return "".join(converted) or '0' | |
def to62(q): | |
"""Base 62 identifiers for integers based upon a random shuffling of string.letters + string.digits""" | |
return to_base(q, '2FQYNEJAUsbGu41zndZTeocMai5H7OIjXkKg8qyt3WC9hLplxfVBm0wSRr6vPD') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment