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 / redis-pipe-commands.py
Created March 19, 2015 01:19
redis workload player
import sys
import redis
import time
i = 0
conn = redis.Connection('localhost', 6379)
start_t = time.time()
for line in sys.stdin.xreadlines():
def human_time_string(delta):
'''
Return a nice human readable "X days[, Y hours [and Y minutes]]" string
for a given datetime.timedelta
'''
minutes = delta.seconds // 60
hours = delta.seconds // 3600
minutes -= hours * 60 # subtract hours
days = delta.days
@steinnes
steinnes / redis-workload-record.py
Last active August 29, 2015 14:17
redis workload recorder
#!/usr/bin/env python
import time
import signal
import sys
import redis
import socket
def stop(sig, frame):
sys.stdout.flush() # flush whatever is there!
sys.stderr.write("Stopping due to {}\n".format(sig))
@steinnes
steinnes / udp-out.c
Created March 9, 2015 16:20
pointless udp dumper
/* read stuff from udp (on given port) and write it to stdout */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc, char *argv[])
@steinnes
steinnes / r.c
Created March 7, 2015 12:49
hiredis test
#include <stdio.h>
#include <hiredis/hiredis.h>
int redis_set(char *key, char *value) {
redisContext *c = redisConnect("127.0.0.1", 6379);
if (c != NULL && c->err) {
printf("Error connecting to redis: %s\n", c->errstr);
return -1;
}
redisCommand(c, "SET %s %s", key, value);
@steinnes
steinnes / dupdate.py
Created March 2, 2015 11:58
dict update vs. assignment speed
import time
class TimeIt(object):
def __init__(self, name):
self.name = name
def __enter__(self, *args, **kwargs):
self.start_t = time.time()
def __exit__(self, *args, **kwargs):
@steinnes
steinnes / fabric-runit-setup.py
Created February 20, 2015 22:36
runit + svlogd example
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))
@steinnes
steinnes / daskarabiner.md
Last active August 29, 2015 14:13
Karabiner XML for MBP + Das Keyboard with Icelandic

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

@steinnes
steinnes / pgbouncer.py
Created September 27, 2014 15:33
pgbouncer datadog agent check
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 / simpleproxy.rb
Created September 25, 2014 02:17
Homebrew formula for simpleproxy
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",