Skip to content

Instantly share code, notes, and snippets.

View stephanGarland's full-sized avatar

Stephan Garland stephanGarland

View GitHub Profile
@stephanGarland
stephanGarland / update_pep484_types.py
Created August 11, 2026 20:56
Updates PEP484 to modern types
import argparse
import ast
class PEP484ToModernTransformer(ast.NodeTransformer):
GENERIC_MAP = {
"Dict": "dict",
"FrozenSet": "frozenset",
"List": "list",
"Set": "set",
@stephanGarland
stephanGarland / pyrepl.py
Created August 11, 2026 20:20
PyREPL - bad name, useful tool - allows you to easily import arbitrary files from within a package to run quick tests, automatically grabbing dependencies as necessary
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Launch a Python REPL with in-tree modules already imported.
Missing third-party dependencies are resolved automatically: the target's import
graph is walked, anything unimportable is installed into a per-project cache venv
that is appended to sys.path, and an import/install loop mops up whatever the
@stephanGarland
stephanGarland / home_assistant_adaptive_lighting.md
Last active April 5, 2026 21:35
Home Assistant Adaptive Lighting Possible Fixes
@stephanGarland
stephanGarland / estimate_row_size_innodb.py
Created December 16, 2025 18:21
Estimate row / index / table size for InnoDB tables
import argparse
import doctest
import re
import signal
import sys
from enum import Enum
from typing import NoReturn
# lambda x: x <= k[0][0] ? k[0][1] : x <= k[1][0] ?...
_SIZE_MAP: dict[str, list[tuple[float | int, int]]] = {
import gzip
import hashlib
import sqlite3
import urllib.request
from dataclasses import asdict, dataclass
@dataclass
class Queries:
insert_program: str = (
@stephanGarland
stephanGarland / collation_postgres_perf.md
Created May 31, 2025 15:26
Demonstrating performance differences of collations in Postgres

Setup

Hardware

M4 Pro MBP w/ 48 GiB RAM

Software

Postgres 17, shared_buffers=2GB, effective_cache_size=8GB

@stephanGarland
stephanGarland / macos_local_mysql_multiple_versions.md
Last active August 21, 2026 15:29
Run local MySQL 5.7 and 8 simultaneously on MacOS via Homebrew

Prerequisites

Mac

This has been tested only on ARM (Apple Silicon) Macs. YMMV on x86. I don't see why it wouldn't work, but you may need to change some directory paths.

MySQL

You'll need to have MySQL 5.7 and 8 installed. The former is somewhat tricky, because the

@stephanGarland
stephanGarland / macos_modify_mysql_configs.py
Last active August 21, 2026 15:30
Modify MySQL config files on MacOS as installed by Homebrew to alllow simultaneous 5.7 and 8.0 installations
# DEPRECATED: no longer required with tap wrapper; retained for posterity
import configparser
import plistlib
import shutil
import subprocess
from enum import Enum
from pathlib import Path
from string import Template
from typing import NamedTuple, Optional
@stephanGarland
stephanGarland / mysql_57_varchar_enum_json.md
Created February 7, 2025 17:37
Comparing VARCHAR, ENUM, and JSON indexed performance in MySQL 5.7

Environment

System

  • Macbook Pro M3
  • RAM: 36 GiB
  • SSD: 500 GB

MySQL

@stephanGarland
stephanGarland / sqlalchemy_enum.py
Created December 20, 2024 18:39
Demonstration of lookup tables with SQLAlchemy that automatically update with new entries
import itertools
import uuid
from functools import lru_cache
from typing import Dict, List, Optional, Union
from sqlalchemy import (Column, DateTime, ForeignKey, Integer, String,
create_engine)
from sqlalchemy.dialects import mysql
from sqlalchemy.orm import (Session, declarative_base, relationship,
sessionmaker)