Skip to content

Instantly share code, notes, and snippets.

@winhamwr
winhamwr / Script for creating a personal package repository in ubuntu
Created February 26, 2010 20:38
Script for creating a personal package repository in ubuntu
#!/usr/bin/env python
import optparse, subprocess, logging, os, sys, shutil
APT_COMMAND = 'apt-get -o Dpkg::Options::="--force-confnew" -y --force-yes -qq install %s'
def apt_install(app):
logging.info("Calling: %s" % (APT_COMMAND % app))
subprocess.call(APT_COMMAND % app, shell=True)
@winhamwr
winhamwr / celeryd_rotate
Created May 17, 2010 14:35
logrotate.d configuration for celery
/var/log/celery/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
copytruncate
}
@winhamwr
winhamwr / celery task using wait()
Created March 12, 2010 17:24
celery task using wait()
def build_document_pdf(document, realtime=False, timeout=None, watermark=True):
"""
Builds and caches a PDF copy of this document.
If ``realtime`` is True, returns the URL to the PDF. Otherwise, the PDF is
generated as asynchronously in the background.
"""
if not timeout:
timeout = print_settings.PRINTING_TIMEOUT
pdf_generator = DocumentPdfGenerator()
@winhamwr
winhamwr / ipsec-monitor.sh
Created December 10, 2013 19:55
Script to check the status of ipsec tunnels and refresh them if they're down. This should be run from cron every minute. To add monitoring on a tunnel, add a commented-out `monitor` line with the IP and port to use for establishing connection status. eg. `#monitor 172.17.105.80 9898` Adapted from a script posted by user "c b" on Strongswan [issu…
#!/bin/bash
function main()
{
monitor_from_file $*
}
function monitor_vpn_ip_port()
{
local CONN_NAME=$1
@winhamwr
winhamwr / awesome_task.py
Created May 17, 2012 16:02
Celery base task that adds some niceties for longish-running or singleton jobs.
"""
Celery base task aimed at longish-running jobs that return a result.
``AwesomeResultTask`` adds thundering herd avoidance, result caching, progress
reporting, error fallback and JSON encoding of results.
"""
from __future__ import division
import logging
import simplejson
@winhamwr
winhamwr / tutorial.md
Created June 4, 2012 22:37
Creating a repeatable, dynamic site to site VPN with OpenSwan on Ubuntu 10.04 from Amazon EC2

Creating a dynamic site-to-site VPN with OpenSwan on Ubuntu 10.04 on EC2

Wes Winham winhamwr@gmail.com

There are many tutorials floating around the web that almost get you a dynamic VPN in EC2. The goal of this tutorial is to be a one-stop-shop for this specific setup.

@winhamwr
winhamwr / kegbot.conf
Created January 10, 2011 05:41
supervisord configuration for kegbot
[group:kegbot]
programs=kegbot_core,kegboard_daemon,kegbot_runserver
[program:kegbot_core]
command=/opt/kegbot/env/bin/kegbot_core.py
directory=/opt/kegbot
user=kegbot
environment=HOME='/home/kegbot'
numprocs=1
autostart=true
@winhamwr
winhamwr / jquery.wymeditor.embed.js
Created June 19, 2012 19:46
WYMeditor embed plugin with video/source support
/**
* WYMeditor : what you see is What You Mean web-based editor
* Copyright (c) 2005 - 2009 Jean-Francois Hovinne, http://www.wymeditor.org/
* Dual licensed under the MIT (MIT-license.txt)
* and GPL (GPL-license.txt) licenses.
*
* For further information visit:
* http://www.wymeditor.org/
*
* File Name:
@winhamwr
winhamwr / wym_autosave.js
Created November 1, 2011 15:39
Javascript to do autosave on a form using WYMeditor
/**
Automatically saves a policy every REFRESH milliseconds through AJAX,
but only when the .autosave form has changed. To use, add the class autosave
to your form.
Note: REFRESH must always be bigger than SAVE_TIMEOUT, otherwise a broken
save will cause deadlock for pending.
**/
function processJson(data) {
@winhamwr
winhamwr / wait_for_vagrant.sh
Created October 23, 2013 17:26
Bash script to wait until a vagrant box is ready
#! /bin/bash
# Sleep until we can successfully SSH into a vagrant box.
# eg. $ wait_for_vagrant devbox && vagrant ssh devbox --command 'cd project && ./manage.py runserver'
# Uses doublinng backoff while waiting
# with_backoff() adapted from http://stackoverflow.com/a/8351489
# Retries a command a configurable number of times with backoff.
#
# The retry count is given by ATTEMPTS (default 5), the initial backoff