Skip to content

Instantly share code, notes, and snippets.

View mikeckennedy's full-sized avatar

Michael Kennedy mikeckennedy

View GitHub Profile
@mikeckennedy
mikeckennedy / prune_uv_pythons.py
Last active August 30, 2026 11:45
prune_uv_pythons.py - Prune uv-managed Python installs, keeping only the newest patch per minor version
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = []
# ///
"""Prune uv-managed Python installs, keeping only the newest patch per minor version.
Why: uv installs a fresh patch release whenever one lands and never removes the old
one, so `uv python list` slowly fills with 3.13.12, 3.13.13, 3.13.14, 3.13.15, and so
on. Each of those is a complete standalone copy of Python sitting in
server {
listen 80;
server_name mkennedy.codes;
charset utf-8;
server_tokens off;
root /apps/static/mkennedy.codes/mkblog/mksite/public-prod;
index index.html;
# To allow for Let's Encrypt
@mikeckennedy
mikeckennedy / .zshrc
Last active April 4, 2026 23:47
Security-aware Always Activate The Venv for Python
# Standard zshrc stuff like path, etc.
# ...
# Enable using the two files above:
# Functions
source venv-auto-activate.sh
# Venv security whitelist/blocklist
alias venv-security='uv run -q --no-project ~/scripts/venv-security.py'
@mikeckennedy
mikeckennedy / test_pypi_security_audit.py
Last active January 7, 2026 20:01
Add pip-audit checks to your pytest / CI tests
"""
Security audit tests using pip-audit to detect known vulnerabilities.
This test runs pip-audit against the installed packages and fails if any
vulnerabilities are detected, ensuring continuous security monitoring.
"""
import subprocess
import sys
from pathlib import Path
@mikeckennedy
mikeckennedy / cache_buster.py
Created September 10, 2025 16:34
Utility to add cache busting query parameter to all static elements on a site.
import hashlib
import os
from typing import Optional
from pyramid.request import Request
from pyramid.response import Response
def build_cache_id(
filename: str,
@mikeckennedy
mikeckennedy / .rumdl.toml
Created August 20, 2025 03:37
Michael Kennedy's rumdl configuraiton for his book "Talk Python in Production"
# Global settings
[global]
exclude = ["node_modules", "build", "dist"]
respect_gitignore = true
# Disable specific rules
disable = ["MD013", "MD033", "MD045", "MD025", "MD042", "MD041", "MD024", "MD042", "MD052", "MD036", "MD029", "MD026", "MD002", "MD014"]
# MD013 - Line length: Allows lines longer than the default limit for better readability in technical docs
# MD033 - Inline HTML: Permits HTML tags within markdown for enhanced formatting when needed
# MD045 - Images should have alternate text: Allows images without alt text (useful for decorative images)
@mikeckennedy
mikeckennedy / auto_python_venv.sh
Created August 12, 2025 00:38
Auto-activate Python virtual environment for any project with a venv directory in your shell (macOS/Linux).
# Include this in your shell *rc file (e.g. .bashrc, .zshrc, etc).
# Update the folder name to your convention.
# This uses venv as the virtual environment name, but if you use .venv, change it in the script.
# Auto-activate virtual environment for any project with a venv directory
function chpwd() {
# Function to find venv directory in current path or parent directories
local find_venv() {
local dir="$PWD"
@mikeckennedy
mikeckennedy / asset_bundler_watcher.py
Last active October 15, 2024 18:07
Example of livereload in python: Creates a file watcher that runs `python build_assets.py`, a utility based on webassets package whenever a css or js file is edited. It bundles a bunch of our CSS files into a single minified one and does the same for our JS files.
from pathlib import Path
# Creates a file watcher that runs `python build_assets.py`, a utility based on
# webassets package whenever a css or js file is edited. It bundles a bunch of
# our CSS files into a single minified one and does the same for our JS files.
def main():
# Only import this if we run it, don't let the webframework try to pull it in prod.
import livereload.server
import datetime
import sys
from typing import Optional
import colorama
import pyramid.config
from loguru import logger
from pyramid.request import Request
from pyramid.response import Response
@mikeckennedy
mikeckennedy / server-hot-reload.js
Last active August 20, 2023 18:55
Server-side hot reload checker by Michael Kennedy. When the contents of the page change in any way, the page will be reloaded.
// *************************************************************************
// server-hot-reload.js v1.0.5
//
// Server-side hot reload check by Michael Kennedy (https://mkennedy.codes).
// Released under the MIT open source license, 2023.
//
// When the contents of the page change in any way, the page will be reloaded.
//
// Usage:
//