Skip to content

Instantly share code, notes, and snippets.

View ghaering's full-sized avatar

Gerhard Häring ghaering

View GitHub Profile
#!/usr/bin/env python2.7
from __future__ import print_function
import commands
import os
import stat
from gitlab import Gitlab
def get_clone_commands(token, repo_root):
con = Gitlab("http://gitlab.your.domain", token)
@ghaering
ghaering / docker.service
Created March 10, 2016 12:51
My Docker service file for systemd
➜ repo git:(master) ✗ sudo cat /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket
[Service]
Type=notify
ExecStart=/usr/bin/docker daemon --bip=172.17.0.1/16 -H fd://
@ghaering
ghaering / gist:58b533a14fb17175b290
Created February 14, 2016 20:50
Fix Docker settings on Arch Linux
➜ ~ git:(master) ✗ diff -C3 /usr/lib/systemd/system/docker.service /etc/systemd/system/docker.service
*** /usr/lib/systemd/system/docker.service 2016-02-12 00:53:30.000000000 +0100
--- /etc/systemd/system/docker.service 2016-02-14 21:48:19.992194898 +0100
***************
*** 6,13 ****
[Service]
Type=notify
! ExecStart=/usr/bin/docker daemon -H fd://
MountFlags=slave
@ghaering
ghaering / guard_cache_size.py
Last active August 29, 2015 14:07
Make sure a cache directory does not overflow the entire filesystem
# Keeps a cache directory from growing over a given size limit.
#
# There are two modes to manage the cache folder:
# 1) absolute size limit of the cache folder (--size flag);
# 2) keep percentage free space on filesystem (--percent_free flag)
import asyncore
from collections import OrderedDict
import os
import sys
@ghaering
ghaering / gist:3dffa08717c147f256d6
Created July 30, 2014 17:09
DynamoDB atomic increment
import boto.dynamodb2
def get_connection():
con = boto.dynamodb2.connect_to_region("eu-west-1")
return con
def get_new_version(con, package_name):
item = con.update_item(
@ghaering
ghaering / create_billing_alarms.py
Created June 25, 2014 09:36
Create AWS Billing alarms tor SNS topis "AWSBill"
from boto import sns
from boto.ec2 import cloudwatch
MY_TOPIC = "AWSBill"
sns_con = sns.connect_to_region("us-east-1")
sns_topic = [v.values()[0] for v in sns_con.get_all_topics()["ListTopicsResponse"]["ListTopicsResult"]["Topics"] if v.values()[0].endswith(":" + MY_TOPIC)][0]
cw_con = cloudwatch.connect_to_region("us-east-1")
@ghaering
ghaering / dbg-cloud-init
Created May 27, 2014 07:22
Re-run cloud init scripts on Ubuntu 12.04 (AWS)
#!/bin/sh
rm -rf /var/lib/cloud/sem/* /var/lib/cloud/instance /var/lib/cloud/instances/*
cloud-init start 2>&1 > /dev/null
cloud-init-cfg all final
@ghaering
ghaering / gist:9f05a362489d3ea5c9c6
Created May 5, 2014 13:57
change to new salt master
service salt-minion stop
rm -f /etc/salt/pki/minion/minion_master.pub
echo "master: salt" > /etc/salt/minion
service salt-minion start
@ghaering
ghaering / top.sls
Created May 1, 2014 20:27
salt top file for muliple environments (production, staging)
{% for environment in 'prod', 'devel' %}
{% if environment == 'prod' %}
base:
{% else: %}
{{environment}}:
{% endif %}
'G@roles:offlinemaps and G@environment:{{environment}}':
- match: compound
- cron
@ghaering
ghaering / gist:7320226
Created November 5, 2013 14:54
Dynamic method creation does not work as excpected
>>> class API:
... def __init__(self):
... pass
...
>>> for i in range(10):
... name = "print_number_%i" % i
... def print_func(self):
... print "my result is", i
... setattr(API, name, print_func)
...