Skip to content

Instantly share code, notes, and snippets.

View benauthor's full-sized avatar

Evan Bender benauthor

View GitHub Profile
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"/>
<script src="http://cmx.io/v/0.1/cmx.js"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:900px; -webkit-transform:rotate(0deg);">
<scene id="scene1">
<label t="translate(0,346)">
@benauthor
benauthor / reverso.py
Created August 22, 2014 04:16
Simulate a right-to-left regex with negative lookahead and backref
import re
def get_matches(regex, mystring):
return [i.group(0) for i in re.finditer(regex, mystring)]
input1 = 'A Foo, A Foo qux: Foo qux: Foo qux:'
regex1 = r'Foo.*?qux:'
print get_matches(regex1, input1)
# >>> ['Foo, Foo qux:', 'Foo qux:', 'Foo qux:']
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"cool": {
"enum": [
"a",
"b"
]
},
@benauthor
benauthor / example.py
Created October 21, 2016 14:40
statsd logger sketch
import logging
import os
from logging.handlers import DatagramHandler
HOST_KEY = "STATSD_HOST"
PORT_KEY = "STATSD_PORT"
logger = logging.getLogger("test")
@benauthor
benauthor / schema_dump.sh
Created March 16, 2017 20:56
Dump a pretty mysql schema without all the noise
#!/bin/bash
mysqldump -d \
--skip-add-drop-table \
--skip-add-locks \
--skip-disable-keys \
--skip-set-charset $@ \
| grep -v SET | head -n -2 | tail -n +7
@benauthor
benauthor / decisiontree.py
Created July 12, 2017 20:58
decision tree sketch
class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
class Choices(dict):
pass
#!/bin/bash
args="--merged"
echo "delete some merged branches:"
{ git branch $args | grep -E -v "master|stable|prod|\*" | cut -c 3- | while read -r branchname; do
read -r -u 3 -p "Delete $branchname (y/n)? " answer
case ${answer:0:1} in
y|Y )
git branch -d "$branchname"
;;
@benauthor
benauthor / fake_statsd.py
Created November 7, 2017 19:00
fake statsd server
#!/usr/bin/env python
"""
A local 'statsd' server for dev purposes
"""
from __future__ import print_function
import socket
import sys
def main(port):
@benauthor
benauthor / clean_old_kernels.sh
Created November 28, 2017 20:15
desktop linux still is a disaster
#!/bin/bash
echo 'cleaning old kernels. fuck you, ubuntu.'
df -h /boot
echo 'all versions'
dpkg --list | grep -P "linux-image"
echo 'maybe delete'
dpkg --list | grep -P "linux-image-\d" | tr -s " " | cut -d " " -f 2 | sort | head -n -1
@benauthor
benauthor / retriable.py
Created February 28, 2018 19:54
python retries decorator
from time import sleep
class retriable(object):
"""
A retrying decorator with backoff.
Use it like so:
@retriable(tries=60, initial_backoff=60, backoff_multiplier=1)