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 Bulk INSERT in a Single Statement
Insert a list of rows in one round trip by building a multi-VALUES statement with placeholders. Orders-of-magnitude faster than looping single INSERTs.
PHP PDO Transaction Wrapper
Run a closure inside a transaction. Commits on success, rolls back on any exception, then re-throws so the caller can react. Avoids the bug-prone copy-paste of begin/commit/rollBack.
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).
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.
Python requests Session with Retry + Timeouts
A pre-configured requests.Session that auto-retries 5xx + connect errors with exponential backoff, applies a default timeout, and uses connection pooling. Use this everywhere instead of bare requests.get().
Python Run sync Iterables as async Stream
Wrap a blocking iterator so each yield happens in a worker thread — useful when integrating sync libraries (DB cursors, file iterators) into an async pipeline without rewriting them.
PHP Auto-Reconnect on "MySQL has gone away"
Long-running daemons sometimes lose their MySQL connection mid-run. Wrap your DB calls to retry once after a transient connection-lost error.
Java JUnit 5 — Parameterized Tests
`@ParameterizedTest` runs the same test with multiple inputs. Use `@CsvSource`, `@MethodSource`, or `@EnumSource` for data. Eliminates copy-paste in test classes.
Java Path Operations — Resolve, Relativize, Normalize
`Path` (NIO) replaces `File` for new code. Operator-like methods compose paths cleanly across OSes — and the underlying file isn't touched until you do I/O.
Java Collectors.groupingBy — Group by Key
Like SQL GROUP BY for streams. Produces a `Map<K, List<V>>` (or any downstream collector you specify). Indispensable for analytics-style aggregations.
Bash Pretty-Print JSON from cURL
Pipe API responses through jq for syntax-colored, indented output. Also great for extracting specific fields without writing a parser.
Bash Background Jobs + wait
Run several commands in parallel with `&`, then wait for all of them with `wait`. Collect exit codes via $! and check after wait returns.
Python Word-Safe Truncate
Cap a string at `max_len` chars without splitting a word; append an ellipsis when truncated. Backs off to the last space if cutting mid-word would happen.
TypeScript Format Duration in ms
Render a number of milliseconds as a human-friendly duration: "1h 23m 45s". Skips leading-zero units automatically so short durations are concise.
PHP Verify a JWT (HS256)
Pair to jwtSign: verify the signature, check the exp claim, and return the decoded payload — or null on any failure. Uses hash_equals for constant-time signature comparison.
PHP Safe JSON Decode (no exceptions)
Wrap json_decode so invalid input gives you a clear false rather than a silent null. PHP 7.3+ JSON_THROW_ON_ERROR makes this cleaner — but the wrapper preserves a simple bool API.
Kotlin java.time — When You Need JVM Interop
On the JVM, `java.time` is fine — and often necessary for interop with Java APIs. Kotlin's extension methods make it ergonomic enough that you might never reach for kotlinx-datetime.
Kotlin kotlinx.serialization — JSON Basics
Compile-time code generation for JSON serialization. Annotate `@Serializable` on a data class; `Json.encodeToString` and `Json.decodeFromString` are typed.