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

Showing 181–210 of 770 public snippets

SQL
Pivot Without PIVOT (Conditional Aggregation)
Most databases don't have a real `PIVOT` keyword (SQL Server does). The portable answer is conditional aggregation — `SUM(CASE WHEN ...) AS col` for each pivoted value.
1h ago 0
Rust
Async/Await with tokio
`async fn` returns a future; `.await` drives it. tokio is the de-facto runtime. The `#[tokio::main]` attribute turns `main` into the runtime entry point.
1h ago 0
HTML
Video Element with Captions
`<video>` with multiple `<source>` formats (MP4 + WebM), `controls`, `poster`, and a captions track via `<track kind="captions">`. All shipped with the browser — no JS player needed.
1h ago 0
TypeScript
URL Builder with Type-Safe Query
Build URLs with a clean query-param API. Skips null/undefined automatically, encodes everything, and accepts arrays for repeated keys. Avoids manual string concatenation.
1h ago 0
Kotlin
kotlin.test — Basic Tests
`kotlin.test` is the multiplatform test stdlib. `@Test` marks a test; `assertEquals`, `assertTrue`, `assertFailsWith` are the workhorses.
1h ago 0
Python
asyncio.to_thread — Run Blocking Code
Wrap a blocking function so it doesn't freeze the event loop. asyncio.to_thread (3.9+) schedules the call onto the default executor and awaits the result.
1h ago 0
Kotlin
Star Projections (List<*>, etc.)
`List<*>` means "list of something I don't need to know exactly" — read-only with Any? as element type. Useful when you genuinely don't care about the parameter.
1h ago 0
Rust
Serde — Derive Serialize / Deserialize
`#[derive(Serialize, Deserialize)]` is the one-liner that bridges Rust structs and JSON / YAML / TOML / etc. via serde's data-format crates.
1h ago 0
PHP
Average / Median / Mode
Three classic descriptive statistics over a numeric array. Built without any external math library — just sort + count.
1h ago 0
SQL
FIRST_VALUE / LAST_VALUE
Return the first or last value within a window. Useful for "compare each row to the partition's first/last value" — for example, "how much have we grown since the user's first order?"
1h ago 0
Java
AtomicInteger / LongAdder
Lock-free atomics for shared counters. `AtomicInteger` for low contention; `LongAdder` for high contention (shards internally — much faster under heavy parallel load).
1h ago 0
Kotlin
Ktor Client — POST JSON with Serialization
Combine Ktor + kotlinx.serialization: register the JSON plugin, declare `@Serializable` data classes, the client (de)serializes automatically.
1h ago 0
Rust
reqwest GET + JSON Deserialize
`reqwest` is the standard HTTP client. Combined with serde, you can fetch and parse a JSON API response into a typed struct in three lines.
1h ago 0
Python
pairwise — Rolling Pair Iterator
`pairwise([a, b, c, d])` yields `(a, b), (b, c), (c, d)` — built into itertools since 3.10. Perfect for "diff consecutive elements" patterns (deltas, rate-of-change, validation between rows).
1h ago 0
SQL
Sessionization — Group Events into Sessions
Stitch a stream of events into "sessions" where events more than N minutes apart start a new session. Uses LAG + a SUM-OVER trick to assign session IDs.
1h ago 0
PHP
Validate Hex Color
Accept #RGB, #RGBA, #RRGGBB, or #RRGGBBAA hex colors (with or without the leading #). Returns the normalized 6/8-digit lowercase form.
1h ago 0
PHP
Slack Incoming-Webhook Notification
Fire a quick notification to a Slack channel via an incoming webhook URL. Includes basic markdown-style mentions and an attachment color for severity.
1h ago 0
SQL
NULLS FIRST / NULLS LAST
Control where NULLs land in an `ORDER BY`. PostgreSQL/Oracle default NULLs to LAST in ASC, FIRST in DESC; MySQL/SQL Server flip it. Be explicit if it matters.
1h 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.
1h ago 0
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).
1h 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.
1h 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.
1h 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.
1h ago 0
Bash
Sort by a Specific Column
Sort takes -k for column-based ordering and -t to set the delimiter. -h sorts human-readable sizes ("1.5G", "300K") correctly.
1h 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.
1h ago 0
Python
Literal + match for Exhaustive Switching
`Literal` pins a value to specific strings/ints. Combine with the match statement (Python 3.10+) and a `_ : assert_never` clause for exhaustiveness — every variant must be handled or mypy yells at you.
1h 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.
1h ago 0
Python
asyncio.wait_for — Timeout Wrapper
Cancel a coroutine if it takes longer than `timeout` seconds. Raises asyncio.TimeoutError when fired so the caller can fall back. Python 3.11+ has asyncio.timeout() as a context-manager alternative.
1h 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.
1h ago 0
Rust
zip / enumerate / chain
Three adapters that pair, index, and concatenate iterators. Every Rust developer reaches for them daily.
1h ago 0