Skip to content

Instantly share code, notes, and snippets.

View boris317's full-sized avatar

Shawn Adams boris317

View GitHub Profile
@boris317
boris317 / gist:9675336
Last active August 29, 2015 13:57
Format a `JsonWeb` `ValidationError` stack
def format_validation_error(error, parent=None, indent=""):
def recurse(e, parent):
return format_validation_error(e, parent=p(parent),
indent=indent + " ")
def p(child):
if parent is None:
return child
@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 / commafloat_field.py
Created September 4, 2012 19:51
Subclass of wtforms.core.FloatField that handles floats with comma delimiters.
"""
For reference wtforms.core.FloatField
-------------------------------------
class FloatField(Field):
widget = widgets.TextInput()
def __init__(self, label=None, validators=None, **kwargs):
super(FloatField, self).__init__(label, validators, **kwargs)
existing_hash = {:foo=>"bar"}
other_hash.each_pair do |key, value|
if some_condition
existing_hash[key] = value
end
end