Prevent two copies of a cron job from running simultaneously. flock takes an FD to a lock file; if the lock is held, the second invocation exits immediately.
Build a password using the `secrets` module (CSPRNG) with rejection sampling for unbiased distribution. Use this — NOT random.choice, which is seeded predictably.
Compute the great-circle distance between two latitude/longitude points using the haversine formula. Returns kilometers; multiply by 0.621 for miles. Useful for "stores near me" features.
Run a closure inside a transaction. Commits on success, rolls back on any exception, then re-throws so the caller can react. Avoids the bug-prone copy-paste of begin/commit/rollBack.
A complete login form with the autocomplete attributes that browsers + password managers depend on. Missing these causes 1Password, Bitwarden, and Chrome to mis-detect the form.
`LIMIT N OFFSET M` is universal — but degrades on deep pages (the DB still has to scan past M rows). Keyset (cursor) pagination is much faster for huge tables.
`LIKE` uses `%` (any string) and `_` (single char). PostgreSQL `ILIKE` is case-insensitive. For real regex, reach for `SIMILAR TO` (POSIX) or `~` (PostgreSQL).
Rust iterators are lazy and zero-cost. Chain transformations and finally collect into a concrete container. The compiler unrolls the whole pipeline into a tight loop.
Bash's ${var:offset:length} and ${var//pattern/replacement} let you do most string operations without ever spawning sed. Faster, and the syntax is portable across modern shells.
Convert a Node-style `(err, result)` callback API into a Promise-returning function. Type-safe via generics — the inferred Promise resolves to the original callback's result type.
Generate a JWT manually using only base64-url and hash_hmac — no library required. Demonstrates header/payload/signature concatenation and the exp claim.