TIL

Preventing accidental struct copies in Go

Prevent dangerous struct copies with noCopy sentinel and go vet's copylock checker. Protect mutexes and sync primitives from value copies.

Go 1.24's "tool" directive

Pin tool versions in Go 1.24 with the new 'tool' directive. Replace tools.go pattern with native go.mod support for project tooling.

Capturing console output in Go tests

Test functions that write to stdout/stderr in Go by capturing output with os.Pipe. Learn patterns to avoid deadlocks in concurrent tests.

Why does Go's io.Reader have such a weird signature?

Understand why io.Reader takes a byte slice parameter instead of returning one. Learn about heap allocations and buffer reuse in Go streams.

Dynamic shell variables

Learn variable indirection in Bash with ${!var} syntax. Build context-aware configs, function dispatch, and dynamic variable name resolution.

Injecting Pytest fixtures without cluttering test signatures

Clean up pytest test signatures using @pytest.mark.usefixtures to inject implicit fixtures without autouse or unused parameter warnings.

Explicit method overriding with @typing.override

Catch method override errors at type-check time with Python's @override decorator from PEP 698, preventing typos and signature mismatches.

Quicker startup with module-level __getattr__

Speed up Python module imports with __getattr__ from PEP 562 for lazy loading, deprecation warnings, and dynamic attribute access.

Docker mount revisited

Master Docker mount types: volumes, bind mounts, tmpfs, and build cache. Clear syntax comparison between -v and --mount options with docker-compose.

Discovering direnv

Automate environment variables per directory with direnv. Load .envrc files on entry, unload on exit. Integrate with Python venv and uv workflow.

Bash namerefs for dynamic variable referencing

Master Bash namerefs with declare -n to create dynamic variable references. Build generic functions for arrays and associative arrays without eval.

Shades of testing HTTP requests in Python

Test HTTP requests in Python with pytest-httpx for full mocking, respx for pattern matching, or VCR.py for recording real responses.

Taming parametrize with pytest.param

Write readable parametrized tests with pytest.param for better test names, conditional skips, custom IDs, and structured test data.

HTTP requests via /dev/tcp

Make raw HTTP requests with Bash's /dev/tcp file descriptor. Build health check scripts without curl or wget using TCP socket connections.

The *nix install command

Replace mkdir, cp, and chmod with a single install command. Copy files, create directories, and set permissions in one step with GNU coreutils.