Skip to content

Instantly share code, notes, and snippets.

@astropanic
Created May 30, 2010 12:04
Show Gist options
  • Save astropanic/418980 to your computer and use it in GitHub Desktop.
Save astropanic/418980 to your computer and use it in GitHub Desktop.
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