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
TypeScript Sum / Mean / Median (numeric arrays)
The descriptive-stat trio for number[]. Median sorts a copy so the input is left alone. Empty input returns 0 / 0 / 0 rather than NaN — opinionated, but predictable.
TypeScript Shuffle (Fisher-Yates)
Uniformly shuffle an array in place using the modern Fisher-Yates algorithm. Returns the same array for chaining. Use crypto.getRandomValues for cryptographic uses.
TypeScript range — Lazy Number Iterator
A generator-based numeric range: `[start, end)` with an optional step. Lazy so it doesn't allocate a huge array up front; consume with for…of or Array.from.
TypeScript Chunk Array Into Fixed-Size Pieces
Split an array into chunks of `size` items. Common building block for batch APIs — "send 50 rows per request" — and for paginated grids.
TypeScript groupBy (with key callback)
Group a list into a record keyed by whatever the callback returns. Like Lodash _.groupBy or the new Object.groupBy in modern runtimes. Generic enough to handle string, number, or symbol keys.
PHP Chunk Array With Preserved Keys
Slice an array into chunks of a given size while preserving the original keys in each chunk. Useful for paginating ordered datasets without losing the row IDs.
PHP PDO Connection with Sensible Defaults
Open a PDO connection with all the options you almost always want: real prepared statements, exceptions on error, associative-array fetch mode, UTF-8 charset.
Bash Watch a File for Changes (no inotify dep)
inotifywait is great when available, but on systems without inotify-tools you can poll mtime. Cheap enough to use in dev/CI workflows.
TypeScript Template Literal Types
Build string types out of other string types. Lets you express patterns like "every CSS event handler starts with on" in the type system itself, with autocomplete to match.
Kotlin init Block + Constructor Order
`init { }` blocks run during construction, in declaration order, interleaved with property initializers. Use to validate the primary constructor or set up derived state.
SQL Correlated Subquery
A subquery that references the outer query's row. Slower than a JOIN for big result sets but sometimes the most readable expression.
JavaScript Scroll to Element Smoothly
Scrolls the page to a target element with an optional pixel offset (useful when a fixed header is present). Uses the native scrollIntoView with smooth behaviour when supported, and falls back to a manual scrollTo with a configurable offset. Pass a CSS selector string or an Element reference.
JavaScript Create Element Helper
A concise helper for creating DOM elements with attributes, properties, styles, event listeners, and children in one call — similar to hyperscript or JSX without a build step. Eliminates repetitive createElement / setAttribute / appendChild chains and keeps DOM construction code readable.
TypeScript Exhaustive `assertNever`
Compile-time guarantee that every variant of a union is handled. When you add a new variant later, every switch missing that case becomes a type error. The runtime version is a safety net.
Go Build Tags + Conditional Compilation
`//go:build` constraints control which files compile under which conditions — different code for Linux vs Windows, dev vs prod, with/without a feature. Standard library uses this heavily.
JavaScript Long Polling Helper
Implements a long-polling loop that repeatedly calls a fetch endpoint and invokes a callback with the result. Backs off exponentially on errors and stops cleanly when cancelled via the returned stop function. A simple alternative to WebSockets for low-frequency server-push events without SSE support.
TypeScript Discriminated Unions with Exhaustive Switch
Discriminated (tagged) unions give you compiler-checked state machines. Pair with `assertNever` to force every new variant to be handled at every switch site — refactors stop being scary.
Java Switch Expressions (Java 14+)
`switch` is now also an expression — it returns a value. Use `->` arrows for fall-through-free arms; `yield` inside `{ }` blocks for multi-statement arms. No more accidental forgotten `break`.