Skip to content

Instantly share code, notes, and snippets.

@winhamwr
winhamwr / machine_setup.sh
Last active December 15, 2015 20:33
PolicyStat Ubuntu dev machine setup
#!/bin/bash
# Gist available at: https://gist.github.com/winhamwr/3bad9f4e05885b599a4e
set -e;
export JOB_IDLE_TIMEOUT=60
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
winhamwr / exporter.py
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
winhamwr / out.log
Created February 23, 2015 18:58
berks traceback
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
winhamwr / calc.py
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(
Customer.objects.annotate(
tenant_count=Count('tenant_set')
).filter(tenant_count__gt=1).values_list('settings__pk', flat=True)
)
num_systems = len(system_setting_pks)
@winhamwr
winhamwr / pr_template.md
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
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 / test.py
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)
UserFactory(
username='existing_username',
tenant=self.tenant,
)
@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
@winhamwr
winhamwr / insert_date.py
Created October 14, 2013 17:04
Autohotkey script for inserting the Excel compliant current date and time any time you type Dnow http://www.autohotkey.com/
import datetime
format_str = '%Y-%m-%d %H:%M:%S'
now = datetime.datetime.now()
output = now.strftime(format_str)
keyboard.send_keys(output)
## Installation
@winhamwr
winhamwr / jquery.wymeditor.spellcheck.js
Created July 23, 2013 14:04
Semi-ghetto WYMeditor spellcheck plugin
var incorrect_spelling_style = {
'border-bottom': '1px dashed #FF0000'
};
var incorrect_spelling_class = 'incorrect';
// No constants for Node.* IE
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
WYMeditor.editor.prototype.spellcheck = function() {