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

Showing 751–770 of 770 public snippets

Go
sync.Pool — Reuse Allocations
`sync.Pool` keeps a pool of reusable objects to reduce allocator pressure in hot paths. Good for byte buffers, JSON encoders, or anything you allocate frequently and only need briefly.
5d ago 0
JavaScript
Fetch with Retry
Wraps the native fetch API with automatic retry logic using exponential backoff. Retries on network errors or non-OK HTTP responses up to a configurable number of attempts. Exponential backoff with optional jitter prevents thundering herd problems when many clients retry simultaneously.
6d ago 0
Bash
Squash Last N Commits
Combine the last N commits into one before merging a feature branch. Avoids hours of "WIP" / "fix typo" commits cluttering history.
6d ago 0
TypeScript
AbortController-Wrapped Fetch
Wire an AbortController so you can cancel in-flight fetches when the user navigates away or types another search query. The optional timeout helper rejects automatically.
6d ago 0
JavaScript
Rate Limiter (Token Bucket)
Implements a token-bucket rate limiter that allows a burst of calls up to a maximum capacity, then replenishes tokens at a steady rate. Useful for throttling outbound API requests, user-facing actions, or any operation where you need to allow occasional bursts without exceeding a sustained rate.
6d 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.
Aug 19, 2026 0
JavaScript
Queue (Async Task Queue)
A serialised async task queue that executes queued async functions one at a time, in order. Useful for sequencing operations that must not run concurrently (file writes, ordered API mutations, step-by-step wizards). add() returns a Promise that resolves/rejects when that specific task completes.
Aug 19, 2026 0
Python
Protocol — Structural (Duck) Typing
Define what an object can DO, not what it IS. A class doesn't need to inherit from a Protocol — it just needs to match the shape. Like TypeScript interfaces with `implements` optional.
Aug 18, 2026 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.
Aug 18, 2026 0
Java
ExecutorService — Thread Pools
`ExecutorService` is the modern way to manage threads. Submit Callables/Runnables, get Futures back. Always shutdown the executor — and prefer try-with-resources on Java 19+ where ExecutorService is AutoCloseable.
Aug 18, 2026 0
HTML
Iframe with Sandbox + lazy loading
Embed third-party content (YouTube, Stripe, maps) safely. `sandbox` restricts what the embedded page can do. `loading="lazy"` defers offscreen iframes — huge perf win for blog posts with multiple embeds.
Aug 18, 2026 0
JavaScript
Scroll to Element Smoothly
Scrolls the page to a target element with an optional pixel offset (useful when a fixed header is present). Uses the native scrollIntoView with smooth behaviour when supported, and falls back to a manual scrollTo with a configurable offset. Pass a CSS selector string or an Element reference.
Aug 17, 2026 0
JavaScript
Create Element Helper
A concise helper for creating DOM elements with attributes, properties, styles, event listeners, and children in one call — similar to hyperscript or JSX without a build step. Eliminates repetitive createElement / setAttribute / appendChild chains and keeps DOM construction code readable.
Aug 17, 2026 0
JavaScript
Parse URL Query String
Parses a URL query string into a plain key-value object. Uses the built-in URLSearchParams API — no regex required. Handles duplicate keys (returns the first value), percent-encoded characters, and works with both full URLs and raw query strings. Pairs nicely with buildQueryString.
Aug 17, 2026 0
JavaScript
Range Generator
Generates an array of numbers from start to end (inclusive) with an optional step. Supports negative steps for counting down. Covers the most common use case of Array.from({ length: n }, (_, i) => i) with a much cleaner API, and handles arbitrary start/end/step combinations.
Aug 17, 2026 0
JavaScript
Async Sleep / Delay
Returns a Promise that resolves after a given number of milliseconds. Use with await to pause async functions without blocking the main thread. More readable than nested setTimeout callbacks and composable with other async utilities.
Aug 11, 2026 0
JavaScript
Group Array by Key
Groups an array of objects into a map keyed by the result of a callback or property name. Uses Object.groupBy when available (ES2024) and falls back to a reduce implementation. Returns an object whose keys are the group names and values are arrays of matching items.
Aug 11, 2026 0
Kotlin
Extension Functions
Add methods to ANY type — including stdlib types like String, List, or Int — without subclassing. Compiled as a static dispatched function, so no runtime overhead.
Aug 11, 2026 0
Java
Switch Expressions (Java 14+)
`switch` is now also an expression — it returns a value. Use `->` arrows for fall-through-free arms; `yield` inside `{ }` blocks for multi-statement arms. No more accidental forgotten `break`.
Aug 11, 2026 0
Kotlin
Extension Properties
Like extension functions, but as a property. Must have a custom getter (and optionally a setter) since extensions can't have backing fields. Reads like a real property at the call site.
Aug 11, 2026 0