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

Showing 451–480 of 770 public snippets

Rust
windows / chunks — Sliding & Fixed
`windows(n)` yields every overlapping sub-slice of length n; `chunks(n)` yields non-overlapping chunks. Both work on slices for free, no extra crates.
6h ago 0
Go
Generic Set Type
A type-safe Set built on `map[T]struct{}` and Go generics. Has Add / Has / Delete / Size — and uses zero bytes per entry for the value side.
6h ago 0
Go
database/sql — Open + Query
`database/sql` is driver-agnostic — pick a driver (`pgx/stdlib`, `go-sql-driver/mysql`, `mattn/sqlite3`). Always `defer db.Close()` only on app exit; the pool is meant to be long-lived.
6h ago 0
Go
slices package — Modern Helpers
`slices` (Go 1.21+) ships the iteration helpers everyone wrote by hand for years: Contains, Index, Sort, SortFunc, BinarySearch, Clone, Reverse, Equal, Max/Min.
6h ago 0
Kotlin
let — Transform or Null-Safe Scope
`x.let { it.foo }` runs the block with `x` as `it` and returns the block's last expression. Combined with `?.`, it's the canonical "do this only if non-null" pattern.
6h ago 0
Java
Jackson — Basic ObjectMapper
`com.fasterxml.jackson.databind.ObjectMapper` is the JSON standard for Java. Construct once (it's expensive + thread-safe) and reuse for every serialization in your app.
6h ago 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.
6h ago 0
PHP
Simple cURL GET with Timeout
A no-dependency HTTP GET helper with sensible defaults: short timeout, follow redirects, return body as string, throw on transport error. Pass extra headers as a simple associative array.
6h ago 0
PHP
Validate Credit Card (Luhn check)
Apply the Luhn checksum algorithm to a credit card number. Strips spaces/dashes first. This validates the format — not whether the card actually exists or has funds.
6h ago 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.
6h ago 0
HTML
Modern Meta Tags (viewport, theme-color, etc.)
The non-obvious meta tags that improve mobile rendering, status-bar coloring, and dark-mode behavior in 2025 browsers. Copy this block whole.
6h ago 0
TypeScript
Debounce (typed)
Wait until the caller stops invoking for `delay` ms, then call the function with the most recent arguments. The TS version preserves the original signature so the returned function has the same parameters.
6h ago 0
Bash
Unique While Preserving Order
`sort -u` re-orders. `awk '!seen[$0]++'` is the classic order-preserving dedupe — and it's a single line.
6h ago 0
Go
log/slog — Structured Logging
`log/slog` (Go 1.21+) is the standard structured logger. Drop-in replacement for `log` with key/value attributes and JSON output for log-pipeline ingestion.
6h ago 0
HTML
Loading State with aria-busy
`aria-busy="true"` tells assistive tech "this section is updating — wait until it's done before re-reading." Combine with a visual spinner and an `aria-live` status message for the best experience.
6h ago 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.
6h ago 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.
6h ago 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.
6h ago 0
Python
Deprecation Warning Decorator
Mark a function as deprecated so callers get a DeprecationWarning the first time it's called. Includes the replacement function name in the message so callers know what to switch to.
6h ago 0
Go
Read File — Whole / Lines / Bytes
Three common patterns: load it all (`os.ReadFile`), iterate line-by-line with `bufio.Scanner`, or stream chunks via `io.Reader`. Pick by file size.
6h ago 0
Kotlin
Cheatsheet: let / apply / also / run / with
Five scope functions cover ~95% of "do something with x" patterns. Pick by two axes: receiver (this vs it) and return value (object itself vs block result).
6h ago 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.
6h ago 0
TypeScript
Truncate at Word Boundary
Cap a string at `max` characters without splitting a word, appending an ellipsis when truncated. Falls back gracefully if the last word is longer than `max`.
6h ago 0
Bash
Safe Bash Script Template
Start every script with the same skeleton: strict error mode (errexit, nounset, pipefail), an IFS reset, and a main() function. Catches silent failures that have lost engineers weeks of debugging.
6h ago 0
Bash
Parallel Map with xargs -P
`xargs -P N` is a Swiss-army knife for parallel map: feed it a list of inputs and a command, it runs N workers. Faster and simpler than bash for-loops with `&`.
6h ago 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.
6h ago 0
PHP
Mask Sensitive Strings (credit cards / emails)
Mask the middle of a string while keeping a few characters at each end visible. Useful for displaying credit card numbers, emails, or API keys in UI without leaking them in full.
6h ago 0
Bash
Word Frequency Count
Classic shell one-liner: split text into words, sort, count uniques, sort by count. Useful for log analysis, content audits, and tag-cloud-style summaries.
6h ago 0
Bash
Progress Bar (basic)
Draw a single-line progress bar that updates in place. Useful for batch jobs where you know the total work count up front.
6h ago 0
TypeScript
zip — Pair Two Arrays
Pair items from two arrays positionally into tuples. The result's length is the shorter of the two inputs. Useful for parallel arrays (labels + values, headers + rows).
6h ago 0