Skip to content

Instantly share code, notes, and snippets.

baverman / .gitignore
Last active November 14, 2021 19:34
FM synth implementation with numpy and tkiner
View .gitignore
baverman /
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():
baverman /
Created May 25, 2018 04:58
File lock using fcntl
def lock(file_name, block=False):
fp = open(file_name, 'w')
opts = fcntl.LOCK_EX
if not block:
opts |= fcntl.LOCK_NB
fcntl.lockf(fp, opts)
baverman /
Created November 6, 2017 17:34
asyncio statsd client
import asyncio
import statsd
class AsyncStatsClient(statsd.StatsClient):
class DummyProto(asyncio.DatagramProtocol):
def __init__(self, host='localhost', port=8125, prefix=None, maxudpsize=512):
self._addr = host, port
baverman / ssl-perf
Last active October 12, 2017 12:12
Shows histogram of TLS connect times
View ssl-perf
#!/usr/bin/env python
import time
import sys
import socket
import ssl
import math
def percentile(N, percent, key=lambda x:x):
baverman / .gitignore
Last active November 23, 2016 08:32
Async vs Sync
View JIRA archive old releases
function archiveOldReleases(dt) {
$('tr.project-config-version-released').each((idx, obj) => {
$obj = $(obj);
if (!$obj.hasClass('project-config-version-archived')) {
var rdate = $obj.attr('data-releasedate');
if (rdate && rdate < dt) {
type: 'PUT',
url: '/rest/api/2/version/' + $obj.attr('data-id'),
contentType: 'application/json',
View throng
#!/usr/bin/env python
import os
import time
import argparse
import signal
from subprocess import Popen
class Pool(object):
def __init__(self, process_count, args):
baverman /
Created July 20, 2016 20:37
DSQ bench
import os
from btasks import add
COUNT = 10000
if os.environ['QUEUE'] == 'rq':
from rq import Queue
from redis import Redis
baverman / http-import-fox
Created April 9, 2015 21:02
Import firefox cookies into httpie
View http-import-fox
#!/usr/bin/env python
from __future__ import print_function
import os.path
import glob
import json
import argparse
import sqlite3