Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| #!/bin/bash | |
| set -eu | |
| shopt -s nullglob | |
| readonly base_dir=/var/lib/docker/registry | |
| readonly output_dir=$(mktemp -d -t trace-images-XXXX) | |
| readonly jq=/usr/bin/jq | |
| readonly repository_dir=$base_dir/repositories |
| # -*- coding: utf-8 -*- | |
| ''' | |
| Created on Jan 11, 2013 | |
| @author: Mourad Mourafiq | |
| About: This is an attempt to solve the Quora challenge Feed Optimizer. | |
| ''' | |
| import itertools | |
| import copy |
| from binascii import hexlify, unhexlify | |
| from hashlib import md5 | |
| from Crypto.Cipher import AES | |
| try: | |
| from M2Crypto import EVP | |
| except ImportError: | |
| EVP = None | |
| def m2_encrypt(plaintext, key, iv, key_as_bytes=False, padding=True): |
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| import redis | |
| import web | |
| SESSION = 'SESSION:' | |
| class RedisStore(web.session.Store): | |
| """Store for saving a session in redis: | |
| import rediswebpy | |
| session = web.session.Session(app, rediswebpy.RedisStore(), initializer={'count': 0}) |