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 Sum a Column with awk
Awk's default field splitter is whitespace; pass a single character with -F. Perfect for summing the Nth column of a log file or CSV.
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.
TypeScript Environment Variable Validator
Validate process.env at boot-time and exit fast if anything's missing. The returned object is typed so the rest of the code reads `env.DATABASE_URL` instead of `process.env.DATABASE_URL!`.
PHP Partition Array Into Two Buckets
Split an array into [matches, non-matches] using a predicate callback. Single pass, preserves order, returns two lists.
Go time.Ticker — Periodic Tasks
`time.NewTicker(d)` fires on a channel every `d` interval. Combine with select + a done channel for a clean way to run periodic work that can be cancelled.
TypeScript invariant() — Always-On Assertion
Throw if a condition is false, with TypeScript narrowing the type afterwards. Replaces ad-hoc `if (!x) throw` ladders and gives you type-safe guards in one line.
Go Custom Generic Constraints
Type constraints are interfaces with type sets. Use them to express "any numeric" or "any ordered" without resorting to `any`.
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.
PHP Slack Incoming-Webhook Notification
Fire a quick notification to a Slack channel via an incoming webhook URL. Includes basic markdown-style mentions and an attachment color for severity.
Rust Result Combinators + the ? Operator
`Result<T, E>` chains like `Option`. The `?` operator unwraps `Ok` or early-returns the `Err`, converting via `From` so callers can use one error type for many sources.
Java Stream Basics — filter / map / collect
The fluent pipeline for transforming collections. `filter` keeps matching elements, `map` transforms each one, `collect(toList())` materializes the result.
HTML Skip-to-Main-Content Link
Keyboard users (and screen-reader users) tab through every nav link before reaching content. A skip-link as the first focusable element jumps straight to <main>. Required for WCAG 2.1 AA.
Python chunked — Split Iterable into Fixed-Size Pieces
Lazy chunker that works on any iterable, not just lists. Common building block for batch APIs — "send 50 rows per request" — without loading the source into memory.
Kotlin Star Projections (List<*>, etc.)
`List<*>` means "list of something I don't need to know exactly" — read-only with Any? as element type. Useful when you genuinely don't care about the parameter.
TypeScript URL Builder with Type-Safe Query
Build URLs with a clean query-param API. Skips null/undefined automatically, encodes everything, and accepts arrays for repeated keys. Avoids manual string concatenation.
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).
Bash Unique While Preserving Order
`sort -u` re-orders. `awk '!seen[$0]++'` is the classic order-preserving dedupe — and it's a single line.
Kotlin fold and scan
`fold` accumulates from a seed across all items. `runningFold` / `scan` yields every intermediate accumulator value — running totals, cumulative metrics.