Skip to content

Instantly share code, notes, and snippets.

View tartley's full-sized avatar
🍰
brb smashing the patriarchy

Jonathan Hartley tartley

🍰
brb smashing the patriarchy
View GitHub Profile
@tartley
tartley / auto-venv.sh
Last active December 2, 2025 15:08
Automatically activate/deactivate virtualenvs in `.venv` when we `cd` into their parent directory
# auto activate virtualenvs ------------------
# I suspect this could be rewritten to just use VIRTUAL_ENV directly,
# without needing the $parentdir variable at all.
function cd() {
builtin cd "$@"
# If we move out of a previous parentdir, deactivate the previous venv
if [[ -n "$parentdir" && "$PWD"/ != "$parentdir"/* ]]; then
@tartley
tartley / gist:b76785daf4383cdeb0bc3d24b7f2202d
Created November 21, 2025 22:10
Replace Firefox snap with apt on Ubuntu
# Ubuntu prefers the Firefox snap. Use the apt instead.
sudo snap remove --purge firefox
sudo add-apt-repository ppa:mozillateam/ppa
sudo apt update
sudo apt install firefox
# Also prefer the apt in future updates
sudo tee /etc/apt/preferences.d/firefox <<EOF
@tartley
tartley / time_time.py
Last active February 7, 2025 19:48
Time how long, on average, it takes to call time.time(), using only time.time() to measure.
#!/usr/bin/env python3
from time import time
# If we iterate a million times,
# then results per-call are in micro seconds.
ITERS = 1_000_000
UNIT = "µs"
# If our first loop below ONLY measures calls to time(),
# then the second loop below (which is to measure loop overhead)
@tartley
tartley / exitval in ps1
Created July 10, 2012 14:22
prepend a red 'last command exit value' to PS1, only for non-zero values.
# display red exit value if it isn't zero
PROMPT_COMMAND='EXITVAL=$?; '$PROMPT_COMMAND
GET_EXITVAL='$(if [[ $EXITVAL != 0 ]]; then echo -n "\[\e[37;41;01m\] $EXITVAL \[\e[0m\] "; fi)'
export PS1="$GET_EXITVAL$PS1"