Skip to content

Instantly share code, notes, and snippets.

View nottrobin's full-sized avatar

Robin Winslow nottrobin

View GitHub Profile
@nottrobin
nottrobin / run gunicorn for bzr-sync.sh
Created January 28, 2015 14:29
Gunicorn command for running the bzr-sync server
gunicorn --keyfile /srv/bzr-sync/certs/bzr-sync.key --certfile /srv/bzr-sync/certs/bzr-sync.cert --pythonpath /srv/bzr-sync --bind 0.0.0.0:9052 wsgi:application
@nottrobin
nottrobin / bzr-sync.conf
Created January 28, 2015 14:32
upstart file for bzr-sync server
# /etc/init/bzr-sync.conf
# A WSGI application
# to sync a github repository to a launchpad one
description "BZR sync"
start on runlevel [2345]
stop on runlevel [016]
@nottrobin
nottrobin / start bzr-sync.sh
Created January 28, 2015 14:32
Start the bzr-sync upstart service
sudo start bzr-sync
@nottrobin
nottrobin / juju-first-machine-number.sh
Last active April 27, 2018 03:53
Get the machine number for the first unit of a juju service
#!/usr/bin/env bash
# Get the machine number for the first unit of a juju service
# Requires:
# - `jq` (http://stedolan.github.io/jq/)
# Usage:
# $ juju-machine-number.sh my-awesome-service
# 12
service_name=${1}
@nottrobin
nottrobin / juju-instance-id.sh
Created February 4, 2015 16:18
Get the instance-id of a juju machine
#!/usr/bin/env bash
# Get the instance ID for a juju machine, by machine number
# Requires:
# - `jq` (http://stedolan.github.io/jq/)
# Usage:
# $ juju-instance-id.sh 12
# 92e3ef6a-ba3d-4eb4-adbc-8be78f2c8abe
machine_number=${1}
@nottrobin
nottrobin / juju-first-instance-id.sh
Created February 4, 2015 16:20
Get the instance ID for the first machine used by a juju service
#!/usr/bin/env bash
# Get the instance ID for a juju machine, by machine number
# Requires:
# - `jq` (http://stedolan.github.io/jq/)
# - `juju-first-machine-number.sh` (https://gist.github.com/nottrobin/9e7ff961cc6c00a65c61)
# - `juju-instance-id.sh` (https://gist.github.com/nottrobin/f918f98a8e1e20803b5f)
# Usage:
# $ juju-first-instance-id.sh my-awesome-service
# 92e3ef6a-ba3d-4eb4-adbc-8be78f2c8abe
@nottrobin
nottrobin / is-secure-frontend.py
Created February 6, 2015 10:52
django-rest-framework - check if request is secure or is forwarded from a secure frontend
forwarded_protocol = request._request.META.get('HTTP_X_FORWARDED_PROTO', '')
is_secure = request.is_secure() or forwarded_protocol == 'https'
@nottrobin
nottrobin / renderers.py
Last active August 29, 2015 14:16
PrettyJSONFormatter for djangorestframework >= v3
from rest_framework.renderers import JSONRenderer
from django.conf import settings
class PrettyJSONRenderer(JSONRenderer):
"""
Extend the existing JSONRenderer from djangorestframework
by using settings.DEFAULT_JSON_INDENT
to always pretty-print JSON output
"""
@nottrobin
nottrobin / exceptions.py
Created March 3, 2015 13:12
PrettyAuthenticationFailed exception for djangorestframework
from rest_framework.exceptions import AuthenticationFailed
class PrettyAuthenticationFailed(AuthenticationFailed):
"""
A fork of the djangorestframework AuthenticationFailed exception
to simply allow the `detail` parameter to contain fully formed
JSON objects, rather than just text
"""
def __init__(self, detail=None):
`.:/osyhhhhyoo+/. ..-/::///:-..
.:shmdmMNNNNNNNMmmMNNhdsshhddhyyysoss+-`
`-odNMNdhhhyyysoooo+oyddmdh`-hhdmdhhhhysssssyy/.
./yNmhyhyyysyyyhdyyssy+ssoooo+/. :hhyyyyys+///o+ssdy:`
`/hmhhyhhyssydyysyosossyssyhhdddddh- :ysosyhdNNNmhs++/+dms:
`-smMMmmsssyyyssoy/+ssyhdyysss++////-o+ `osyddhyssyydhmNh+-+mNh:
`o/ydmNmhoosssyshyssyhsossooososshddmmhyso``:yyhdmdNdNNNdhdmNNy++mN+`
+NNNMds++sydhyss+so++o+sosydddhs+:-..``` ````.`--:/shhyosdh+yNs.
hMmyo:ohNdssooossososhdNmh+-.` `sho` `-odmyydmNMm: