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 / 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 / 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))
@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 / setup_swap.sh
Created March 15, 2016 02:01
swapfile setup script
#!/bin/bash
SWAPFILE=/var/swapfile
SWAP_MEGABYTES=2048
if [ -f $SWAPFILE ]; then
echo "Swapfile $SWAPFILE found, assuming already setup"
exit;
fi
@steinnes
steinnes / 01_setup_swap.config
Last active October 30, 2019 17:32
EB config file which executes setup_swap.sh
container_commands:
01setup_swap:
command: "bash .ebextensions/setup_swap.sh"
import time
timings = (
(1, 'up'),
(2, 'down'),
(7, 'up'),
(8, 'down'),
(13, 'up'),
(14, 'down'),
(19, 'up'),