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

Showing 631–660 of 770 public snippets

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).
27m ago 0
Java
HttpClient — Async (CompletableFuture)
`sendAsync` returns a `CompletableFuture<HttpResponse<T>>` — chain it like any other CF. Fan out N requests, wait for all with `CompletableFuture.allOf`.
27m ago 0
JavaScript
Detect Mobile / Device Type
Detects whether the user is on a mobile, tablet, or desktop device. The navigator.userAgentData API (Chromium) is preferred for its structured data; falls back to a User-Agent regex for Safari and Firefox. Useful for conditional rendering, touch event handling, and analytics segmentation.
27m 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.
27m ago 0
Go
Minimal net/http Server
The standard library ships a production-quality HTTP server. `http.HandleFunc` registers a function; `http.ListenAndServe` blocks forever serving requests.
27m 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.
27m ago 0
Kotlin
windowed and chunked
`chunked(n)` splits a list into NON-overlapping pieces of size n. `windowed(n)` slides a fixed-size window across — overlapping. Useful for moving averages, n-grams, batch APIs.
27m ago 0
PHP
Average / Median / Mode
Three classic descriptive statistics over a numeric array. Built without any external math library — just sort + count.
27m ago 0
PHP
RGB ↔ Hex Conversion
Two-way conversion between #RRGGBB hex strings and [R, G, B] arrays. Handy when working with theme colors that come from both sources (CSS strings vs. RGB sliders).
27m 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.
27m ago 0
Rust
axum — Hello World HTTP Server
axum is the tokio-team's web framework — composable, type-safe handlers built on tower middleware. The hello-world is small enough to read in one screen.
27m ago 0
Go
Pipeline (channel chain)
A pipeline is a chain of stages connected by channels — each stage runs in its own goroutine. Classic Go pattern for streaming transformations with backpressure built in.
27m ago 0
Java
java.time — Duration and Period
`Duration` for elapsed time (hours/minutes/seconds). `Period` for calendar amounts (days/months/years). Don't mix — calendar math respects month lengths and DST; clock math doesn't.
27m ago 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.
27m ago 0
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.
27m 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.
27m ago 0
Java
flatMap — Flatten Nested Streams
Map each element to a Stream, then concatenate all of them into one. Used everywhere from "all words from a list of sentences" to "all permissions from a list of roles".
27m ago 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".
27m 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.
27m ago 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.
27m ago 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.
27m ago 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`).
27m ago 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.
27m 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.
27m ago 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.
27m ago 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.
27m ago 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).
27m ago 0
Kotlin
Write to a File
`writeText` overwrites; `appendText` appends. For multiple writes, use `bufferedWriter().use { }` for efficiency + auto-close.
27m 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.
27m ago 0
Kotlin
Ktor Server — Middleware (Plugins)
Plugins wrap every request — logging, CORS, auth, rate limiting. Install with `install(Plugin) { config }` at the application level.
27m ago 0