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
Kotlin Exposed — Kotlin-First ORM
JetBrains' Exposed combines a SQL DSL with a lightweight ORM. Either style is fully type-safe; both compile to plain SQL.
Kotlin Compose Modifier Chain
`Modifier` is how you customize composables — padding, click handlers, background, size, alignment. Order matters: each modifier wraps the previous one.
Kotlin inline Functions — Zero-Cost Lambdas
`inline fun` copies the body (including lambda bodies) into the call site at compile time. Result: no `Function` object allocated for the lambda; `return` from inside the lambda exits the enclosing function.
Rust impl Trait — Static Dispatch Returns
When you want to return a complex iterator chain or closure, you don't need to spell out the type. `impl Trait` lets the compiler infer the concrete type while exposing only the API contract.
Bash Days Between Two Dates
Convert both dates to epoch seconds, subtract, divide. Works for hours/minutes too with the obvious divisor.
Bash Split String into Array on Delimiter
Use IFS + read or readarray to split safely. Don't use word-splitting tricks — they break on edge cases (empty fields, spaces in values).
Python Bulk Insert with executemany
Insert many rows in one round-trip using executemany. Orders-of-magnitude faster than a loop of single inserts — and the driver handles batching/parametrization for you.
Python Sliding Window Iterator
Iterate over an iterable with a rolling window of N items. itertools.batched (Python 3.12+) gives you NON-overlapping chunks; this helper gives overlapping ones, common for moving averages or n-gram analysis.
TypeScript Format Relative Time ("3 days ago")
Use the built-in Intl.RelativeTimeFormat to render "3 days ago" / "in 5 hours". Localized for free — pass any BCP 47 locale. No date library needed.
TypeScript partition — Split by Predicate
Split an array into [pass, fail] in a single pass. Type guard overload lets the truthy bucket get a narrowed type when you pass a `x is T` predicate.
TypeScript Result / Either Type
Encode "this might fail" in the type signature instead of throwing. Force the caller to handle both branches at compile time. Better than try/catch for foreseeable failures.
PHP UPSERT (INSERT ... ON DUPLICATE KEY UPDATE)
A MySQL upsert helper: insert a row, or if a unique key collides, update the same row with the new values. Returns whether the row was inserted (true) or updated (false).
PHP Validate Uploaded File
A defense-in-depth check for $_FILES uploads: confirms the upload completed, the size is within bounds, the MIME type matches an allow-list (by libmagic, not by extension), and the file landed where PHP expected.
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.
HTML Navigation with aria-current
Use `<nav>` for primary navigation. Mark the currently-active link with `aria-current="page"` — screen readers will announce it, and you get a free CSS hook with `[aria-current]`.
Java Builder Pattern
For objects with many optional parameters, a Builder beats a constructor with 12 args (or a half-initialized object you have to call setters on). Method chaining + a `build()` step that validates.
Bash Count Occurrences of a Pattern
Several ways to count matches: lines containing X, total matches across a file, matches grouped by capture, etc.
Bash Heredoc with Variable Interpolation Control
Heredocs are the cleanest way to embed multi-line text. Unquote the delimiter to allow variable expansion; QUOTE it to keep the body literal (no $foo expansion).