SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
571–600
of
770
public snippets
SQL
Running Totals (SUM OVER)
Window aggregates with an implicit "rows up to here" frame give you running totals, cumulative counts, and ratchet-up metrics. No self-join needed.
2h ago
0
HTML
Print Stylesheet Setup
Tune the print layout: hide nav/footer, force black-on-white text, expand absolute URLs, hide images you don't want printed. Save your users from wasting paper on the page chrome.
2h ago
0
Kotlin
JDBC with use { } — Auto-Close Connections
Plain JDBC is fine for simple cases. Wrap connections / statements / result sets in `use { }` for guaranteed cleanup even on exceptions.
2h ago
0
Kotlin
Property Delegation by Map
Delegate a property to a `Map<String, V>` — reading the property fetches by name; writing stores by name. Quick way to back a class with a config map.
2h 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.
2h ago
0
TypeScript
safeJsonParse — Result-Typed
Parse JSON without ever throwing. Returns a Result-like discriminated union so callers must handle both success and failure paths at compile time.
2h ago
0
Python
TypedDict for JSON API Shapes
When you parse JSON, you want types — but creating a class for every payload is overkill. TypedDict gives you the static-checking benefits without the runtime overhead, and `total=False` marks every field optional.
2h ago
0
Bash
Check If Port Is Open
Several ways to probe a remote port: nc (most portable), bash's /dev/tcp pseudo-device (zero deps), or curl. Pick by what's available.
2h 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.
2h ago
0
Bash
Prune Dangling Docker Images
Reclaim disk space from Docker. `prune` operates on stopped containers, dangling images, build cache, and unused networks. Run periodically on CI runners.
2h ago
0
Go
time.Format — The Reference Time
Go's time formatting uses a reference date instead of strftime tokens: `Mon Jan 2 15:04:05 MST 2006` (which is 01/02 03:04:05PM '06 -0700, or 1/2/3/4/5/6/7 — mnemonic). Strange at first, instantly memorable.
2h ago
0
Java
Collectors.toMap with Merge Function
`toMap` builds a `Map<K, V>` from a stream. The 3-arg form takes a merge function for handling duplicate keys — without it, duplicates throw IllegalStateException.
2h ago
0
Java
Optional — Stop Returning Null
`Optional<T>` makes "may be absent" part of the type signature so callers can't forget the null check. `map`, `orElse`, `ifPresent` chain naturally — no `if (x != null)` boilerplate.
2h ago
0
HTML
HTML5 Document Boilerplate
Sensible HTML5 starting template: UTF-8 charset, responsive viewport, language attribute, semantic landmarks. Drop this in every new project before adding anything else.
2h ago
0
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.
2h ago
0
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).
2h ago
0
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.
2h ago
0
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.
2h ago
0
PHP
Paginated Query Helper
Run a SELECT with LIMIT/OFFSET and also return the total row count, so you can render "Page 3 of 47" UIs. Single function, two round trips.
2h ago
0
Python
Async Context Manager (aiohttp pattern)
Define an async resource using `@asynccontextmanager` from contextlib. Cleaner than writing a class with __aenter__/__aexit__ for one-off wrappers.
2h ago
0
Python
Generate Strong Random Password
Build a password using the `secrets` module (CSPRNG) with rejection sampling for unbiased distribution. Use this — NOT random.choice, which is seeded predictably.
2h ago
0
Bash
Tail Logs from Multiple Containers
`docker compose logs -f` already does this — but the one-liner with --tail and filters is the more useful day-to-day workflow when you only care about recent activity from a subset of services.
2h ago
0
Rust
Iterator Chain — map / filter / collect
Rust iterators are lazy and zero-cost. Chain transformations and finally collect into a concrete container. The compiler unrolls the whole pipeline into a tight loop.
2h ago
0
Java
Stream.generate / iterate — Infinite Streams
Build streams from a seed + a function. `generate(supplier)` calls the supplier each time; `iterate(seed, next)` applies a unary op. Always pair with `limit` to bound them.
2h 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.
2h ago
0
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`.
2h ago
0
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.
2h ago
0
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.
2h ago
0
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().
2h ago
0
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.
2h ago
0
1
…
18
19
20
21
22
…
26