Skip to content

Instantly share code, notes, and snippets.

@eigenhombre
Created October 9, 2012 18:38
Show Gist options
  • Select an option

  • Save eigenhombre/3860597 to your computer and use it in GitHub Desktop.

Select an option

Save eigenhombre/3860597 to your computer and use it in GitHub Desktop.
import binascii
import hashlib
import random
import json
import bz2
def mbid(pos):
h = hashlib
return h.sha224(str(pos)).hexdigest()[:10]
def sim_config(name, strings=86, doms_per_str=60, domfrac=1.0):
return {'config': name,
'strings': [{'str': s + 1,
'doms': [{mbid(d + 1): d + 1}
for d in range(doms_per_str)
if random.random() < domfrac]}
for s in range(strings)]}
def test_config_barf():
cfg = sim_config('sim')
dumped = json.dumps(cfg)
compressed = bz2.compress(dumped)
hexed = binascii.hexlify(compressed)
unhexed = binascii.unhexlify(hexed)
uncompressed = bz2.decompress(unhexed)
undumped = json.loads(uncompressed)
assert undumped == cfg
print len(dumped), len(compressed), len(hexed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment