Skip to content

Instantly share code, notes, and snippets.

View nottrobin's full-sized avatar

Robin Winslow nottrobin

View GitHub Profile
@nottrobin
nottrobin / github-api-create-pull-request-end-to-end.py
Created September 6, 2016 14:30
With Github API v3, create branch, commit a change to a file and open a pull request
#! /usr/bin/env python
from base64 import b64decode
from github import Github
with open('access-token.txt') as token_file:
token = token_file.read().strip()
api = Github(token)
site = api.get_repo('nottrobin/gh-cms-example-site')
@nottrobin
nottrobin / update-file-through-github-api.py
Created September 6, 2016 11:29
Updating a file with Github CMS v3
#! /usr/bin/env python
from base64 import b64decode
from github import Github
with open('access-token.txt') as token_file:
token = token_file.read().strip()
api = Github(token)
@nottrobin
nottrobin / setup-lxc-shared-directory.sh
Last active January 20, 2017 16:03
How to set up a *writeable* shared directory in an LXC/LXD container
[robin@xps ~ ]$ lxc launch ubuntu:16.04 my-xenial # Create & start a new container
[robin@xps ~ ]$ getfacl ./share/ # Check extended permissions on "share" directory
# file: share
# owner: robin
# group: robin
user::rwx
group::rwx
other::r-x
[robin@xps ~ ]$ sudo ls -ld /var/lib/lxd/containers/my-xenial # Find the user ID for my container (165536)
[sudo] password for robin:
import json
with open('redirects.yaml') as redirects_file:
redirects = json.load(redirects_file)
new_redirects = {}
for request, target in redirects.iteritems():
if '?' in request:
# Remove anything with a question mark (it wont work)
@nottrobin
nottrobin / redirects-json-from-txt.py
Created April 6, 2016 13:51
Convert a file of doublespaced redirect instructions to JSON
#!/usr/bin/env python
"""
This will consume a 'redirects.txt' file containing redirects of the format:
request/path http://example.com/target/path # some comment
And output the same redirects in formatted JSON format instead:
{
@nottrobin
nottrobin / clbin-helper-function.sh
Last active February 29, 2016 11:58
Helper function for https://clbin.com.
# https://clbin.com helper function
# ===
#
# Usage examples:
# ---
#
# $ echo "hello world" | clbin
# https://clbin.com/SwP5h
# $ curl https://clbin.com/SwP5h
# hello world
$ curl -I http://cn.ubuntu.com/static/css/styles.css?v=d5d2934
...
Cache-Control: public, max-age=31557600
@nottrobin
nottrobin / django-setting-whitenoise-max-age.py
Created February 25, 2016 10:13
Django settings example for setting max-age headers with Whitenoise
# myapp/settings.py
WHITENOISE_MAX_AGE = 31557600
$ curl -I localhost:8000/static/css/styles.css?v=d5d2934
...
Cache-Control: public, max-age=0
@nottrobin
nottrobin / django-settings-whitenoise.py
Created February 25, 2016 10:09
Django settings example for Whitenoise
# myapp/settings.py
STATIC_ROOT = 'static'
STATIC_URL = '/static/'
# myapp/wsgi.py
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())