Skip to content

Instantly share code, notes, and snippets.

@timhughes
timhughes / settings.py
Created October 16, 2013 21:00
Django RotatingFileHandle example
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
#!/usr/bin/env python
#
# Copyright 2012 Patrick Hetu <patrick.hetu@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
import simplejson as json
import lxml
class objectJSONEncoder(json.JSONEncoder):
"""A specialized JSON encoder that can handle simple lxml objectify types
>>> from lxml import objectify
>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
>>> objectJSONEncoder().encode(obj)
'{"price": 1.5, "author": "W. Shakespeare"}'
"""
@timhughes
timhughes / virt-sliver
Last active December 29, 2015 17:29
Basic script to create qcow2 backed kvm domains based on a golden domain. To install the the dependencies on fedora 19 run the following: yum install libvirt-client qemu-img libguestfs-tools xmlstarlet libxml2 The virt-sysprep tool can do much more than this and I could potentially set the hostname and configure the machine to run some scripts w…
#!/bin/bash
# Requirements on Fedora are:
# libguestfs-tools for virt-sysprep
# xmlstarlet
# libvirt-client
# qemu-img
# libxml2 for xmllint
#
# Usage:
@timhughes
timhughes / puppet-testing
Last active December 31, 2015 08:59
Puppet testing environment
Puppet testing
==============
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
TODO: we probably need the puppet gem installed in the rvm for any of this to work
Initial install of RVM::
@timhughes
timhughes / puppet-master.sh
Last active December 31, 2015 14:19
Install a puppet master with Apache and Passenger using puppet modules. This script works nicely on a CentOS 6 install.
#!/bin/bash
hostname $1
grep -q '^HOSTNAME' /etc/sysconfig/network && sed -i "s/HOSTNAME=.*$/HOSTNAME=$(hostname -f)/g" /etc/sysconfig/network || echo "HOSTNAME=$(hostname -f)" >> /etc/sysconfig/network
grep -q '^search' /etc/resolv.conf && sed -i "s/search=.*/search $(hostname -d)/g" /etc/resolv.conf || echo "search $(hostname -d)" >> /etc/resolv.conf
echo $(hostname -i|awk '{print $1}') $(hostname) >> /etc/hosts && cat /etc/hosts|uniq > /etc/hosts_tmp && /bin/mv /etc/hosts_tmp /etc/hosts
@timhughes
timhughes / httpd.docker
Last active December 31, 2015 19:08
Docker file for creating a http server which is managed by supervisord
# HTTP server
#
# Need to get the supervisord xmlrpc server listening on 9001 so that we can control it remotely
#
# Create and run::
#
# docker build -t timhughes/webserver - < httpd.docker
# docker run -t timhughes/webserver
#
# Base stuff for supervisor
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "your@email.to.match" ]
@timhughes
timhughes / git-unsorted-log.go
Last active April 28, 2017 09:51
An example of howto user git2go https://github.com/libgit2/git2go which is a libgit2 bindings package for golang
/*
requires libgit2
*/
package main
import (
@timhughes
timhughes / pysyslog.py
Created April 11, 2014 11:51
Python logging to syslog
import logging
import logging.handlers
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler('localhost', 514)
my_logger.addHandler(handler)
for i in range(20):