Skip to content

Instantly share code, notes, and snippets.

Avatar

Steinn Eldjárn Sigurðarson steinnes

View GitHub Profile
@steinnes
steinnes / bm.py
Created Mar 17, 2014
Small benchmark script to time different serialization methods as we were evaluating json vs. simplejson vs. ujson vs. msgpack.
View bm.py
import json
import simplejson
import ujson
import msgpack
import time
class Timer(object):
def __init__(self, name):
self.name = name
@steinnes
steinnes / redis-dump-keys-safely.py
Created Apr 1, 2014
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.
View redis-dump-keys-safely.py
import redis
import sys
port = None
try:
port = int(sys.argv[2])
except:
pass
r = redis.Redis(sys.argv[1], port)
@steinnes
steinnes / heartbleedcheck.sh
Last active Aug 29, 2015
ELB Heartbleed alerter
View heartbleedcheck.sh
#!/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
View 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;
View gitps1.sh
# 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\]"
View 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
@steinnes
steinnes / simpleproxy.rb
Created Sep 25, 2014
Homebrew formula for simpleproxy
View simpleproxy.rb
require "formula"
class Simpleproxy < Formula
homepage ""
url "http://downloads.sourceforge.net/project/simpleproxy/simpleproxy/3.4/simpleproxy-3.4.tar.gz"
sha1 "ec98a2e622507f5b6ecdbbe0b50d2fc82480bcc2"
def install
system "./configure", "--disable-debug",
"--disable-dependency-tracking",
@steinnes
steinnes / pgbouncer.py
Created Sep 27, 2014
pgbouncer datadog agent check
View pgbouncer.py
from checks import AgentCheck, CheckException
class pgBouncer(AgentCheck):
"""Collects pgbouncer statistics
"""
RATE = AgentCheck.rate
GAUGE = AgentCheck.gauge
def __init__(self, name, init_config, agentConfig):
@steinnes
steinnes / daskarabiner.md
Last active Aug 29, 2015
Karabiner XML for MBP + Das Keyboard with Icelandic
View daskarabiner.md

I recently got a new mechanical keyboard named "Das Keyboard". I decided to go for the Brown Cherry MX keys which provide excellent tactile feedback while not being the absolute loudest there are.

I am using the keyboard with my 13" MacBook Pro Retina, which is connected to a Thunderbolt display, and it works .. mostly. I guess if it worked I wouldn't need to remap keys? ¯\_(ツ)_/¯

The Problem

View fabric-runit-setup.py
def setup_runit_service(self, service_name, runfile, logrunfile=None, enable_service=True):
self.shell.sudo("mkdir -p /etc/rserv")
self.shell.sudo("mkdir -p /etc/rserv/{}".format(service_name))
self.shell.upload_file(runfile, "/etc/rserv/{}/run".format(service_name))
self.shell.sudo("chmod +x /etc/rserv/{}/run".format(service_name))
if logrunfile:
self.shell.sudo("mkdir -p /etc/rserv/{}/log".format(service_name))
self.shell.sudo("mkdir -p /etc/rserv/{}/log/main".format(service_name))
self.shell.upload_file(logrunfile, "/etc/rserv/{}/log/run".format(service_name))
self.shell.sudo("chmod +x /etc/rserv/{}/log/run".format(service_name))