This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import redis | |
import time | |
i = 0 | |
conn = redis.Connection('localhost', 6379) | |
start_t = time.time() | |
for line in sys.stdin.xreadlines(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SWAPFILE=/var/swapfile | |
SWAP_MEGABYTES=2048 | |
if [ -f $SWAPFILE ]; then | |
echo "Swapfile $SWAPFILE found, assuming already setup" | |
exit; | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
container_commands: | |
01setup_swap: | |
command: "bash .ebextensions/setup_swap.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
timings = ( | |
(1, 'up'), | |
(2, 'down'), | |
(7, 'up'), | |
(8, 'down'), | |
(13, 'up'), | |
(14, 'down'), | |
(19, 'up'), |