SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
331–360
of
770
public snippets
SQL
Gap Detection — Missing Days / Sequences
Find holes in a series — missing invoice numbers, days with no events, gaps in a sequence. Combine `LAG` (or `generate_series`) with a join to spot them.
5h ago
0
Rust
Arc<Mutex<T>> — Shared Mutable State
Share mutable data across threads: `Arc` for the shared ownership, `Mutex` for the synchronized access. Lock with `.lock().unwrap()`; the guard drops the lock on scope exit.
5h ago
0
HTML
Figure + Figcaption (Images, Code, Charts)
`<figure>` groups self-contained illustrative content with its caption. Use it for images, code blocks, charts, diagrams — anything that's referenced from the surrounding text but stands on its own.
5h ago
0
Kotlin
also — Side Effect, Return Itself
`x.also { ... }` runs a side-effect block with `x` as `it` and returns `x` unchanged. Used for logging, debugging, or asserting mid-chain without breaking it.
5h ago
0
SQL
Moving Average (Window Frame)
Add a frame clause (`ROWS BETWEEN N PRECEDING AND CURRENT ROW`) to compute moving averages, sliding sums, rolling stats — anything that needs a bounded look-back.
5h ago
0
Rust
zip / enumerate / chain
Three adapters that pair, index, and concatenate iterators. Every Rust developer reaches for them daily.
5h ago
0
Kotlin
Custom Property Delegate
Any object with `getValue` / `setValue` operator methods can serve as a delegate. Lets you encapsulate cross-cutting behavior (logging, persistence, validation).
5h ago
0
Bash
PID File Management
Write a daemon's PID to a file at start, check on subsequent runs, clean up on exit. Avoids two copies of the same daemon when the script is invoked twice.
5h ago
0
Bash
Run on Multiple Hosts via SSH (with progress)
Iterate a host list, run the same command on each, show colored OK/FAIL summary at the end. Useful for ad-hoc fleet operations without setting up Ansible.
5h ago
0
Go
goroutine + sync.WaitGroup
`go fn()` spawns a goroutine. To wait for several to finish, use `sync.WaitGroup` — call `Add` before spawning, `Done` (deferred) inside, `Wait` to block until all are done.
5h ago
0
HTML
Sortable Table (semantic markup + JS hook)
Use `<button>` inside `<th>` and `aria-sort` on the column so screen readers announce sort state. The button is the keyboard-accessible trigger; JS only handles the actual sort.
5h ago
0
PHP
CSV Writer with Proper Escaping
Write rows to a CSV file using fputcsv with sensible quoting. Also writes a UTF-8 BOM so Excel opens the file with the right encoding.
5h ago
0
Kotlin
Local Functions
Functions can be declared inside other functions. Closures over outer scope let you eliminate parameter-threading. Use sparingly — too many nested locals hurts readability.
5h ago
0
Bash
Parse --flag=value Arguments
A getopts-free arg parser handling long flags, equals-separated values, and bundled short flags. Customize as needed.
5h ago
0
TypeScript
useDebounce — Debounced State
A React hook that returns a debounced version of any value. Trigger expensive effects (search, autosave, network fetches) on this value instead of the raw input.
5h ago
0
Kotlin
Default Arguments + Named Parameters
Default values eliminate most overload sets. Named args make call sites self-documenting and let you skip middle parameters without thinking about positions.
5h ago
0
Bash
Most-Modified Files in Repo
Find the hottest files in a git history — useful for spotting hotspots that need refactoring or extra test coverage.
5h ago
0
TypeScript
useFetch — Minimal Data Fetching Hook
A tiny self-contained data-fetching hook with loading/error/data states and AbortController cleanup on unmount. Good baseline before reaching for TanStack Query.
5h ago
0
Rust
Trait with Default Methods
A trait can supply default implementations — implementors override only the bits they need. Like abstract base classes, but with structural typing and zero runtime cost.
5h ago
0
HTML
Visually Hidden Utility (.sr-only)
Hides content from sighted users but keeps it discoverable by screen readers. Use for icon-only buttons, table-row context, and form-status announcements that don't need visible text.
5h ago
0
JavaScript
JSON Fetch Wrapper
A thin wrapper around fetch that automatically serialises the request body to JSON, sets the Content-Type header, parses the response as JSON, and throws a descriptive error on non-OK responses. Covers the boilerplate needed for 95% of REST API calls in a single reusable function.
5h ago
0
Go
Multiple Return Values + Named Returns
Go functions can return multiple values — most idiomatically a `(result, error)` pair. Named returns let you document the meaning of each value AND enable naked returns in short functions.
5h ago
0
Rust
Custom Iterator Implementation
Implementing `Iterator` is just supplying a `next() -> Option<Item>`. You automatically gain `map`, `filter`, `collect`, and every other adapter for free.
5h ago
0
SQL
ARRAY_AGG and JSON_AGG (PostgreSQL)
Roll up grouped rows into a PostgreSQL array or JSON array — often a faster replacement for the application doing the same "group children under parent" join.
5h ago
0
Bash
Print a Boxed Banner
Wrap a string in a Unicode box for important headers. Auto-sizes to the longest line. Helps milestone messages stand out in long CI logs.
5h ago
0
Kotlin
repeat, also lateinit and isInitialized
`repeat(n) { i -> ... }` for N-times loops where you don't care about index naming. `lateinit var` lets you declare a non-null var without initializing it — common for DI / framework injection.
5h ago
0
Bash
Confirm Prompt (y/n)
A reusable yes/no prompt with a configurable default and a single-keystroke read. Returns 0 for yes, non-zero for no.
5h ago
0
Kotlin
observable — Listen for Property Changes
`Delegates.observable(initial) { prop, old, new -> ... }` fires a callback every time the property changes. Useful for state-tracking, simple observability without a full reactive lib.
5h ago
0
Bash
Run Command with Timeout
`timeout` (GNU coreutils) kills a command after N seconds. Returns exit code 124 on timeout — let the caller distinguish "timed out" from "failed for other reasons."
5h ago
0
Python
pathlib Quick Reference
Forget os.path.* — pathlib.Path is the modern, OS-aware way to work with paths. Operator overloading for joins, attribute access for components, methods for reads/writes/iterations.
5h ago
0
1
…
10
11
12
13
14
…
26