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
Python Generate Strong Random Password
Build a password using the `secrets` module (CSPRNG) with rejection sampling for unbiased distribution. Use this — NOT random.choice, which is seeded predictably.
PHP Paginated Query Helper
Run a SELECT with LIMIT/OFFSET and also return the total row count, so you can render "Page 3 of 47" UIs. Single function, two round trips.
Java Stream.generate / iterate — Infinite Streams
Build streams from a seed + a function. `generate(supplier)` calls the supplier each time; `iterate(seed, next)` applies a unary op. Always pair with `limit` to bound them.
Python Async Context Manager (aiohttp pattern)
Define an async resource using `@asynccontextmanager` from contextlib. Cleaner than writing a class with __aenter__/__aexit__ for one-off wrappers.
Kotlin Operator Overloading
Specially-named methods or extensions get operator syntax: `plus → +`, `minus → -`, `times → *`, `get → []`, `invoke → ()`, `contains → in`. Use sparingly for types that have natural arithmetic semantics.
PHP cURL POST JSON
Post a JSON body with the right Content-Type header and parse the response. Returns the decoded body or throws on a non-2xx response.
PHP Business Days Between Two Dates
Count weekdays (Mon-Fri) between two dates, excluding an optional list of holidays. Direction-aware (works even if $end < $start).
Rust Iterator Chain — map / filter / collect
Rust iterators are lazy and zero-cost. Chain transformations and finally collect into a concrete container. The compiler unrolls the whole pipeline into a tight loop.
PHP Build & Sign a JWT (HS256)
Generate a JWT manually using only base64-url and hash_hmac — no library required. Demonstrates header/payload/signature concatenation and the exp claim.
SQL Pattern Matching — LIKE / ILIKE / SIMILAR
`LIKE` uses `%` (any string) and `_` (single char). PostgreSQL `ILIKE` is case-insensitive. For real regex, reach for `SIMILAR TO` (POSIX) or `~` (PostgreSQL).
SQL Pagination with LIMIT / OFFSET
`LIMIT N OFFSET M` is universal — but degrades on deep pages (the DB still has to scan past M rows). Keyset (cursor) pagination is much faster for huge tables.
Go Generic Function with Type Parameters
Go 1.18+ generics. `[T any]` is unconstrained; `[T comparable]` allows == and !=; custom constraints work too. The compiler infers T from arguments.
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.
Bash Substring + Find/Replace (parameter expansion)
Bash's ${var:offset:length} and ${var//pattern/replacement} let you do most string operations without ever spawning sed. Faster, and the syntax is portable across modern shells.
HTML Login Form (with autocomplete hints)
A complete login form with the autocomplete attributes that browsers + password managers depend on. Missing these causes 1Password, Bitwarden, and Chrome to mis-detect the form.
Kotlin Path Operations with java.nio.file
Modern Kotlin code uses `java.nio.file.Path` over the legacy `File`. Operator overloads + Kotlin extensions make it ergonomic.
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.
HTML Search Form with Accessible Label
A search input usually has a visible-only icon — but screen readers need a real label. Pair a visually-hidden `<label>` with the icon, OR use `aria-label` on the input.