Skip to content

Instantly share code, notes, and snippets.

winhamwr /
Last active December 15, 2015 20:33
PolicyStat Ubuntu dev machine setup
# Gist available at:
set -e;
make --makefile=$WORKSPACE/scripts/hudson/Makefile log_job_started_for_idle_shutdown;
sudo apt-get update;
sudo apt-get install -y;
sudo apt-get install -y build-essential linux-headers-$(uname -r) nfs-kernel-server dkms dpkg-dev;
winhamwr /
Last active August 29, 2015 14:23
pydocx image handler for resizing images to their displayed size
import base64
import logging
import cgi
import logging
import os
import posixpath
import re
import subprocess
import time
from tempfile import NamedTemporaryFile
winhamwr / out.log
Created February 23, 2015 18:58
berks traceback
View out.log
vagrant up dev
Bringing machine 'dev' up with 'virtualbox' provider...
==> dev: Loading Berkshelf datafile...
==> dev: Sharing cookbooks with VM
==> dev: Couldn't find Cheffile at ./Cheffile.
==> dev: Updating Vagrant's Berkshelf...
The following berks command failed to execute:
/opt/chefdk/bin/berks vendor /home/wes/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150126-5078-1e0wj59-dev --berksfile /home/wes/policystat/workspace/pstat/Berksfile
winhamwr /
Created February 5, 2015 16:19
Percentage of active customers using any-site login
from __future__ import division
from django.db.models import Count
system_setting_pks = list(
).filter(tenant_count__gt=1).values_list('settings__pk', flat=True)
num_systems = len(system_setting_pks)
winhamwr /
Created April 30, 2014 14:01
PolicyStat's Pull Request Template

What does this PR do?

Where should the reviewer start?

How should this be manually tested?

Any background context you want to provide?

Screenshots (if appropriate)

winhamwr /
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 9898` Adapted from a script posted by user "c b" on Strongswan [issu…
function main()
monitor_from_file $*
function monitor_vpn_ip_port()
local CONN_NAME=$1
winhamwr /
Last active December 27, 2015 17:29
My first real dynamic-typing bug in 6 years of doing python and Django. Luckily, we caught it in code review.
# This test passes, even though the existing-username validation is completely broken
class UsernameUpdateCSVTestCase(TestCase):
def test_new_username_already_exists_validation_error(self):
# If the new_username already exists on the same home site, we throw a
# validation error
site_admin_username, _ = split_username(self.site_admin_user.username)
winhamwr /
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 && ./ runserver'
# Uses doublinng backoff while waiting
# with_backoff() adapted from
# Retries a command a configurable number of times with backoff.
# The retry count is given by ATTEMPTS (default 5), the initial backoff
winhamwr /
Created October 14, 2013 17:04
Autohotkey script for inserting the Excel compliant current date and time any time you type Dnow
import datetime
format_str = '%Y-%m-%d %H:%M:%S'
now =
output = now.strftime(format_str)
## Installation
winhamwr / jquery.wymeditor.spellcheck.js
Created July 23, 2013 14:04
Semi-ghetto WYMeditor spellcheck plugin
View jquery.wymeditor.spellcheck.js
var incorrect_spelling_style = {
'border-bottom': '1px dashed #FF0000'
var incorrect_spelling_class = 'incorrect';
// No constants for Node.* IE
var TEXT_NODE = 3;
WYMeditor.editor.prototype.spellcheck = function() {