Created
May 30, 2010 12:04
-
-
Save astropanic/418980 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CHARS64 = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a + ["-", "_"] | |
# Return a 22 byte URL-safe string, encoded six bits at a time using 64 characters | |
def to_s22 | |
integer = self.to_i # UUID as a raw integer | |
rval = "" | |
22.times do | |
c = (integer & 0x3F) | |
rval += CHARS64[c] | |
integer = integer >> 6 | |
end | |
return rval.reverse | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment