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

Showing 121–150 of 770 public snippets

Rust
flat_map and Iterator::flatten
`flat_map(f)` is `map(f).flatten()` — map each item to an iterator, then concatenate. Indispensable for working with nested structures.
just now 0
PHP
CSRF Token Generate + Verify
Per-session CSRF token helpers using hash_equals for constant-time comparison. Token is regenerated on logout but persists across requests within a session.
just now 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.
just now 0
Go
Test Helpers with t.Helper()
When you extract a verification routine into a helper, call `t.Helper()` so failure messages point to the CALLER line — not the helper line. One line, much better diagnostics.
just now 0
HTML
Card Pattern (article + link wrapper)
The standard content card — image, title, excerpt, meta. Make the WHOLE card clickable by wrapping the title link and using `::after` to extend the hit area to the full card.
just now 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.
just now 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.
just now 0
HTML
All Standard Input Types
HTML5 input types each have built-in validation, on-screen keyboards (mobile), and pickers. Use them — `<input type="number">` beats `<input type="text">` + JS validation every time.
just now 0
Bash
Clean Up Merged Branches
Delete every local branch that's been merged to main. Filters out main/master and the current branch as a safety net.
just now 0
PHP
Atomic File Write
Write a file in a way that other processes never see a half-written state. Write to a temp file in the same directory, then rename — rename is atomic on POSIX filesystems.
just now 0
TypeScript
Type-Safe Event Emitter
A 30-line type-safe mini EventEmitter. The event-name → payload map is enforced at compile time, so emit and on calls can't drift apart.
just now 0
PHP
Validate Password Strength
Score a password 0–4 (NIST-inspired, not the full zxcvbn algorithm). Encourages length over complexity; flags well-known weak patterns. Use as a UI hint, not a hard barrier.
just now 0
Kotlin
distinct, distinctBy, intersect, union
Set-style ops on collections. `distinct` removes duplicates; `distinctBy` lets you key the dedupe by a derived value; `union/intersect/subtract` give you set operations.
just now 0
Kotlin
Sequences — Lazy Collections
A `List` materializes every intermediate `map`/`filter` result. A `Sequence` processes ONE element through the whole pipeline at a time — better for big inputs or short-circuiting (`first`, `take`).
just now 0
PHP
Find Open TCP Port
Probe whether a remote host:port accepts connections, with a configurable timeout. Useful for quick health checks in deploy scripts.
just now 0
JavaScript
Flatten Nested Array
Recursively flattens an array of arbitrary nesting depth into a single flat array. Accepts an optional depth limit — pass Infinity to flatten completely. Uses the native Array.flat when the browser supports it, otherwise falls back to a recursive reduce.
just now 0
Rust
tokio mpsc Channel
Async multi-producer / single-consumer channel. Producers `.send()`, the single receiver `.recv().await` items as they arrive. Bounded — the channel back-pressures producers when full.
just now 0
TypeScript
Sleep / Delay
The async/await-friendly version of `setTimeout`. The one-liner everyone re-invents — keep it in a util file. Optional AbortSignal lets you cancel mid-wait.
just now 0
PHP
Generate Identicon Avatar
Render a deterministic 5x5 symmetric "identicon" placeholder avatar from any seed (usually a user's email or username). No external service — pure GD.
just now 0
Kotlin
map / filter / reduce
The three classic functional combinators. Each takes a lambda and returns a new collection (or a single value for reduce). Chain freely — intermediate allocations only matter at very large scale (use `Sequence` then).
just now 0
Go
Table-Driven Tests with t.Run
A table of test cases looped through `t.Run` gives every case its own name in the output, makes adding new cases trivial, and lets you run individual cases with `-run TestX/case_name`.
just now 0
TypeScript
range — Lazy Number Iterator
A generator-based numeric range: `[start, end)` with an optional step. Lazy so it doesn't allocate a huge array up front; consume with for…of or Array.from.
just now 0
JavaScript
Web Crypto — AES-GCM Encrypt & Decrypt
Encrypts and decrypts text using AES-GCM (256-bit) via the browser's native Web Crypto API — no external library needed. A random 96-bit IV is generated per encryption and prepended to the output so decryption can recover it. Suitable for encrypting sensitive data client-side before storage.
just now 0
Kotlin
Write to a File
`writeText` overwrites; `appendText` appends. For multiple writes, use `bufferedWriter().use { }` for efficiency + auto-close.
just now 0
HTML
Code Markup — pre, code, kbd, samp, var
HTML has five semantic elements for technical text: `<code>` (source code), `<pre>` (preserve whitespace), `<kbd>` (keyboard input), `<samp>` (sample output), `<var>` (math/program variable). Each has a different meaning to screen readers and search engines.
just now 0
TypeScript
clamp / lerp / mapRange
Three numeric utilities you reach for constantly in animation, UI math, and audio code. Generic enough to use anywhere, no Math.* dance required.
just now 0
Bash
cURL GET with Timeout + Retry
A sensible default cURL invocation: short connect timeout, total timeout, retry on transient failures with backoff, fail-on-error.
just now 0
SQL
Transactions and Isolation Levels
Wrap related changes in a transaction so they commit or roll back together. Isolation levels trade consistency for concurrency — pick the weakest one that meets your correctness needs.
just now 0
Kotlin
Ktor Server — Middleware (Plugins)
Plugins wrap every request — logging, CORS, auth, rate limiting. Install with `install(Plugin) { config }` at the application level.
just now 0
Python
Multipart File Upload
POST a file (or several) as multipart/form-data using requests, with optional extra form fields. Lets you upload to /avatar-style endpoints without manual boundary construction.
just now 0