Skip to content

Instantly share code, notes, and snippets.

View awestendorf's full-sized avatar

Aaron Westendorf awestendorf

View GitHub Profile
@awestendorf
awestendorf / chai_example.py
Created February 28, 2011 21:46
An example of Chai
from chai import Chai
class CustomObject (object):
def get(self, arg):
pass
class TestCase(Chai):
def test_mock_get(self):
obj = CustomObject()
expect(obj.get).args('name').returns('My Name')
@awestendorf
awestendorf / mongo_rebalance.py
Created March 7, 2011 15:16
An example of rebalancing a pymongo MasterSlaveConnection
from pymongo.connection import Connection, _str_to_node
from pymongo.master_slave_connection import MasterSlaveConnection
from pymongo.errors import AutoReconnect,DuplicateKeyError,CollectionInvalid
import time
# validate slaves every 5 minutes
VALIDATE_INTERVAL = 5 * 60
class ClusterConnection(MasterSlaveConnection):
@awestendorf
awestendorf / synaptics-np900x3c.conf
Created October 30, 2012 01:30
Synaptics Configuration for Samsung Series 9 NP900X3C
# /usr/share/X11/xorg.conf.d/52-synaptics-np900x3c.conf
#
# There are a lot of examples out there; they and the (K)Ubuntu defaults suck. Keeping this updated as I work to
# make my awesome laptop usable.
# Configure clickpad for Samsung Series 9 (NP900X3C).
Section "InputClass"
Identifier "np900x3c clickpad"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
@awestendorf
awestendorf / gist:10398084
Last active August 29, 2015 13:58
Example of old libssl linked in desktop applications
~$ sudo grep -l 'libssl.*deleted' /proc/*/maps | tr -cd 0-9\\n | xargs -r ps u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
* 794 0.5 2.3 3805132 186696 ? Sl Mar18 194:22 /usr/bin/amarok
* 3351 0.0 0.1 456840 9940 ? S Mar10 0:04 python /usr/bin/printer-applet
* 11789 0.0 0.1 86420 10540 ? S Apr04 0:00 /usr/bin/python /usr/share/apt-xapian-index/update-apt-xapian-index-dbus
@awestendorf
awestendorf / proxy.js
Created April 18, 2014 15:52
SSL proxy for custom Tender domains
// A simple node.js proxy which will force SSL encryption on support.yourcompany.com
// and forward through the secure tenderapp domain for your support account.
// npm install http-proxy
var fs = require('fs'),
http = require('http'),
httpProxy = require('http-proxy');
httpProxy.createServer({
ssl: {
@awestendorf
awestendorf / flake8-git
Created May 14, 2015 19:38
Run flake8 on the changes in your branch
export CUR_BRANCH=$(git name-rev --name-only HEAD) && git diff --name-only $CUR_BRANCH $(git merge-base $CUR_BRANCH master) | grep .py | xargs flake8
@awestendorf
awestendorf / flake8-pre-commit
Last active May 17, 2018 16:01
Run flake8 on the set of changes in a pre-commit hook
#!/bin/bash
# Place in .git/hooks/pre-commit
# Filters out deleted files with --diff-filter
# GNU
git diff --cached --name-only --diff-filter=ACMRTUXB | grep .py | xargs --no-run-if-empty flake8 $FLAKE
# BSD
git diff --cached --name-only --diff-filter=ACMRTUXB | (grep .py || echo " ") | xargs flake8 $FLAKE
@awestendorf
awestendorf / remove-old-kernels.sh
Last active August 23, 2017 13:09
Removes old kernels from debian/ubuntu
#!/bin/bash
# Thank you to the person who answered a long-lost post on the internet with this code,
# which I have been using successfully for many years
sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get purge $@
@awestendorf
awestendorf / get-file.sh
Created March 18, 2019 18:38
Get a file off a remote system using an SSH tunnel through a gateway
#!/bin/bash
# Fetch a file from a host in a datacenter. Example:
# ./get-file.sh my-datacenter my-host ~/my.file
# spawn tunnel
ssh -n -t -t -L 22000:$2:22 $1 &
TUNNEL=$!
sleep 5
@awestendorf
awestendorf / put-file.sh
Created March 18, 2019 18:42
Put a local file on to a remote system using an SSH tunnel through a gateway
#!/bin/bash
# Fetch a file from a host in a datacenter. Example:
# ./put-file.sh my-datacenter my-host ~/local.file ~/my.file
# spawn tunnel
ssh -n -t -t -L 22000:$2:22 $1 &
TUNNEL=$!
sleep 5