Skip to content

Instantly share code, notes, and snippets.

View nottrobin's full-sized avatar

Robin Winslow nottrobin

View GitHub Profile
nottrobin /
Created January 26, 2016 01:42
Change directory / working directory context processor for python
import os
from contextlib import contextmanager
def working_directory(path):
A context manager which changes the working directory to the given
path, and then changes it back to its previous value on exit.
View git-prune
set -o errexit
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
exit 0
nottrobin / nginx-sigquit.Dockerfile
Created November 15, 2019 11:48
nginx should use STOPSIGNAL SIGQUIT
View nginx-sigquit.Dockerfile
FROM nginx
RUN echo 'server {\n\
listen 80 default_server;\n\
location / {\n\
}' > /etc/nginx/conf.d/default.conf
nottrobin / settings.json
Created March 24, 2020 14:49
VSCode editor settings for black, flake8, html
View settings.json
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"editor.formatOnSave": true,
nottrobin /
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 =
api = Github(token)
site = api.get_repo('nottrobin/gh-cms-example-site')
nottrobin /
Created November 8, 2016 09:57
git force-clone: clone a repository; if it already exists locally, reset it to a clone of the remote.
#! /usr/bin/env bash
set -euo pipefail
_usage() {
echo "
git-force-clone -b branch remote_url destination_path
nottrobin /
Created August 2, 2022 10:38
Add "web-and-design" topic to all our team's repos
import requests
import json
from github import Github
token = "REPLACE_ME"
g = Github(token)
org = g.get_organization("canonical")
teams = org.get_teams()
nottrobin /
Created June 9, 2022 21:13
Find latest commit, check for modified articles in it, check if it was added in this commit
#! /usr/bin/env bash
commit_id=$(git log --format="%H" -n 1)
articles=( $(git diff --name-only HEAD HEAD^ | egrep '^_articles') )
for article in "${articles[@]}"
article_added_in=$(git log --pretty=format:"%H" --diff-filter=A -- $article)
nottrobin /
Last active May 12, 2021 19:09
To clean out a Juju model so you can use it from scratch, without deleting and recreating it
# Clear out a model, for Juju 2
# ==
# Destroy all machines and remove applications
# --
clean_model() {
juju status --model ${model_name} --format json | jq '.machines' | jq -r 'keys[]' | xargs -n 1 juju remove-machine --force # Force destroy all machines
juju status --model ${model_name} --format json | jq '.applications' | jq -r 'keys[]' | xargs -n 1 juju remove-application # Remove all applications
watch -c -n 10 juju status --model ${model_name} --color
nottrobin /
Created August 24, 2020 22:21
Curl Ubuntu Boston
$ curl -I --resolve
HTTP/2 200
server: nginx/1.14.0 (Ubuntu)
date: Mon, 24 Aug 2020 22:21:24 GMT
content-type: text/html; charset=utf-8
content-length: 68552
vary: Accept-Encoding
strict-transport-security: max-age=15724800
cache-control: max-age=61, stale-while-revalidate=90
x-view-name: canonicalwebteam.templatefinder.templatefinder.template_finder