Skip to content

Instantly share code, notes, and snippets.

View steinnes's full-sized avatar

Steinn Eldjárn Sigurðarson steinnes

View GitHub Profile
@steinnes
steinnes / mockmethod.py
Created August 19, 2014 13:48
mockmethod.py
# I couldn't figure out how to do this with Mock or MagicMock
class MockMethod(object):
def __init__(self, *return_values):
self.return_values = return_values
self.called = 0
self.call_args = []
def __call__(self, *args, **kwargs):
self.called += 1
# I found this somewhere on the internet and modified just slightly.
# Sorry whoever I got it from, I don't remember where so no credit for you :-(
function color_my_prompt {
local __user_and_host="\[\033[01;32m\]\u:"
local __cur_location="\[\033[01;34m\]\w"
local __git_branch_color="\[\033[31m\]"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __prompt_tail="\[\033[3m\]$"
local __last_color="\[\033[00m\]"
@steinnes
steinnes / rateof.sh
Created June 20, 2014 17:04
rateof.sh
#!/bin/bash
CMD=$1
cmds=`bash -c "$CMD"`
while [ 0 ]; do
new_cmds=`bash -c "$CMD"`;
let cmds_per_sec="$new_cmds - $cmds";
echo $cmds_per_sec;
cmds=$new_cmds;
@steinnes
steinnes / heartbleedcheck.sh
Last active August 29, 2015 13:58
ELB Heartbleed alerter
#!/bin/bash
# quick little script to make an alert window popup when AWS have updated the SSL on
# a host -- can be used to monitor something else, but the best use case is obviously
# when waiting for a third party to fix something.
#
# uses https://github.com/titanous/heartbleeder/
# runs on OS X -- probably the osascript line can be replaced with a similar oneliner
# on linux
HOST=$1
@steinnes
steinnes / redis-dump-keys-safely.py
Created April 1, 2014 16:31
Because "keys *" can block for several seconds (or longer) on large redis instances, this script scans through keys and dumps them safely. Suffers from the standard SCAN limitations, so it actually may never finish.
import redis
import sys
port = None
try:
port = int(sys.argv[2])
except:
pass
r = redis.Redis(sys.argv[1], port)
@steinnes
steinnes / bm.py
Created March 17, 2014 13:24
Small benchmark script to time different serialization methods as we were evaluating json vs. simplejson vs. ujson vs. msgpack.
import json
import simplejson
import ujson
import msgpack
import time
class Timer(object):
def __init__(self, name):
self.name = name