Skip to content

Instantly share code, notes, and snippets.

@baverman
baverman / asyncio_statsd.py
Created Nov 6, 2017
asyncio statsd client
View asyncio_statsd.py
import asyncio
import statsd
class AsyncStatsClient(statsd.StatsClient):
class DummyProto(asyncio.DatagramProtocol):
pass
def __init__(self, host='localhost', port=8125, prefix=None, maxudpsize=512):
self._addr = host, port
@baverman
baverman / vk-cli.py
Created Sep 17, 2012
Prints a downloadable url for VK video search
View vk-cli.py
#!/usr/bin/env python2
import sys
import re
from urllib2 import build_opener, HTTPCookieProcessor
from urllib import urlencode
from cookielib import CookieJar
from netrc import netrc
@baverman
baverman / simple_notify.py
Last active Mar 10, 2020
Simple libnotify implementation using only plain dbus-send. Can close created notification.
View simple_notify.py
import sys
from subprocess import Popen, PIPE
def notify(title, body=None, timeout=-1, appname='simple-notify'):
cmd = [
'dbus-send',
'--type=method_call',
'--print-reply=literal',
'--dest=org.freedesktop.Notifications',
'/org/freedesktop/Notifications',
@baverman
baverman / improf.py
Created Jun 10, 2019
Import memory profiler
View improf.py
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
baverman / file_lock.py
Created May 25, 2018
File lock using fcntl
View file_lock.py
@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 / http-import-fox
Created Apr 9, 2015
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
@baverman
baverman / ssl-perf
Last active Oct 12, 2017
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):
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) {
$.ajax({
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):