Programming Tutorials
Standalone programming tutorials for solving one specific problem at a time. Each guide starts with the exact error message, failing behavior, or design constraint, gives you a minimal reproducible script or query, and walks through the fix with real output.
Pick a language below or filter by topic and difficulty when you need a quick, practical reference you can test locally and apply right away.
Reproduce a deadlock between two money transfers, read the message, and fix it by locking rows in the same order.
Let two workers take different jobs from one table with FOR UPDATE SKIP LOCKED, and see what happens to a job when a worker fails.
Add a NOT NULL column to a big table with a constant default, or with a nullable column, a batch backfill, NOT VALID and VALIDATE.
Walk down an employee tree, walk up to the top, count each manager's team and guard the query against a loop with CYCLE.
Take a pg_dump backup in Docker, restore it into a scratch database, compare the tables and see what a damaged backup looks like.
Reproduce Go's nil map panic, initialize maps with make or literals, and guard struct map fields safely. After this, map writes never crash on zero-value structs.
See why two Go slices overwrite each other after append and prevent it with full-slice expressions or slices.Clone.
Fix Go structs that decode to zero values in json.Unmarshal and catch misspelled JSON keys with DisallowUnknownFields.
Use net/http/httptest to send JSON requests, check status codes, and test validation paths in memory. After this, you can test HTTP handlers in milliseconds without opening a port.
Compare default go build output against CGO_ENABLED=0 with -trimpath and -ldflags="-s -w", and check shared library links with ldd.
Trigger a real data race under go test -race, read the race detector output, and fix shared counters, maps, and slice writes using atomic, sync.Mutex, and disjoint indices.
Measure nanoseconds and heap allocations with testing.B and -benchmem, compare += vs strings.Builder, pre-size slices, and reuse buffers with sync.Pool.