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

Showing 661–690 of 770 public snippets

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
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.
27m ago 0
PHP
Validate URL (scheme + host)
Beyond filter_var, also require the URL to have an http(s) scheme and a non-empty host. Rejects "javascript:" and other risky pseudo-schemes commonly seen in stored XSS.
27m ago 0
Rust
Threads with thread::spawn + join
Native OS threads with `std::thread::spawn`. The returned `JoinHandle` lets you wait for the thread and get its return value. Use `move` to transfer ownership of captured variables.
27m ago 0
Bash
Process Substitution Cheatsheet
`<(...)` makes a command's output look like a file; `>(...)` makes a command's input look like a file. Killer feature for tools that only accept filenames.
27m ago 0
Go
errgroup — Fan-Out with Cancellation
`golang.org/x/sync/errgroup` runs N goroutines, returns the first error, and cancels the others via a shared context. The right pattern for parallel I/O where any failure should abort the rest.
27m ago 0
HTML
Semantic Article Structure
`<article>` for self-contained content (blog post, comment, news item). Each article gets its own header, body, and (optionally) footer. Helps screen readers, RSS, and Google understand structure.
27m ago 0
JavaScript
DOM Ready Helper
Runs a callback when the DOM is fully parsed and ready, without waiting for images or stylesheets. Works whether called before or after DOMContentLoaded has already fired — unlike a bare addEventListener which misses the event if the DOM is already ready when the script runs.
27m ago 0
PHP
Detect & Strip Byte Order Mark
Some text editors prepend a UTF-8 BOM (0xEF 0xBB 0xBF) which breaks header() calls, JSON, and PHP output. Detect and strip it defensively when ingesting external files.
27m ago 0
Rust
zip / enumerate / chain
Three adapters that pair, index, and concatenate iterators. Every Rust developer reaches for them daily.
27m ago 0
SQL
date_trunc — Bucket Times into Hours/Days/Weeks
`date_trunc('day', ts)` rounds a timestamp down to the start of the day. Use for time-series GROUP BYs — daily/weekly/hourly buckets without messy arithmetic.
27m ago 0
Python
JWT Sign + Verify (PyJWT)
The de-facto JWT library for Python. HS256 demo with an exp claim and the standard "verify everything" decode flow. Mind that PyJWT raises specific exceptions you can catch separately.
27m ago 0
Java
CountDownLatch — Wait for N Events
Block one or more threads until a count of events occurs. Set the count up front; each event calls `countDown()`; waiters call `await()`. Classic "wait until all workers are ready" pattern.
27m ago 0
Java
Generic Class with Type Parameter
Stamp out type-safe containers and helpers — same class body, multiple element types. The `<T>` declaration is what makes it generic.
27m ago 0
PHP
Word Count (UTF-8 aware)
Count words in a string in a way that works for any Unicode script — including those without ASCII whitespace. Built on the \p{L}\p{N} Unicode regex categories.
27m ago 0
PHP
Unique by Callback
Like array_unique, but the uniqueness test is a callback that returns the key to dedupe by. Useful for "unique by ID" or "unique by lowercased email" across arrays of objects/rows.
27m ago 0
PHP
Validate Email (RFC-aware)
Use PHP's built-in FILTER_VALIDATE_EMAIL with the FILTER_FLAG_EMAIL_UNICODE flag for IDN domains, plus a length sanity check. Trust this over hand-rolled regex.
27m ago 0
Python
asyncio.wait_for — Timeout Wrapper
Cancel a coroutine if it takes longer than `timeout` seconds. Raises asyncio.TimeoutError when fired so the caller can fall back. Python 3.11+ has asyncio.timeout() as a context-manager alternative.
27m ago 0
TypeScript
Deferred / Externally-Resolvable Promise
Create a Promise whose `resolve` and `reject` are exposed externally. Useful when you need to settle a promise from outside its executor — e.g. waiting on an event-driven response.
27m ago 0
HTML
Textarea with Character Counter
Combine `maxlength` (hard cap) with a small JS-driven live counter. Browsers won't let users paste past `maxlength`, so this is purely UX feedback.
27m ago 0
PHP
PDO Schema Existence Checks
Idempotent helpers to test whether a table, column, or index already exists — handy when writing your own migration runner without an ORM.
27m ago 0
Java
CompletableFuture — Async Chains
`CompletableFuture` is the idiomatic way to compose async work. `thenApply` for sync transforms, `thenCompose` for async chains (flatMap), `exceptionally` for fallback on failure.
27m ago 0
JavaScript
Base64 Encode & Decode (Unicode-safe)
Encodes and decodes strings to/from Base64. The native btoa/atob only handles Latin-1 characters, so these wrappers use TextEncoder/Uint8Array to handle the full Unicode range including emoji and CJK characters. Useful for encoding binary data, tokens, and payloads for URLs or localStorage.
28m 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.
28m ago 0
Bash
Run on Multiple Hosts via SSH (with progress)
Iterate a host list, run the same command on each, show colored OK/FAIL summary at the end. Useful for ad-hoc fleet operations without setting up Ansible.
28m ago 0
JavaScript
Detect Dark Mode Preference
Reads the user's OS-level dark mode preference using the prefers-color-scheme media query and watches for live changes. Useful for initialising theme state before any user interaction and reacting automatically when the user switches their system theme without reloading the page.
28m ago 0
PHP
Find Files Modified in Last N Days
List every file under a directory that was modified within the last N days. Useful for incremental backups or detecting stale entries.
28m 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.
28m ago 0
JavaScript
Memoize Function
Caches the result of a pure function keyed by its serialised arguments. On repeated calls with the same inputs the cached value is returned instantly, skipping expensive computation. Supports single and multi-argument functions via JSON key serialisation.
28m ago 0