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
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.
Rust Atomic File Write (tempfile + persist)
Write to a temp file in the SAME directory, then atomically `persist` (rename). The `tempfile` crate handles cleanup if you crash before persisting.
Go JSON API Endpoint
Decode an incoming JSON body into a typed struct, do work, encode a JSON response. The whole roundtrip is ~20 lines of standard library.
PHP Atomic File Write
Write a file in a way that other processes never see a half-written state. Write to a temp file in the same directory, then rename — rename is atomic on POSIX filesystems.
Bash Associative Array (hash map)
Bash 4+ supports key-value associative arrays. Must `declare -A` first — Bash won't infer it. Iterate keys with !arr[@].
Bash SSH to Multiple Hosts in Parallel
Run the same command on a fleet of hosts. Three patterns: serial loop (simplest), GNU parallel (fastest), pssh (purpose-built).
Rust axum with Shared State + Extractors
Use `State` to inject shared application state (DB pool, config, etc.) into every handler. `Path` and `Json` extractors deserialize URL params and request bodies for you.
JavaScript Memoize Function
Caches the result of a pure function keyed by its serialised arguments. On repeated calls with the same inputs the cached value is returned instantly, skipping expensive computation. Supports single and multi-argument functions via JSON key serialisation.
JavaScript Format Relative Time
Returns a human-readable relative time string ("3 days ago", "in 2 hours") using the Intl.RelativeTimeFormat API. Automatically selects the most appropriate unit (seconds, minutes, hours, days, weeks, months, years) based on the elapsed time. Fully localised — pass any BCP 47 locale.
JavaScript Rate Limiter (Token Bucket)
Implements a token-bucket rate limiter that allows a burst of calls up to a maximum capacity, then replenishes tokens at a steady rate. Useful for throttling outbound API requests, user-facing actions, or any operation where you need to allow occasional bursts without exceeding a sustained rate.
JavaScript Random Hex Color
Generates a random 6-digit hex colour string. Useful for seeding avatar backgrounds, chart series colours, placeholder UI elements, and testing colour-dependent components. The crypto version produces a more unpredictable result suitable for generating unique palette tokens.
PHP Hash Large File Without Loading It
Compute the SHA-256 of a multi-gigabyte file by streaming it through hash_init / hash_update_stream — no memory blow-up. Useful for backup verification or torrent-style integrity checks.
PHP Generate Crypto-Strong Password
Generate a strong random password with configurable length and character sets. Uses rejection sampling to keep the distribution uniform across the chosen alphabet (no biased % alphabetLen).
Rust Option Combinators (no unwrap!)
`Option<T>` has a rich combinator API that lets you avoid both `unwrap()` and the verbose `match`. Chain `map`, `and_then`, `unwrap_or`, `or_else` to compose fallible operations.
PHP CSRF Token Generate + Verify
Per-session CSRF token helpers using hash_equals for constant-time comparison. Token is regenerated on logout but persists across requests within a session.
PHP Validate IP Address (v4 + v6)
Distinguish IPv4 from IPv6, optionally reject private/reserved/loopback ranges. Useful for hardening server-side fetchers against SSRF.
TypeScript Promisify a Callback Function
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.
PHP Memoize a Function's Result
Cache the result of an expensive pure function by its arguments. Returns a closure with the same call signature that only invokes the inner function once per unique argument set.