Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Bash cURL GET with Timeout + Retry
A sensible default cURL invocation: short connect timeout, total timeout, retry on transient failures with backoff, fail-on-error.
Python functools.cache Memoization
Wrap any pure function with @cache (Python 3.9+) and get an unbounded memoization layer for free. Use @lru_cache(maxsize=N) when you need a bounded cache.
HTML Progress and Meter Elements
`<progress>` shows how much of a task is done (downloads, multi-step forms). `<meter>` shows a value within a known range (disk usage, password strength). Both render as native UI in every browser.
TypeScript uniqueBy — Dedupe by Callback
Deduplicate an array using a derived key (object id, lowercased email, etc.). First occurrence wins. Backed by a Map for O(n) performance.
Go os.Getenv with Defaults
`os.Getenv` returns "" when unset — easy to miss. Wrap it with a typed helper that supplies defaults and parses numerics. Saves boilerplate at every config-read site.
Python ProcessPoolExecutor for CPU-Bound Work
Use processes (not threads) for CPU-bound work to sidestep the GIL. Functions must be picklable — define them at module level, not as locals or lambdas.
Go Struct Embedding (Composition over Inheritance)
Go has no inheritance. Embed a type to "promote" its fields and methods as if they were on the outer type. Same effect as inheritance for most purposes, but explicit.
PHP Safe Path Join
Concatenate path segments and produce a normalized canonical path that resists "../" escape attempts. Throws if the result would land outside the given base directory.
Python textwrap dedent + fill (Multi-line Strings)
`textwrap.dedent` strips common leading whitespace from a triple-quoted string — finally, you can indent multiline strings inside functions without breaking the formatting. `fill` wraps to a max width.
PHP TOTP Code Generate + Verify
Generate and verify a 6-digit time-based one-time password (RFC 6238) compatible with Google Authenticator / Authy. Uses a base32-encoded secret and 30-second time steps.
PHP Generate Secure API Key
Mint an API key with a recognizable prefix ("sk_live_…") and 32 bytes of crypto-random entropy encoded as URL-safe base64. Stripe-style readable IDs.
Bash Generate UUID
Several portable ways to mint a v4 UUID from the shell — useful for request IDs, idempotency keys, temporary filenames.
Bash Atomic File Write (write then rename)
Write to a temp file in the SAME directory, then `mv` to the final name. mv on the same filesystem is atomic — readers never see a half-written file.
PHP RGB ↔ Hex Conversion
Two-way conversion between #RRGGBB hex strings and [R, G, B] arrays. Handy when working with theme colors that come from both sources (CSS strings vs. RGB sliders).
Bash Read File Line-By-Line (the safe way)
The classic `for line in $(cat file)` is wrong — it word-splits and globbing fires on filenames. Use `while IFS= read -r line` with input redirection.
Rust String vs &str — The Cheat Sheet
`String` is an owned, growable heap allocation; `&str` is a borrowed view into a UTF-8 buffer. Function params should usually take `&str`; return types use `String` when ownership is needed.
Python Safe JSON Read/Write
Idiomatic helpers for reading + writing JSON to disk, with atomic writes and pretty-printed output. Catches the common "edit and save → corrupt file on crash" failure mode.
Go CSV Read/Write with encoding/csv
`encoding/csv` parses RFC 4180 CSVs. Read row-by-row with `Read()` or all at once with `ReadAll()`. Same for writing — flush with `Writer.Flush()` before closing.