Skip to content

Instantly share code, notes, and snippets.

View stefanv's full-sized avatar

Stefan van der Walt stefanv

View GitHub Profile
@stefanv
stefanv / org-gh-links.el
Created January 20, 2024 22:02
GitHub links for org mode
@stefanv
stefanv / install-deps
Last active November 4, 2023 21:45
Install build or other dependencies from pyproject.toml
#!/usr/bin/env python
import tomllib
import argparse
import sys
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument(
import numpy as np
from skimage.transform import warp, PolynomialTransform
from skimage import data
import matplotlib.pyplot as plt
def swirl(xy, x0, y0, R):
r = np.sqrt((xy[:,1]-x0)**2 + (xy[:,0]-y0)**2)
a = np.pi*r / R
xy = np.copy(xy)
xy[:, 1], xy[:, 0] = (

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
stefanv / http_server_python
Last active September 23, 2021 07:45
Multi-threaded HTTP server in Python
#!/usr/bin/env python3
# See https://github.com/Nakiami/MultithreadedSimpleHTTPServer/blob/master/MultithreadedSimpleHTTPServer.py
# Python 3.x
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
#!/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
stefanv / problem10.py
Last active December 10, 2020 17:05
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
stefanv / i3_autorandr
Created August 27, 2020 22:05
Automated setup of side-by-side displays in i3
#!/bin/bash
# Modified from: https://faq.i3wm.org/question/2332/flexible-monitor-setup/
SWITCH_WS="${HOME}/scripts/i3-switch-ws"
# 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 ' '`