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
Python
group_by — Group Items by a Key
A dict-returning groupby that doesn't require sorted input. Like itertools.groupby but materializes the groups so consumers can iterate them multiple times.
4h 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.
4h ago
0
Bash
Deduplicate Array (preserve order)
Bash's associative arrays let you dedupe in a single pass while keeping the original order — `sort -u` would shuffle.
4h ago
0
Bash
Epoch ↔ Human Date Conversion
`date +%s` gives now-as-epoch; `date -d @N` converts an epoch number back to a human date. Often what API responses expect / return.
4h ago
0
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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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).
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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`.
4h ago
0
1
…
18
19
20
21
22
…
26