SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
181–210
of
770
public snippets
JavaScript
String Template Tag — SQL / HTML Sanitiser
A tagged template literal that automatically escapes interpolated values, preventing SQL injection (server-side) or XSS (client-side) from untrusted input. The html tag HTML-encodes values; the sql tag parameterises values and returns a { text, values } tuple ready for a parameterised query driver.
18m ago
0
Python
Timing Decorator with Logger
Drop @timed on any function and get its wall-clock duration logged on every call. Uses functools.wraps so introspection (name, docstring, signature) still works.
18m ago
0
HTML
Tabs (ARIA tablist pattern)
The accessible tab pattern: a `role="tablist"` container, each tab as `role="tab"`, panels as `role="tabpanel"`. `aria-selected` + `aria-controls` link them and announce state.
18m ago
0
Kotlin
StateFlow — Observable State
`StateFlow<T>` is a hot Flow holding a single current value. Perfect for UI state in Compose/Android — always has a value, conflates intermediate values, multi-subscriber.
18m ago
0
TypeScript
AbortController-Wrapped Fetch
Wire an AbortController so you can cancel in-flight fetches when the user navigates away or types another search query. The optional timeout helper rejects automatically.
18m ago
0
Kotlin
Compose LaunchedEffect — Side Effects
`LaunchedEffect(key)` runs a coroutine when the key changes. Use for one-shot init, snapshot listening, data loading, or any suspend work tied to a composition.
18m ago
0
Kotlin
use { } — Auto-Close Resources
`use { }` calls `close()` on any `Closeable` (file, stream, JDBC connection, …) when the block exits — even on exception. Kotlin's try-with-resources.
18m 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.
18m 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.
18m 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.
18m ago
0
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.
18m 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.
18m ago
0
JavaScript
Queue (Async Task Queue)
A serialised async task queue that executes queued async functions one at a time, in order. Useful for sequencing operations that must not run concurrently (file writes, ordered API mutations, step-by-step wizards). add() returns a Promise that resolves/rejects when that specific task completes.
18m 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.
18m 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?"
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m 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.
18m ago
0
1
…
5
6
7
8
9
…
26