Skip to content

Instantly share code, notes, and snippets.

View boris317's full-sized avatar

Shawn Adams boris317

View GitHub Profile
@boris317
boris317 / log_context.py
Created June 5, 2014 13:57
Context manager for testing log output
import logging
from contextlib import contextmanager
from cStringIO import StringIO
@contextmanager
def log_context(logger_name, level=logging.DEBUG, formatter=None):
"""
:param logger_name: Name of your logger as passed to ``logging.getLogger``.
:param level: (optional) logging level to capture.
@boris317
boris317 / kodi.conf
Created February 12, 2015 15:13
kodi upstart script for Kodibuntu
# kodi-upstart
env DISPLAY=:0.0
description "Kodi upstart script"
author "Shawn Adams"
start on (filesystem and stopped udevtrigger)
stop on runlevel [016]
# tell upstart to respawn the process if abnormal exit
[Unit]
Description=CouchPotato application instance
[Service]
ExecStart=/media/nzb_apps/CouchPotatoServer/CouchPotato.py --daemon --data_dir=/media/nzb_apps/.couchpotato
GuessMainPID=no
Type=forking
User=root
Group=root
@boris317
boris317 / digital_ocean.py
Created February 18, 2015 19:40
Modifying ansible's DO dynamic inventory to return more helpful groups that suite my needs
# in for loop of method 'build_inventory'
if "-" in droplet['name']:
# Create new groups for names like prod-appname-whatever
# Given the above name, 2 new groups would be created "prod"
# and "prod-appname"
parts = droplet['name'].split("-")
if len(parts) > 1:
self.push(self.inventory, "-".join(parts[0:2]), dest)
self.push(self.inventory, parts[0], dest)

Keybase proof

I hereby claim:

  • I am boris317 on github.
  • I am shawnbytes (https://keybase.io/shawnbytes) on keybase.
  • I have a public key whose fingerprint is 85AC 20B8 9C56 B0D5 F0F5 360B 0B04 9462 EDE5 D0C4

To claim this, I am signing this object:

@boris317
boris317 / gist:28ca0ce271118bad51bb
Created March 26, 2015 15:12
P4 get the diff of a change list
# p4 diff by changelist
function p4d {
if [ "$1" == "" ]
then
echo "usage: p4d CL";
return 1;
fi
p4 opened -c $1 | sed -e 's/#.*//' | p4 -x - diff -du | less
}
@boris317
boris317 / install-packer.sh
Created May 16, 2015 14:50
Running packer from source (OSX)
#!/bin/bash
# Usage: $ ./install-packer.sh
brew install golang
# Create go workspace dir
mkdir ~/golang
cat << EOF > ~/.bashrc
# Golang
export GOPATH=$HOME/golang
@boris317
boris317 / statsd-tcpdump.sh
Last active November 14, 2017 16:43
Verify data is being fed to collectd and statsd
# statsd
sudo tcpdump -i eth0 -p -n -s 1500 -A udp port 8125
# statsd flushing to graphite
sudo tcpdump 'port 2005 or 2009' -s0 -A
# collectd
sudo tcpdump -i eth0 -p -n -s 1500 -A udp port 25827
#!/usr/bin/env python
import sys
print "\\n".join([l.strip() for l in sys.stdin.readlines()])
@boris317
boris317 / test.js
Created July 29, 2016 01:32
RXJS Chaining HTTP Calls
var http = require('http');
var RX = require('rx');
var request = require('request');
function get(url) {
return RX.Observable.create(function(observer) {
request(url, function(err, response, body) {
if (err) {
observer.onError(err);
return;