admin
@admin ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes

Showing 211–240 of 770 public snippets

PHP
Recursive Deep Merge
Merge two associative arrays at any nesting depth — like array_merge_recursive, but later values OVERWRITE earlier ones at the leaf level instead of combining them into arrays. Perfect for config-file overrides.
37m ago 0
Bash
Wait For Docker Container to Be Healthy
docker-compose entrypoints often need to wait for a sibling service (DB, cache) to be healthy before starting work. Poll the health-check status until healthy or timeout.
37m ago 0
Bash
Find Commit That Introduced a String
`git log -S` (the "pickaxe") finds commits whose diff added or removed a given string. The fastest way to answer "when did this line first appear?"
37m ago 0
Bash
Spinner During Long Task
Show a rotating spinner next to a status message while a background command runs. Cosmetic but vastly improves the user experience of long scripts.
37m ago 0
Java
Custom Exception Hierarchy
For library/service code, define a small exception hierarchy rooted at a common base class. Callers can catch the base type or specific subclasses; you can add fields for structured context.
37m ago 0
Kotlin
Read a File — Whole, Lines, or Stream
Stdlib extensions on `java.io.File` and `java.nio.file.Path`. Use `readText()` for small files, `useLines { }` for memory-efficient line-by-line.
37m ago 0
Go
http.Client with Timeout
`http.DefaultClient` has no timeout — a hung server can hang your whole program forever. ALWAYS use a custom client with an explicit timeout for outbound requests.
37m ago 0
Go
Atomic File Write (temp + rename)
Write to a temp file in the SAME directory, then `os.Rename` to the final name. Rename is atomic on POSIX — readers never see a half-written file.
37m ago 0
Kotlin
takeIf / takeUnless — Conditional Pipelines
`takeIf { predicate }` returns `this` if the predicate holds, else null. `takeUnless` is the inverse. Combine with `?.let { ... }` for clean conditional transformations.
37m ago 0
Bash
Memory / CPU / Load Quick Check
One-liners for the three most-requested system metrics. Use in monitoring scripts or as ad-hoc sanity checks.
37m ago 0
SQL
Window Function vs N+1 Query
Don't fetch a list, then loop in code to count each parent's children. Use a window function or a single GROUP BY — turn 1,001 queries into 1.
37m ago 0
Rust
Atomic File Write (tempfile + persist)
Write to a temp file in the SAME directory, then atomically `persist` (rename). The `tempfile` crate handles cleanup if you crash before persisting.
37m ago 0
PHP
Discord Webhook Notification
Same idea as Slack but for Discord webhooks — supports rich embeds with a title, description, and color. Useful for dev/ops dashboards or bot integrations.
37m ago 0
HTML
Native <dialog> Modal
The HTML `<dialog>` element gives you a real modal — focus trap, Escape-to-close, backdrop overlay — without any JS library. Method `.showModal()` opens; `.close()` closes.
37m ago 0
Go
context.Context — Cancellation & Deadlines
`context.Context` propagates deadlines, cancellation, and request-scoped values down a call chain. EVERY blocking / long-running function should take a `ctx context.Context` as its first parameter.
37m ago 0
Kotlin
Coroutine Testing with runTest
`runTest { }` from kotlinx-coroutines-test gives you a virtual time scheduler — `delay(1000)` finishes instantly while preserving ordering. No more flaky 1-second test sleeps.
37m ago 0
TypeScript
Deep Clone with structuredClone
Forget JSON.parse(JSON.stringify(...)) — modern runtimes (Node 17+, all current browsers) ship structuredClone, which handles Dates, Maps, Sets, typed arrays, and cycles correctly.
37m ago 0
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.
37m ago 0
JavaScript
Async Sleep / Delay
Returns a Promise that resolves after a given number of milliseconds. Use with await to pause async functions without blocking the main thread. More readable than nested setTimeout callbacks and composable with other async utilities.
37m ago 0
Kotlin
Ktor Client — GET Request
Ktor is JetBrains' Kotlin-first HTTP client. Multiplatform (JVM, JS, Native). Coroutine-native — every call is a suspend function.
37m ago 0
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.
37m ago 0
Python
Stream Large CSV with DictReader
Iterate over a CSV row-by-row as a dict — never loading the whole file. Tolerant of UTF-8 BOMs (utf-8-sig). Generator wrapper makes consumers naturally use for/break.
37m ago 0
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.
37m ago 0
JavaScript
Group Array by Key
Groups an array of objects into a map keyed by the result of a callback or property name. Uses Object.groupBy when available (ES2024) and falls back to a reduce implementation. Returns an object whose keys are the group names and values are arrays of matching items.
37m ago 0
SQL
UPSERT — PostgreSQL ON CONFLICT
`INSERT ... ON CONFLICT DO UPDATE` inserts a row, or updates the existing one if a unique-constraint collision happens. The atomic alternative to "SELECT, then INSERT or UPDATE".
37m ago 0
HTML
Iframe with Sandbox + lazy loading
Embed third-party content (YouTube, Stripe, maps) safely. `sandbox` restricts what the embedded page can do. `loading="lazy"` defers offscreen iframes — huge perf win for blog posts with multiple embeds.
37m ago 0
Bash
ANSI Color Output Helpers
Wrap printf with ANSI escape codes for color and bold. Auto-disable if stdout isn't a TTY (so piping to a file doesn't pollute it with escape sequences).
37m ago 0
Rust
Generic Function with Trait Bounds
Use `T: Trait` to require a capability on a generic parameter. The `where` clause is the more readable variant when bounds get long.
37m ago 0
SQL
UPSERT — MySQL ON DUPLICATE KEY UPDATE
MySQL's flavor of upsert. Triggers when an INSERT would violate a PRIMARY KEY or UNIQUE constraint. Use `VALUES()` (or `NEW.col` in MySQL 8.0.20+) to reference the would-be-inserted row.
37m ago 0
Kotlin
reified Type Parameters
In an `inline` function, a `reified` type parameter survives erasure — you can use `T::class`, `is T`, `as T` at runtime. The killer use-case for JSON parsers ("give me a List<User>").
37m ago 0