Skip to content

Instantly share code, notes, and snippets.


Stefan van der Walt stefanv

View GitHub Profile
View typed-libraries.rst

Typing Guidance for Python Libraries

Much of Python’s popularity can be attributed to the rich collection of Python libraries available to developers. Authors of these libraries play an important role in improving the experience for Python developers. This document provides some recommendations and guidance for Python library authors.

These recommendations are intended to provide the following benefits:

stefanv / http_server_python
Last active Sep 23, 2021
Multi-threaded HTTP server in Python
View http_server_python
#!/usr/bin/env python3
# See
# Python 3.x
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
#!/usr/bin/env python3
import subprocess
import time
import os
from datetime import datetime
# Check after every X minutes
delay = 60
import numpy as np
validators_online = 102
consensus_size = 28
replacement_factor = 4
validators = np.arange(validators_online)
replacement_N = len(validators) // replacement_factor
N = 10000
stefanv /
Last active Dec 10, 2020
Advent of Code :: Problem 10
adapters = np.sort(adapters)
start = 0
end = np.max(adapters) + 3
cache = {}
def next_in_line(last_link):
if last_link in cache:
return cache[last_link]
stefanv / i3_autorandr
Created Aug 27, 2020
Automated setup of side-by-side displays in i3
View i3_autorandr
# Modified from:
# Switch screens on, in case they were asleep
xset dpms force on
# Find laptop display (DEFAULT)
DEFAULT=`xrandr | grep -e eDP.*connected | cut -f 1 -d ' '`
stefanv / dotemacs-zenburn.el
Created May 15, 2020
Customizing zenburn for org-mode to highlight all headings
View dotemacs-zenburn.el
(use-package zenburn-theme
(setq org-fontify-whole-heading-line t
org-fontify-quote-and-verse-blocks t)
(load-theme 'zenburn t)
`(org-level-1 ((t (:inherit ,z-variable-pitch
:foreground ,zenburn-orange
stefanv / fetch_prs
Last active Dec 5, 2019
NumPy: nr of PRs per contributor
View fetch_prs
curl "" > prs0.json
curl "" > prs1.json
curl "" > prs2.json
stefanv /
Created Dec 4, 2019
Auto-crop jpeg image without recompressing (requires Python 3 with scikit-image, and jpegtran)
#!/usr/bin/env python
import subprocess
import sys
from skimage import io, filters
import numpy as np
filename = sys.argv[1]
base, ext = filename.rsplit('.', 1)
outfile = f'{base} cropped.{ext}'