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 / 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 / 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 / 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 / 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))
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-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():
import time
timings = (
(1, 'up'),
(2, 'down'),
(7, 'up'),
(8, 'down'),
(13, 'up'),
(14, 'down'),
(19, 'up'),
@steinnes
steinnes / synchronize.py
Created May 15, 2016 12:23
python threading lock example
import threading
import time
from functools import wraps
FN_LOCKS = {}
class Lock(object):
def __init__(self, func_id):
global FN_LOCKS
@steinnes
steinnes / nginx.conf
Created December 30, 2016 13:11
nginx config to listen on IPv6 and proxy
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
@steinnes
steinnes / circle-ci-env-variables.txt
Created February 9, 2017 00:12
Circle CI environment variables
# This is a list of Circle CI environment variables, pulled on Feb 9th 2017 @ 00:10
# This can be useful for example when running tests inside a docker and you wish to
# pass environment variables into the docker via docker-compose. That's why I made
# this list by starting a build with SSH enabled, and executing:
#
# ubuntu@box103:~$ env|grep ^CI|cut -d\= -f1|sort -u
CI
CI_PULL_REQUEST
CI_PULL_REQUESTS