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
JavaScript Chunk Array
Splits an array into smaller arrays (chunks) of a specified size. The last chunk may be smaller if the array length is not evenly divisible. Useful for batch processing, pagination, rendering large lists in chunks, and rate-limited API calls.
Kotlin Result Type — Safe Error-Returning APIs
`Result<T>` wraps "success or thrown exception" without forcing the caller into try/catch. `runCatching { ... }` is the standard producer.
PHP JSON Structured Logger
Append a single JSON object per line to a log file. Easy to grep and to ship into Datadog / Loki / CloudWatch later without re-parsing.
PHP Convert Camel Case ↔ Snake Case
Convert between camelCase and snake_case identifiers. Handy when mapping JS API responses (camelCase) into PHP database column names (snake_case) and vice versa.
PHP Validate Email (RFC-aware)
Use PHP's built-in FILTER_VALIDATE_EMAIL with the FILTER_FLAG_EMAIL_UNICODE flag for IDN domains, plus a length sanity check. Trust this over hand-rolled regex.
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).
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.
PHP Recursively Delete Directory
Remove a directory and everything under it. Defensive against symlinks (unlinks the symlink rather than recursing into it). Returns the count of items removed.
PHP Parse Link Header for Pagination
Parse the standard HTTP Link header (RFC 5988) into a relation → URL map. Lets you follow rel="next" pagination in APIs like GitHub without manually building URLs.
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.
PHP RGB ↔ Hex Conversion
Two-way conversion between #RRGGBB hex strings and [R, G, B] arrays. Handy when working with theme colors that come from both sources (CSS strings vs. RGB sliders).
PHP URL-Safe Base64 Encode / Decode
Standard base64 uses + and / which break in URLs. Swap them for - and _, drop the = padding, and you get a string you can put in path segments and query parameters safely.
Kotlin Infix Functions
A single-arg method/extension can be called without dot or parens when marked `infix`. Lets you write DSL-style code like `5 shouldBe 5` or `key to value`.
PHP Measure Code Block Execution Time
Time a closure with microsecond precision and return both its result and the elapsed milliseconds. Great for quick perf experiments without pulling in a profiler.
PHP Atomic File Write
Write a file in a way that other processes never see a half-written state. Write to a temp file in the same directory, then rename — rename is atomic on POSIX filesystems.
PHP Send Plain Email via mail()
A thin wrapper around PHP's mail() with proper headers (From, Reply-To, Content-Type with UTF-8). For anything serious reach for PHPMailer or Symfony Mailer — this is fine for transactional one-offs.
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.
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).