Skip to content

Instantly share code, notes, and snippets.

View nottrobin's full-sized avatar

Robin Winslow nottrobin

View GitHub Profile
@nottrobin
nottrobin / working-directory.py
Created January 26, 2016 01:42
Change directory / working directory context processor for python
View working-directory.py
import os
from contextlib import contextmanager
@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.
Usage:
View git-prune
#!/bin/bash
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
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\
proxy_pass http://httpbin.org/delay/10;\n\
}\n\
}' > /etc/nginx/conf.d/default.conf
STOPSIGNAL SIGQUIT
@nottrobin
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": [
"--line-length",
"79"
],
"editor.formatOnSave": true,
@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
View github-api-create-pull-request-end-to-end.py
#! /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 / git-force-clone.sh
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.
View git-force-clone.sh
#! /usr/bin/env bash
set -euo pipefail
_usage() {
echo "
Usage:
git-force-clone -b branch remote_url destination_path
Example:
@nottrobin
nottrobin / update_topics.py
Created August 2, 2022 10:38
Add "web-and-design" topic to all our team's repos
View update_topics.py
import requests
import json
from github import Github
token = "REPLACE_ME"
g = Github(token)
org = g.get_organization("canonical")
teams = org.get_teams()
@nottrobin
nottrobin / find-changed-files.sh
Created June 9, 2022 21:13
Find latest commit, check for modified articles in it, check if it was added in this commit
View find-changed-files.sh
#! /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[@]}"
do
article_added_in=$(git log --pretty=format:"%H" --diff-filter=A -- $article)
@nottrobin
nottrobin / clean-juju-model.sh
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
View clean-juju-model.sh
# Clear out a model, for Juju 2
# ==
# Destroy all machines and remove applications
# --
clean_model() {
model_name=${1}
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
nottrobin / curl-ubuntu-boston.sh
Created August 24, 2020 22:21
Curl Ubuntu Boston
View curl-ubuntu-boston.sh
$ curl -I --resolve 91.189.91.44:443:ubuntu.com https://ubuntu.com
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