Skip to content

Instantly share code, notes, and snippets.

View groner's full-sized avatar

Kai Groner groner

  • Charlottesville, VA
View GitHub Profile
@groner
groner / coverage-xref.py
Created October 4, 2022 02:38
coverage.py crossreferencer
from argparse import ArgumentParser
from os import fspath
from pathlib import Path
import re
import sys
from textwrap import dedent
from coverage import Coverage
from coverage.exceptions import NotPython
@groner
groner / stopwatch.py
Created December 14, 2020 23:02
stopwatch for terminal (python)
#!/bin/env python3
import argparse
from contextlib import contextmanager
from datetime import datetime
from datetime import timedelta
from select import select
import termios
@groner
groner / cookie-suite.sh
Last active June 10, 2022 13:29
scripts to test different haproxy cookie mode behaviors
@groner
groner / prom-helpers.sh
Created May 30, 2018 19:47
prometheus query helpers (uses curl and jq)
prom-query () {
local tmp=$(mktemp -t prom-query.XXXXXX)
curl -Ggs cakepile.local:8001/api/v1/namespaces/monitoring/services/prometheus-k8s:web/proxy/api/v1/query --data-urlencode query="$1" >$tmp
if jq -e '.status=="error"' <$tmp >/dev/null; then
jq <$tmp >&2 -r .error
rm -f $tmp
return 1
fi
jq <$tmp '.data.result[]'
rm -f $tmp
@groner
groner / timeout.pl
Created September 8, 2017 20:23
wrapper script to run a command with a timeout
use POSIX qw(WNOHANG WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG);
use Time::HiRes qw(gettimeofday);
die "usage: $0 TIMEOUT COMMAND ...\n" if (@ARGV < 2);
$timeout = shift @ARGV;
$pid = fork();
die "fork: $!" if not defined $pid;
if ($pid == 0) {
exec @ARGV or die "$ARGV[0]: $!";
function dedent(block) {
// Find the common leading space in a block of text, then remove it. Tabs are NOT handled.
//let spaces = Math.min.apply(null, block.match(/^ +(?=[^ ])/gm).map((ws) => ws.length));
//let spaces = block.match(/^ +(?=[^ ])/gm).map((ws) => ws.length).reduce(Math.min);
let spaces = block.match(/^ +(?=[^ ])/gm).reduce((a,b) => a<b?a:b).length;
return block.replace(new RegExp(`^ {1,${spaces}}`, 'gm'), '');
}
@groner
groner / findclassannotations.py
Last active August 29, 2015 14:24
pip install astunparse; find . -name \*.py -exec python3 findclassannotations.py {} +
import argparse
import ast
import re
import sys
from astunparse import unparse as astunparse
from astunparse import dump as astdump
def main():
@groner
groner / annotatedmethod.py
Created February 18, 2015 18:29
Binding classes and instances with jeni injectors
'''This is my second attempt. It is much cleaner, except for the part that exposes the injector on bound classes and instances.
'''
from contextlib import suppress
from functools import wraps
from pprint import pprint
import jeni
newpgrp() {
# Non-interactive shells don't have job control. Spawn an interactive shell
# to create a new process group. The inner non-interactive shell is there
# to avoid interactive side-effects later on.
$BASH --norc -ic '$BASH -c \"\$@\" -- "$@"' -- "$@"
}
# Notes on things that don't work:
# set -i
# You can't turn job control on this way
@groner
groner / dumpmodels.py
Created October 14, 2013 18:11
rubedo model schema exporter for prac.doc
# encoding: utf8
import json
from collections import OrderedDict
import dfiance
from dfiance.graph import TypeGraphNode
from rubedo.document import (
Document,
DocRef,
)