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

Showing 661–690 of 770 public snippets

Rust
impl Trait — Static Dispatch Returns
When you want to return a complex iterator chain or closure, you don't need to spell out the type. `impl Trait` lets the compiler infer the concrete type while exposing only the API contract.
3h ago 0
Kotlin
inline Functions — Zero-Cost Lambdas
`inline fun` copies the body (including lambda bodies) into the call site at compile time. Result: no `Function` object allocated for the lambda; `return` from inside the lambda exits the enclosing function.
3h ago 0
Kotlin
Compose Modifier Chain
`Modifier` is how you customize composables — padding, click handlers, background, size, alignment. Order matters: each modifier wraps the previous one.
3h ago 0
Kotlin
Exposed — Kotlin-First ORM
JetBrains' Exposed combines a SQL DSL with a lightweight ORM. Either style is fully type-safe; both compile to plain SQL.
3h ago 0
Go
time.Ticker — Periodic Tasks
`time.NewTicker(d)` fires on a channel every `d` interval. Combine with select + a done channel for a clean way to run periodic work that can be cancelled.
3h ago 0
PHP
Partition Array Into Two Buckets
Split an array into [matches, non-matches] using a predicate callback. Single pass, preserves order, returns two lists.
3h ago 0
Python
sqlite3 with Row Factory + Context
Stdlib sqlite3 is fine for embedded / small workloads. Use `with conn:` for automatic commit/rollback, and a row_factory so you get dicts (or namedtuples) instead of bare tuples.
3h ago 0
Bash
Heredoc with Variable Interpolation Control
Heredocs are the cleanest way to embed multi-line text. Unquote the delimiter to allow variable expansion; QUOTE it to keep the body literal (no $foo expansion).
3h ago 0
Bash
Count Occurrences of a Pattern
Several ways to count matches: lines containing X, total matches across a file, matches grouped by capture, etc.
3h ago 0
Java
Builder Pattern
For objects with many optional parameters, a Builder beats a constructor with 12 args (or a half-initialized object you have to call setters on). Method chaining + a `build()` step that validates.
3h ago 0
HTML
Navigation with aria-current
Use `<nav>` for primary navigation. Mark the currently-active link with `aria-current="page"` — screen readers will announce it, and you get a free CSS hook with `[aria-current]`.
3h ago 0
Python
Dataclass with frozen + slots + defaults
Modern dataclass essentials: immutable instances (frozen=True), tighter memory + faster attribute access (slots=True), and default_factory for mutable defaults so every instance gets its own list.
3h ago 0
Bash
Tail Last N Lines (no `tail` shortcuts)
`tail -n 20` works for any case where tail is available. The pure-bash version below is useful inside containers or rescue shells where coreutils is missing.
3h ago 0
Bash
Filter Lines by Regex
grep -E (extended regex) is the right tool 95% of the time. Combine -i (case-insensitive), -v (invert), -n (line numbers), -B/-A (context lines).
3h ago 0
Rust
unsafe — When and How
Most Rust is safe. `unsafe` only lets you do 5 things the compiler can't check (raw pointer deref, mutable static, unsafe fn / trait, FFI, union access). Wrap unsafe operations in safe abstractions.
3h ago 0
Go
Interface Segregation — Small Interfaces
"The bigger the interface, the weaker the abstraction." Go encourages small, focused interfaces (often just one method) — io.Reader, io.Writer, fmt.Stringer. Define them at the consumer side.
3h ago 0
Go
Benchmarks with testing.B
`BenchmarkXxx(b *testing.B)` functions are run by `go test -bench`. `b.N` is the loop count the framework auto-tunes; report results in ns/op, allocs/op.
3h ago 0
HTML
RTL (Right-to-Left) Document
Set `dir="rtl"` on the root element for languages that read right-to-left (Arabic, Hebrew, Persian). The browser flips text alignment, scroll, and form controls automatically. Use `dir="auto"` to let user-generated text decide per-block.
3h ago 0
Kotlin
apply — Configure Object, Return Itself
`x.apply { ... }` runs the block with `x` as `this` (so you call methods/set properties directly) and returns `x`. The canonical builder-style configuration.
3h ago 0
Kotlin
Jetpack Compose — Basic Composable
Compose is Android's modern declarative UI toolkit. A `@Composable` function describes UI; the runtime re-runs it when inputs change. Replaces XML layouts entirely.
3h ago 0
Python
NewType for Nominal IDs
Python's type system is structural — `UserId` and `PostId` are both just `int` unless you ask otherwise. `NewType` creates a distinct type with zero runtime cost for static checking only.
3h ago 0
Bash
Convert Between Timezones
Set TZ inline to print a date in a specific timezone, then read with another TZ. Avoids messing with the system timezone.
3h ago 0
Rust
fold / reduce / scan
`fold` is the general aggregator: starts from an accumulator, applies a fn to each item. `reduce` uses the first item as the seed. `scan` yields intermediate accumulator values.
3h ago 0
Go
iota — Auto-Incrementing Constants (Enums)
Go has no `enum` keyword but `iota` inside a const block gives you the same effect. Each line is the previous expression with iota auto-incremented.
3h ago 0
Rust
Result Combinators + the ? Operator
`Result<T, E>` chains like `Option`. The `?` operator unwraps `Ok` or early-returns the `Err`, converting via `From` so callers can use one error type for many sources.
3h ago 0
Go
Custom Generic Constraints
Type constraints are interfaces with type sets. Use them to express "any numeric" or "any ordered" without resorting to `any`.
3h ago 0
TypeScript
Capitalize / Title-Case
Two common case transforms. `capitalize` for the first letter only; `titleCase` for every word, with small "stop words" left lowercase except at the edges.
3h ago 0
Python
Async Retry with Exponential Backoff
Retry an async operation up to N times, doubling the wait each attempt with random jitter to avoid thundering herd. Predicate controls retryability so 4xx errors stop immediately.
3h ago 0
Java
java.time — Instant, LocalDate, ZonedDateTime
Java 8's `java.time` package replaced the broken `Date`/`Calendar`. Three types you actually use: `Instant` (UTC moment), `LocalDate` (date with no tz), `ZonedDateTime` (date+time in a zone).
3h ago 0
Java
Stream Basics — filter / map / collect
The fluent pipeline for transforming collections. `filter` keeps matching elements, `map` transforms each one, `collect(toList())` materializes the result.
3h ago 0