Skip to content

Instantly share code, notes, and snippets.

@ehamberg
Created May 6, 2014 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehamberg/19bced1772ebb9944592 to your computer and use it in GitHub Desktop.
Save ehamberg/19bced1772ebb9944592 to your computer and use it in GitHub Desktop.
import qualified Data.DList as DL
import Control.Monad (forever)
base62Encode :: Integer -> String
base62Encode = map ((base62Alphabet!!) . fromIntegral) . DL.toList . digits
where base62Alphabet = ['0'..'9'] ++ ['A'..'Z'] ++ ['a'..'z']
digits n | n < 62 = DL.singleton n
| otherwise = digits (n `div` 62) `DL.snoc` (n `mod` 62)
readUuid :: String -> Integer
readUuid = read . ("0x"++) . filter (/='-')
main :: IO ()
main = forever $ fmap (base62Encode . readUuid) getLine >>= print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment