This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Ballpark reference on function call, thread, process overhead | |
bender@dishoftheday:work$ python3 overhead.py 1000 | |
forloop: 0.030994415283203125 ms | |
funcloop: 0.17786026000976562 ms | |
threadloop: 110.0301742553711 ms | |
threadloop2: 85.56795120239258 ms | |
threadloop_p: 77.57711410522461 ms | |
procloop: 5104.6202182769775 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(classes = MyConfigurationClass.class) | |
public class MyTest { | |
@Autowired | |
private MyWhateverType myConfiguredBean; | |
@Test | |
public void testMyConfiguredBean() { | |
System.out.println("works"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a pattern I like but I always forget the details | |
class Boo(object): | |
def __init__(self): | |
self.foo = u"☃" | |
def __unicode__(self): | |
return u"Boo(foo={})".format(self.foo) | |
def __str__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cProfile import Profile | |
from functools import wraps | |
import pstats | |
def profiled(f): | |
""" | |
Decorator for profiling a function | |
To use: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
A local 'statsd' server for dev purposes | |
""" | |
from __future__ import print_function | |
import socket | |
import sys | |
def main(port): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AttrDict(dict): | |
def __init__(self, *args, **kwargs): | |
super(AttrDict, self).__init__(*args, **kwargs) | |
self.__dict__ = self | |
class Choices(dict): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
NewerOlder