Skip to content

Instantly share code, notes, and snippets.

@mduheaume
Created August 20, 2012 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mduheaume/3409226 to your computer and use it in GitHub Desktop.
Save mduheaume/3409226 to your computer and use it in GitHub Desktop.
compressing a bunch of id's to construct a url
import random
import base64
import zlib
random_ids = [''.join([random.choice(string.ascii_lowercase) for x in range(8)]) for n in range(1000)]
long_string = ','.join(random_ids)
b64_string = base64.urlsafe_b64encode(long_string)
compressed_string = zlib.compress(long_string, 9)
b64_compressed_string = base64.urlsafe_b64encode(compressed_string)
len(long_string)
len(b64_string)
len(compressed_string)
len(b64_compressed_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment