Skip to content

Instantly share code, notes, and snippets.

@baverman
baverman / ssl-perf
Last active October 12, 2017 12:12
Shows histogram of TLS connect times
#!/usr/bin/env python
import time
import sys
import socket
import ssl
import math
def percentile(N, percent, key=lambda x:x):
@baverman
baverman / file_lock.py
Created May 25, 2018 04:58
File lock using fcntl
@contextmanager
def lock(file_name, block=False):
fp = open(file_name, 'w')
opts = fcntl.LOCK_EX
if not block:
opts |= fcntl.LOCK_NB
try:
fcntl.lockf(fp, opts)
@baverman
baverman / improf.py
Created June 10, 2019 10:24
Import memory profiler
import sys
from importlib._bootstrap import _find_and_load
from resource import getrusage, RUSAGE_SELF
from contextlib import contextmanager
IMPORT_ENTRY = _find_and_load.__code__
def get_mem():