Skip to content

Instantly share code, notes, and snippets.

# -*- 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
bjaglin /
Last active Nov 29, 2018
Remove orphan layers left by the "file" storage backend of the docker registry, heavily inspired by
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
pokstad /
Created Sep 7, 2011
Redis session store backend for
import redis
import web
class RedisStore(web.session.Store):
"""Store for saving a session in redis:
import rediswebpy
session = web.session.Session(app, rediswebpy.RedisStore(), initializer={'count': 0})
gsakkis /
Last active Jan 23, 2020
Porting AES from M2Crypto to Crypto
from binascii import hexlify, unhexlify
from hashlib import md5
from Crypto.Cipher import AES
from M2Crypto import EVP
except ImportError:
EVP = None
def m2_encrypt(plaintext, key, iv, key_as_bytes=False, padding=True):
tonyc / gist:1384523
Last active Feb 2, 2021
Using strace and lsof
View gist:1384523

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999})   = 0 (Timeout)
hrldcpr /
Last active Mar 1, 2021
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

jboner / latency.txt
Last active Mar 7, 2021
Latency Numbers Every Programmer Should Know
View latency.txt
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