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

Showing 691–720 of 770 public snippets

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.
5d ago 0
Java
Switch Expressions (Java 14+)
`switch` is now also an expression — it returns a value. Use `->` arrows for fall-through-free arms; `yield` inside `{ }` blocks for multi-statement arms. No more accidental forgotten `break`.
5d ago 0
Python
Producer / Consumer Queue (threading)
Classic producer / multi-consumer pattern using queue.Queue. Producers put work onto the queue; consumers pull and process; a sentinel value signals shutdown.
5d ago 0
Kotlin
require / check / requireNotNull
Three contract-style assertions in the stdlib: `require` for inputs (throws `IllegalArgumentException`), `check` for state (throws `IllegalStateException`), `requireNotNull` returns the value smart-cast.
5d ago 0
JavaScript
Validate Email Address
Validates an email address using a battle-tested regex that covers the vast majority of real-world addresses without being overly strict. For server-side code, pair this with a confirmation email step — client-side regex alone is not a security measure. Returns a boolean for easy conditional use.
5d ago 0
Go
Sentinel Errors (var ErrFoo = errors.New)
Sentinel errors are package-level singletons you can compare against with `errors.Is`. Use sparingly — they're part of your package's API surface and changing them is a breaking change.
5d ago 0
SQL
RANK / DENSE_RANK
`RANK` leaves gaps after ties (1, 2, 2, 4); `DENSE_RANK` doesn't (1, 2, 2, 3). `ROW_NUMBER` is always unique. Pick by what tied rows should produce.
5d ago 0
Go
regexp.MustCompile + FindAll
`regexp.MustCompile` panics on a bad pattern at startup — perfect for package-level vars. Use `Find`, `FindString`, `FindAllStringSubmatch` to extract matches and capture groups.
6d ago 0
JavaScript
Generate Initials Avatar (Canvas)
Draws a coloured circular avatar with up to two initials on an HTML5 Canvas and returns it as a data URL. Generates a consistent background colour from the name string so the same user always gets the same colour. Useful as a fallback when a user has no profile photo.
6d ago 0
SQL
NTILE — Bucket Rows into N Buckets
Assign rows to N approximately-equal-sized buckets based on the ORDER BY. The standard way to compute quartiles, deciles, or any percentile bucket.
6d ago 0
Kotlin
Extension Functions
Add methods to ANY type — including stdlib types like String, List, or Int — without subclassing. Compiled as a static dispatched function, so no runtime overhead.
6d ago 0
JavaScript
Parse URL Query String
Parses a URL query string into a plain key-value object. Uses the built-in URLSearchParams API — no regex required. Handles duplicate keys (returns the first value), percent-encoded characters, and works with both full URLs and raw query strings. Pairs nicely with buildQueryString.
Jun 20, 2026 0
Java
var — Local Type Inference (Java 10+)
`var` for local variables lets the compiler infer the type from the initializer. Reduces noise when the type is obvious from context — but you still get static typing.
Jun 20, 2026 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.
Jun 20, 2026 0
Kotlin
Operator Overloading
Specially-named methods or extensions get operator syntax: `plus → +`, `minus → -`, `times → *`, `get → []`, `invoke → ()`, `contains → in`. Use sparingly for types that have natural arithmetic semantics.
Jun 20, 2026 0
Rust
Lifetime Annotations Basics
Lifetimes are how Rust proves references don't outlive what they point to. Most are inferred — but functions returning references from arguments need explicit `'a` to relate input and output.
Jun 20, 2026 0
Java
Pattern Matching for instanceof (Java 16+)
Combine `instanceof` with a variable binding — no separate cast needed. Eliminates the most common "check then cast" bug pattern and is significantly less verbose.
Jun 20, 2026 0
JavaScript
Retry Promise with Backoff
Retries a Promise-returning function up to a specified number of times with configurable exponential backoff and optional jitter. Accepts a shouldRetry predicate so you can skip retries on specific error types (e.g. 401 Unauthorized). Returns the resolved value or re-throws the last error after exhausting retries.
Jun 20, 2026 0
PHP
Discord Webhook Notification
Same idea as Slack but for Discord webhooks — supports rich embeds with a title, description, and color. Useful for dev/ops dashboards or bot integrations.
Jun 20, 2026 0
Bash
Symlink Force-Update
`ln -s` fails if the target already exists. `ln -sf` is the idempotent variant — useful in deploy scripts that point a "current" symlink to a fresh release directory.
Jun 20, 2026 0
Kotlin
Pair, Triple, and to() Infix
`Pair<A,B>` and `Triple<A,B,C>` are stdlib lightweight tuples. The `to` infix returns a Pair — used everywhere for map literals.
Jun 19, 2026 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.
Jun 19, 2026 0
SQL
INSERT … SELECT — Bulk Copy
Copy/transform rows from a SELECT into another table — the cheapest way to move data within the database. Skip column lists at your peril; positional matching is fragile.
Jun 19, 2026 0
Rust
Enum with Data + match
Rust enums are full sum types — each variant can carry its own data. `match` is exhaustive: leave a variant unhandled and the compiler refuses to build.
Jun 19, 2026 0
SQL
COALESCE / NULLIF — Null Handling
`COALESCE(a, b, c)` returns the first non-NULL value — perfect for fallbacks. `NULLIF(a, b)` returns NULL when a equals b — handy for "treat sentinel as null".
Jun 19, 2026 0
SQL
Correlated Subquery
A subquery that references the outer query's row. Slower than a JOIN for big result sets but sometimes the most readable expression.
Jun 19, 2026 0
Java
Text Blocks (Java 15+)
Multi-line string literals with proper indentation handling. Stop concatenating newlines by hand. The compiler removes the common leading whitespace automatically.
Jun 19, 2026 0
Go
embed — Compile Assets into the Binary
Go 1.16+ `embed` lets you bundle static files (templates, web assets, SQL migrations) directly into the compiled binary — no companion files to ship.
Jun 19, 2026 0
HTML
Responsive Table — Scroll on Mobile
Wrap any wide table in a horizontally-scrolling container. The table itself stays semantic (no display:block hacks that break screen readers); only the wrapper scrolls.
Jun 18, 2026 0
Java
ConcurrentHashMap — Thread-Safe Map
The default thread-safe map. Better than `Collections.synchronizedMap` — segmented locking allows multiple readers AND writers. Use `compute`, `merge`, `putIfAbsent` for atomic compound updates.
Jun 18, 2026 0