Skip to content

Instantly share code, notes, and snippets.

View boris317's full-sized avatar

Shawn Adams boris317

View GitHub Profile

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 / 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)
[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 / 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
@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 / 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 / base_converter.py
Last active December 25, 2015 18:09
Encode base 10 integer into other bases
class BaseConverter(object):
"""
Class for encoding/decoding base 10 values to/from another base
"""
def __init__(self, base, base_digits):
"""
:param base: (int) the base (e.g 2, 16, 64)
:param base_digits: (iterator) of base digits (e.g "01" for base 2, etc)
"""
self.base = base
@boris317
boris317 / build.sh
Created October 1, 2012 15:42
OpenShift action hooks for python tornado deployment.
#!/bin/bash
#
# .openshift/action_hooks/build
#
DIR=$( cd "$( dirname "$0" )" && pwd )
source $DIR/../env.sh
if [ ! -d $X_OPENSHIFT_VENV ]; then
echo "[build] $(virtualenv --distribute $X_OPENSHIFT_VENV)"
#!/bin/bash
DIR=$( cd "$( dirname "$0" )" && pwd )
source $DIR/../env.sh
if [ ! X_OPENSHIFT_RUNNING_LOCAL ]; then
source $X_OPENSHIFT_VENV/bin/activate
fi
@boris317
boris317 / flask_shell.py
Created September 25, 2012 17:00
IPython interactive shell + Flask App
from exampleapp import app
import IPython
app.testing = True
test_client = app.test_client()
welcome_message = """Welcome to your Flask CLI environment.
The following variables are available to use:
app -> Your Flask app instance.