Skip to content

Instantly share code, notes, and snippets.

@abdollar
Created January 21, 2012 20:29
Show Gist options
  • Save abdollar/1653897 to your computer and use it in GitHub Desktop.
Save abdollar/1653897 to your computer and use it in GitHub Desktop.
Base62 Ruby
SIXTYTWO = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
def to_s_62(i)
return '0' if i == 0
s = ''
while i > 0
s << SIXTYTWO[i.modulo(62)]
i /= 62
end
s.reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment