Skip to content

Instantly share code, notes, and snippets.

@winhamwr
winhamwr / ipsec-monitor.sh
Created Dec 10, 2013
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…
View ipsec-monitor.sh
#!/bin/bash
function main()
{
monitor_from_file $*
}
function monitor_vpn_ip_port()
{
local CONN_NAME=$1
@winhamwr
winhamwr / tutorial.md
Created Jun 4, 2012
Creating a repeatable, dynamic site to site VPN with OpenSwan on Ubuntu 10.04 from Amazon EC2
View tutorial.md

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 / celery task using wait()
Created Mar 12, 2010
celery task using wait()
View 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 / kegbot.conf
Created Jan 10, 2011
supervisord configuration for kegbot
View kegbot.conf
[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 / celeryd_rotate
Created May 17, 2010
logrotate.d configuration for celery
View celeryd_rotate
/var/log/celery/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
copytruncate
}
@winhamwr
winhamwr / jquery.wymeditor.embed.js
Created Jun 19, 2012
WYMeditor embed plugin with video/source support
View jquery.wymeditor.embed.js
/**
* 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 Nov 1, 2011
Javascript to do autosave on a form using WYMeditor
View wym_autosave.js
/**
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 / awesome_task.py
Created May 17, 2012
Celery base task that adds some niceties for longish-running or singleton jobs.
View awesome_task.py
"""
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 / wait_for_vagrant.sh
Created Oct 23, 2013
Bash script to wait until a vagrant box is ready
View wait_for_vagrant.sh
#! /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
@winhamwr
winhamwr / Script for creating a personal package repository in ubuntu
Created Feb 26, 2010
Script for creating a personal package repository in ubuntu
View 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)