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
PHP Set Nested Value by Dot Path
Mutate a nested array by dot path, auto-creating any intermediate arrays. Companion to getPath; together they replace a lot of isset+array_key_exists ladders.
Kotlin withContext — Switching Dispatchers
`withContext(dispatcher)` suspends the calling coroutine, runs the block on the given dispatcher, returns the result. Use `Dispatchers.IO` for blocking I/O, `Default` for CPU work, `Main` for UI updates.
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.
Bash Recursive Directory Walker with Predicate
Use `find -print0` + `read -d ""` to safely iterate filenames that may contain spaces, newlines, or quotes. Standard bash for-loop over `find` output breaks on these.
Bash Array Basics (index + iterate)
Bash 4+ arrays — declare, access by index, get all elements with [@], length with #. The quoting matters: "${arr[@]}" preserves each element; ${arr[@]} word-splits.
SQL Soft Delete with Partial Index
Set a `deleted_at` timestamp instead of physically removing rows — preserves history and lets you "undelete". Pair with a partial index for fast queries that skip the soft-deleted rows.
SQL CASE WHEN — Conditional Values
Inline if/else inside a SELECT, ORDER BY, or aggregation. The Swiss-army knife for converting raw column values into labels or buckets.
Rust Builder Pattern with Method Chaining
Construct complex objects step-by-step with `self`-returning methods. Type-state can enforce required vs. optional fields at compile time — but the simple version is plenty for most cases.
PHP cURL Multipart File Upload
Upload one or more files via multipart/form-data using cURL's CURLFile abstraction. No manual boundary or body construction needed.
SQL RETURNING — Get Back What You Wrote
PostgreSQL `RETURNING *` returns the rows affected by an INSERT/UPDATE/DELETE — no separate SELECT round-trip needed. SQL Server has `OUTPUT`; MySQL added `RETURNING` in MariaDB and 8.0.31+.
Go Type Switches
When you have an `interface{}` (or any) and need to dispatch on its underlying type, use `switch v := x.(type)`. Cleaner than a chain of type-assertions.
PHP Number to Ordinal (1st, 2nd, 3rd)
Convert an integer to its English ordinal form ("1st", "2nd", "3rd", "11th", "22nd", "103rd"). Pure rule-based; no library needed.
Kotlin Sorting Collections
`sortedBy { ... }` returns a sorted copy. `sortedWith(compareBy { ... })` chains tie-breakers cleanly. Avoid `sortBy` (in-place) on read-only lists.
Rust Walk a Directory Tree
`walkdir` recursively iterates every entry under a path, skipping inaccessible directories cleanly. The standard-library alternative requires manual recursion.
PHP Get Nested Value by Dot Path
Read deeply-nested array values like Lodash _.get(). Use a "a.b.c" string instead of nested isset checks; returns a default on any missing segment.
Kotlin Coroutine Timeout with withTimeout
`withTimeout(ms) { ... }` cancels the inner coroutine if it doesn't finish in time and throws `TimeoutCancellationException`. `withTimeoutOrNull` returns null instead.
SQL Indexes — B-tree, Partial, Composite
Indexes are the difference between a 50ms query and a 50s one. Composite indexes match queries that filter / sort on the columns in order; partial indexes skip irrelevant rows for big space savings.
Kotlin minOf / maxOf / sumOf / averageOf
Numerical reducers with a selector lambda — much cleaner than `.map { ... }.max()` chains. `sumOf` is type-aware (returns Int, Long, Double, BigDecimal as appropriate).