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

Showing 1–30 of 770 public snippets

JavaScript
Serialize Form to Object
Converts all named form fields into a plain JavaScript object using the FormData API. Handles text inputs, selects, textareas, and checkboxes. Multiple values for the same name (e.g. multi-select, checkboxes) are collected into an array. Ready to JSON.stringify and POST to an API.
2h ago 1
JavaScript
Cookie Helpers (Get / Set / Delete)
Minimal cookie utilities: getCookie retrieves a value by name, setCookie writes a cookie with optional expiry days and path, deleteCookie removes it by setting an expired date. No library needed for simple first-party cookie management. For complex scenarios (SameSite, Secure, partitioned) extend the options object.
2h ago 1
JavaScript
i18n Minimal Translator
A tiny internationalisation helper that loads a locale dictionary and resolves translation strings by dot-notation key. Supports variable interpolation via {{placeholder}} syntax. Falls back to the key itself when a translation is missing, keeping the UI readable during development. Swap the locale at runtime without a page reload.
2h ago 1
JavaScript
Flatten Object (Dot Notation)
Flattens a deeply nested object into a single-level object with dot-notation keys. Useful for comparing configs, building form field names from nested data, logging structured objects to analytics, or preparing data for flat key-value stores like Redis or environment variables.
2h ago 1
JavaScript
Middleware Pipeline
A simple Koa/Express-style middleware runner for client-side use. Middleware functions receive a context object and a next() function — call next() to pass control to the next middleware or skip it to short-circuit the chain. Useful for building plugin systems, request pipelines, and composable validation logic.
2h ago 1
HTML
Radio Group with Fieldset + Legend
Always wrap radio groups (and checkboxes that share semantics) in a `<fieldset>` with a `<legend>`. Screen readers announce the legend before each option — without it, the choice is contextless.
23m ago 0
PHP
CSV Writer with Proper Escaping
Write rows to a CSV file using fputcsv with sensible quoting. Also writes a UTF-8 BOM so Excel opens the file with the right encoding.
37m ago 0
PHP
Truncate Text with Ellipsis (word-safe)
Cleanly truncate a string to a max length without breaking words mid-character. Adds a trailing ellipsis when truncated and never exceeds the requested length including the ellipsis.
1h ago 0
PHP
Levenshtein Similarity Percentage
Wrap PHP's built-in levenshtein() to return a similarity score from 0.0 (totally different) to 1.0 (identical). Handy for "did you mean…?" suggestions.
1h ago 0
Java
Functional Interfaces — Function / Predicate / Consumer / Supplier
The four core single-method interfaces in `java.util.function`. They're the parameter types for streams, Optional methods, CompletableFuture, and countless library APIs.
1h ago 0
HTML
Details / Summary — Native Accordion
`<details>` is the built-in "click to expand" widget. Free keyboard navigation, search-engine-indexable content (open or closed), no JS needed. Style with CSS to match your design.
1h ago 0
HTML
Hero Section
The big "above the fold" intro on a landing page: large heading, sub-copy, primary CTA, optional supporting image. Keep the H1 unique to the page and one per document.
1h ago 0
Rust
macro_rules! — Simple Declarative Macros
Declarative macros let you write functions that take token trees instead of values. Great for boilerplate reduction; cleaner than copy-paste, simpler than proc macros.
1h ago 0
PHP
Convert Camel Case ↔ Snake Case
Convert between camelCase and snake_case identifiers. Handy when mapping JS API responses (camelCase) into PHP database column names (snake_case) and vice versa.
1h ago 0
Kotlin
init Block + Constructor Order
`init { }` blocks run during construction, in declaration order, interleaved with property initializers. Use to validate the primary constructor or set up derived state.
1h ago 0
HTML
RTL (Right-to-Left) Document
Set `dir="rtl"` on the root element for languages that read right-to-left (Arabic, Hebrew, Persian). The browser flips text alignment, scroll, and form controls automatically. Use `dir="auto"` to let user-generated text decide per-block.
1h ago 0
HTML
Print Stylesheet Setup
Tune the print layout: hide nav/footer, force black-on-white text, expand absolute URLs, hide images you don't want printed. Save your users from wasting paper on the page chrome.
1h ago 0
Rust
Cargo Workspace Setup
A workspace lets a single repo contain multiple related crates (e.g. core lib + CLI + server) that share `target/` and dependencies. The root `Cargo.toml` lists members.
1h ago 0
PHP
Normalize Phone Number to E.164
A minimal E.164 normalizer for US/CA numbers — strips formatting, prepends "+1" if missing, and validates the digit count. For full international support, reach for giggsey/libphonenumber-for-php.
1h ago 0
PHP
Send Plain Email via mail()
A thin wrapper around PHP's mail() with proper headers (From, Reply-To, Content-Type with UTF-8). For anything serious reach for PHPMailer or Symfony Mailer — this is fine for transactional one-offs.
1h ago 0
Bash
URL-Encode and URL-Decode
Encode and decode URL-safe strings entirely in bash — no python or external tool required. Useful in pure-shell deployment scripts that need to build query strings.
1h ago 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.
1h 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.
1h 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.
1h ago 0
Go
iter.Seq — Range-Over-Func (Go 1.23+)
Go 1.23 added "range over func" — your own functions can produce values that work with `for v := range fn`. Cleaner than channels for in-process iteration without goroutine overhead.
1h ago 0
Kotlin
repeat, also lateinit and isInitialized
`repeat(n) { i -> ... }` for N-times loops where you don't care about index naming. `lateinit var` lets you declare a non-null var without initializing it — common for DI / framework injection.
1h ago 0
Rust
unsafe — When and How
Most Rust is safe. `unsafe` only lets you do 5 things the compiler can't check (raw pointer deref, mutable static, unsafe fn / trait, FFI, union access). Wrap unsafe operations in safe abstractions.
1h ago 0
Go
JSON Marshal / Unmarshal
`encoding/json` is the standard library JSON parser. `Marshal` produces compact JSON; `MarshalIndent` produces pretty-printed. `Unmarshal` decodes into a typed value (struct, map, or any).
1h ago 0
PHP
Email Address Obfuscator
Render an email address as HTML that is human-readable but resistant to naive scraping bots. Uses entity encoding and an optional Caesar-style ROT for the mailto link.
1h ago 0
TypeScript
Slugify (Unicode-aware)
Turn any string into a URL-safe slug. Uses Intl normalize + diacritic stripping so "Café" becomes "cafe". No external dependency.
1h ago 0