Skip to content

Instantly share code, notes, and snippets.

Wes Winham winhamwr

Block or report user

Report or block winhamwr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@winhamwr
winhamwr / machine_setup.sh
Last active Dec 15, 2015
PolicyStat Ubuntu dev machine setup
View machine_setup.sh
#!/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 Aug 29, 2015
pydocx image handler for resizing images to their displayed size
View exporter.py
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 Feb 23, 2015
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
winhamwr / calc.py
Created Feb 5, 2015
Percentage of active customers using any-site login
View calc.py
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 Apr 30, 2014
PolicyStat's Pull Request Template
View pr_template.md

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 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 / test.py
Last active Dec 27, 2015
My first real dynamic-typing bug in 6 years of doing python and Django. Luckily, we caught it in code review.
View test.py
# 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 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 / insert_date.py
Created Oct 14, 2013
Autohotkey script for inserting the Excel compliant current date and time any time you type Dnow http://www.autohotkey.com/
View insert_date.py
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 Jul 23, 2013
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 ELEMENT_NODE = 1;
var TEXT_NODE = 3;
WYMeditor.editor.prototype.spellcheck = function() {
You can’t perform that action at this time.