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

Showing 271–300 of 770 public snippets

Rust
Clone vs Copy — When to Use Each
Stack-allocated primitives implement `Copy` (auto-duplicated). Heap-owning types like `String` and `Vec` only implement `Clone` (you must explicitly call `.clone()` to opt into the deep copy cost).
4h ago 0
SQL
STRING_AGG / GROUP_CONCAT
Concatenate values across a group into a single delimited string. PostgreSQL/MSSQL use `STRING_AGG`; MySQL uses `GROUP_CONCAT`; SQLite has both.
4h ago 0
SQL
Views and Materialized Views
A view is a named query — no data stored. A materialized view caches the result; refresh it on demand. Great for expensive joins or aggregations that don't need to be real-time.
4h 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.
4h ago 0
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.
4h ago 0
Rust
zip / enumerate / chain
Three adapters that pair, index, and concatenate iterators. Every Rust developer reaches for them daily.
4h 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.
4h ago 0
Java
Generic Class with Type Parameter
Stamp out type-safe containers and helpers — same class body, multiple element types. The `<T>` declaration is what makes it generic.
4h 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.
4h 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.
4h 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.
4h 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).
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h 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.
4h ago 0
Java
Files.readString / readAllLines
`java.nio.file.Files` shipped these convenience helpers in Java 8/11. Way cleaner than the legacy `FileReader` + `BufferedReader` ceremony for small/medium files.
4h 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.
4h ago 0