Skip to content

Instantly share code, notes, and snippets.

View nottrobin's full-sized avatar

Robin Winslow nottrobin

View GitHub Profile
@nottrobin
nottrobin / settings.json
Created March 24, 2020 14:49
VSCode editor settings for black, flake8, html
{
"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 / sorting_and_search_algorithms.py
Last active February 26, 2020 16:33
Sorting and search algorithms in Python - quick sort, merge sort, linear search, binary search
def quick_sort(items):
"""
https://en.wikipedia.org/wiki/Quicksort
Worst-case complexity: O(n^2)
Best-case complexity: O(n log n)
Auxilliary space complexity: O(n), can be O(log n) if you're clever
"""
pivot_item = items[-1]
@nottrobin
nottrobin / create-pdf.sh
Last active November 22, 2019 10:05
Create PDF of server docs from https://ubuntu.com/server/docs
#! /usr/bin/env bash
# ===
# This will pull down the server documentation from https://discourse.ubuntu.com/c/server/guide
# ===
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
# Empty the documents directory, so we get fresh documents
@nottrobin
nottrobin / nginx-sigterm.Dockerfile
Created November 15, 2019 13:07
nginx with SIGTERM immediately exits
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
CMD ["nginx", "-g", "daemon off;"]
@nottrobin
nottrobin / nginx-sigquit.Dockerfile
Created November 15, 2019 11:48
nginx should use STOPSIGNAL SIGQUIT
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 / why-monzo-should-be-open-source.md
Last active November 5, 2019 09:17
Why Monzo should be open source

A reply to the "Is Mondo open source" forum thread from 2016:


I know this was years ago, so I’d love it if, but I’m not hopeful that, Monzo’s attitude to Open Source might have changed.

This was such a painful thread to read. Yes, it’s unthinkable that a regular bank would open-source their code, in the same way that it’s unfortunately unthinkable that they would have reduced transaction time if they hadn’t been forced to, or that they would use standard 2-factor authentication methods. The banking sector have various delusions:

  • firstly their security needs are different from (greater than?) the rest of the tech industry, and so they need different methods
  • secondly that their use cases are legitimately so much more complicated, so they can’t possibly use the same tools and practices as the rest of software
@nottrobin
nottrobin / convert-django-to-jinja2-with-statements.sh
Created August 22, 2019 14:51
Convert Django templates' `{% include with ... %}` syntax to Jinja2's `{% with ... %}{% include %}{% endwith %}`
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\" %}\n {% include \"\$1\" %}\n{% endwith %}/" {} \;
find templates -name '*.html' -exec perl -p -i -e "s/ *[{]% +include +\"(.*)[\"'] +with +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] +([^=]+)=[\"']([^\"]*)[\"'] *%[}]/{% with \$2=\"\$3\",\n \$4=\"\$5\",\n \$6=\"\$7\",\n \$8=\"\$9\" %}\n {% include \"\$1\" %}\n{% endwith
@nottrobin
nottrobin / 1-concurrent_requests.py
Last active August 12, 2019 21:54
Compare time for concurrent requests in aiohttp vs grequests
#! /usr/bin/env python3
import asyncio
import grequests
from aiohttp import ClientSession
from timeit import default_timer
# aiohttp concurrent requests code from:
# https://gist.github.com/Den1al/2ede0c38fa4bc486d1791d86bcf9034e
@nottrobin
nottrobin / test-devun.sh
Last active June 14, 2019 12:47
Test out the devrun snap with ubuntu.com
snap install --devmode --beta dotrun
git clone -b dotrun [email protected]:nottrobin/ubuntu.com ubuntu-dotrun
cd ubuntu-dotrun
dotrun serve --watch
Redirect permanent /static/resources/ubuntu-core-16-security-whitepaper.pdf https://www.ubuntu.com/internet-of-things/core
Redirect permanent /core/get-started/raspberry-pi-2-3 https://www.ubuntu.com/download/iot/raspberry-pi-2-3
Redirect permanent /core/get-started/installation-medias https://www.ubuntu.com/download/iot/installation-media
Redirect permanent /core/get-started https://www.ubuntu.com/download/iot
Redirect permanent / https://www.ubuntu.com/desktop/developers
Redirect permanent /core https://www.ubuntu.com/download/iot
Redirect permanent /core/get-started/intel-nuc https://www.ubuntu.com/download/iot/intel-nuc
Redirect permanent /core/get-started/developer-setup https://forum.snapcraft.io
Redirect permanent /core/get-started/kvm https://www.ubuntu.com/download/iot/kvm
Redirect permanent /core/examples/snaps-on-mir https://tutorials.ubuntu.com/tutorial/secure-ubuntu-kiosk