Skip to content

Instantly share code, notes, and snippets.

0eJzFfe3OHjdy7K0E/r0KZvg95wbORRwEgSy/8QqxPiDJuwmCvffzWJvdl3xbxanhVEt/Fl5ZZnH6aTab7Ori//z082+/P3389Pb9l5/+z7/8z09vvzy9e/xD96d/+pef3r758P7z40//3+Pfv//l6b8e/7g//vjz21/fv/7t63/25b8/Pv3xn339zx//6v3rd1///+vPn5/e/fzb2/e/vnr3+s2f375/ehV/+tvf/u3xV/7y9Onz2w/vH3+rtBpC24+thsefP73/8vbL26f/xfv44fPj/339a//z038//vfVXrZ/zY+/98csXsX2r/lv//iP/vvf3//+7uenT/87vX/M4dOHnz98/PDpy0+Pv/jNAXPtBqzfHjB0A/789tdXT789vfny6e2bVx8//PYERy77v27/HDn/6/atkWM38runX97+/m5h8FC/PXiSDA5mnpcH73/B8u3By+PPfnn76THc3//b/ks+/v7uI/41j87mYPDaD/b249OrLx9e/frpw+/vf8HDhvNh22zOHMzgMenbMMcE5um/Pn56+vz51QPj6dPfsV79/PTb12X8z0X6/uPvk9UQzmewbzen8OH3L7M5DFYIYA779zMDmkJwNkO/TjYwhyhZKGj0BRceLIfGzdqlEhrAmYURrZPAKVR3J+kj9be3w1lk+sccPn/87e2XL4+//6d/YP77IwP48Okx0tdt9O2vf55YonOmAMLjzgSuL59ev//8x3b9dztQeGB/Cnej1MmP384/ObwMUuHGJzfik19GpG/h3fjkSkxhFpAE/p4LYfYk9LRCfPPLcFbW8Yawhr6PCWvs92UCj4lhLF4i8Jh4xeJFAk8ZmcI5XmQi00pYAIlKZMLQnTXZz2EHc2BC08o3gxQjvoxDd/B6H4oA72XM+VYMuGPjfg4gL4+ztOqOHyM8ZRyKhB+/jENXbXyyvUXCjV+GphuhfsBDbvwyNN3B65bNfoAbg5ehSbRMd5Aep100ProB6ed/6Zai36jg6Mu3N/1vD38LJqQ
@ekimekim
ekimekim / jsonnet_lazy_proxy.py
Last active March 13, 2019 23:54
A very hacky way of creating a python object which lazily looks up keys of a jsonnet object as needed, without re-evaluating the entire jsonnet each time.
import collections
import json
import threading
from Queue import Queue
import _jsonnet as jsonnet
class LazyExecutor(threading.Thread):
# Taken from streamlink
import re
from binascii import unhexlify
from collections import namedtuple
from itertools import starmap
from urlparse import urljoin, urlparse
// Render any jsonnet value (except functions) to TOML format.
local
inlineTable(body) =
"{" +
std.join(", ", ["%s = %s" % [escapeKeyToml(k), renderBody(body[k])] for k in std.objectFields(body)]) +
"}",
renderArray(body) =
local
@ekimekim
ekimekim / run_in_netns.py
Last active January 22, 2018 17:08
run_in_netns.py: A script for running a command in a new network namespace with NATting
import functools
import itertools
import sys
from collections import namedtuple
import argh
from ipaddress import IPv4Network
import easycmd
import os
import signal
import subprocess
class Timeout(Exception):
"""This is raised when a timeout occurs"""
import os
import random
import re
import sys
import argh
ROOT = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
@ekimekim
ekimekim / lddcopy
Last active December 4, 2015 06:04
lddcopy - A script to copy all required libraries to a output directory
#!/bin/bash
USAGE="$0 EXECUTABLE PATH
For all shared libraries used by EXECUTABLE, copy that .so file to PATH"
if [ "$#" -ne 2 ]; then
echo "$USAGE" >&2
exit 1
fi
IDENTITY = lambda x: x
class Pool(object):
"""Implements a generic pool of resources.
The resource is an object that:
* is created by the given factory function / class
* is intended to be re-used
* is hashable and unique (ie. multiple calls to factory() won't return the same object)
* optionally, gets prepared for re-use by given clean_fn
@ekimekim
ekimekim / gerrit-fetch-changes
Last active December 31, 2015 21:39
Pulls every change ref from gerrit remote (TODO: configurable remote), and assigns latest patch to refs/changes/CHANGE_ID
#!/bin/env python
import sys
from subprocess import check_call as cmd
from subprocess import check_output as cmd_out
from subprocess import CalledProcessError
out = cmd_out(['git', 'ls-remote', 'origin'])
refs = [line.split("\t") for line in out.strip().split("\n")]