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

Showing 331–360 of 770 public snippets

HTML
Comment / Review Markup with Schema
Comments and reviews can also have Schema.org markup. The `Review` type appears under products in Google search results with star ratings; `Comment` is for general user feedback.
1h ago 0
Bash
Find Largest Files and Directories
Quick "where did all my disk go?" answer. du sorts by size, ncdu (interactive) is better for exploration.
1h ago 0
Rust
Arc<Mutex<T>> — Shared Mutable State
Share mutable data across threads: `Arc` for the shared ownership, `Mutex` for the synchronized access. Lock with `.lock().unwrap()`; the guard drops the lock on scope exit.
1h 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).
1h ago 0
Java
Immutable Collections — List.of / Map.of
Java 9+ static factory methods return immutable collections with no nulls allowed. Concise, fast, and safer to share across threads or APIs than mutable equivalents.
1h ago 0
PHP
URL-Safe Base64 Encode / Decode
Standard base64 uses + and / which break in URLs. Swap them for - and _, drop the = padding, and you get a string you can put in path segments and query parameters safely.
1h ago 0
Python
Literal + match for Exhaustive Switching
`Literal` pins a value to specific strings/ints. Combine with the match statement (Python 3.10+) and a `_ : assert_never` clause for exhaustiveness — every variant must be handled or mypy yells at you.
1h ago 0
Kotlin
Compose Layout: Column, Row, Box
Compose's three fundamental layouts. `Column` stacks vertically, `Row` horizontally, `Box` overlays. Combine with `Modifier.weight()`, alignment, and arrangement for flexible UIs.
1h ago 0
Go
time.Since — Easy Benchmark Timing
`time.Since(start)` is shorthand for `time.Now().Sub(start)`. Pair with `defer` for a quick "how long did this function take?" measurement.
1h ago 0
SQL
Generated / Computed Columns
A column whose value is derived from other columns and maintained automatically. PostgreSQL has STORED (persisted) and MySQL adds VIRTUAL (computed on read). Saves you from triggers for derived data.
1h 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.
1h ago 0
SQL
UUID Primary Keys
UUIDs as PKs avoid sequence contention across services and let clients generate IDs offline. v4 is random (worst for B-tree indexes); v7 is time-ordered (B-tree friendly).
1h ago 0
Bash
Show Current Branch in Prompt
Append the git branch to your bash prompt. Survives non-git dirs gracefully (just shows nothing). Drop into ~/.bashrc.
1h ago 0
TypeScript
useLocalStorage — Synced State
A useState replacement that persists to localStorage and syncs across tabs via the `storage` event. Strongly typed via the initial value's type.
1h ago 0
HTML
Preload + Preconnect for Critical Resources
`<link rel="preload">` fetches a critical asset early (fonts, hero image, above-fold CSS). `preconnect` opens the TCP+TLS handshake to a third-party origin you'll need soon. Both cut perceived load time.
1h ago 0
Bash
PID File Management
Write a daemon's PID to a file at start, check on subsequent runs, clean up on exit. Avoids two copies of the same daemon when the script is invoked twice.
1h 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.
1h ago 0
JavaScript
Long Polling Helper
Implements a long-polling loop that repeatedly calls a fetch endpoint and invokes a callback with the result. Backs off exponentially on errors and stops cleanly when cancelled via the returned stop function. A simple alternative to WebSockets for low-frequency server-push events without SSE support.
1h ago 0
Kotlin
Custom Property Delegate
Any object with `getValue` / `setValue` operator methods can serve as a delegate. Lets you encapsulate cross-cutting behavior (logging, persistence, validation).
1h ago 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.
1h ago 0
Bash
Parse --flag=value Arguments
A getopts-free arg parser handling long flags, equals-separated values, and bundled short flags. Customize as needed.
1h ago 0
JavaScript
Intersection Observer (Lazy Load / Reveal)
Uses the IntersectionObserver API to trigger a callback when elements enter the viewport. The reveal pattern adds a visible class to animate elements as they scroll into view. The lazyLoad pattern loads images on demand by swapping data-src to src. Much more performant than scroll event listeners.
1h ago 0
Go
Channels — Basics
Channels are typed pipes between goroutines. Unbuffered = synchronous handoff; buffered = up to N values queued. Close a channel to signal "no more values" — receivers see ok=false.
1h ago 0
JavaScript
Animate Counter (Number Roll-Up)
Smoothly animates a number from a start value to an end value over a given duration using requestAnimationFrame. Supports a custom easing function (defaults to ease-out quad). Ideal for dashboard stat widgets, donation counters, and any UI where a bare static number would be less impactful.
1h ago 0
Kotlin
Type Aliases
`typealias` gives a shorter / more meaningful name to an existing type. Compile-time only — no new type, no overhead. Great for taming verbose function types or generic parameters.
1h ago 0
Rust
Custom Iterator Implementation
Implementing `Iterator` is just supplying a `next() -> Option<Item>`. You automatically gain `map`, `filter`, `collect`, and every other adapter for free.
1h ago 0
Kotlin
Immutable vs Mutable Collections
`listOf` / `setOf` / `mapOf` build READ-ONLY views; `mutableListOf` / `mutableSetOf` / `mutableMapOf` are mutable. Default to immutable — the call site is a contract about intent.
1h ago 0
Python
asyncio.gather with Errors Tolerated
`gather(*tasks)` cancels everything on the first failure — usually NOT what you want. `return_exceptions=True` lets every task finish, returning the exception in place of a result. Perfect for fan-out HTTP fetches.
1h ago 0
SQL
ARRAY_AGG and JSON_AGG (PostgreSQL)
Roll up grouped rows into a PostgreSQL array or JSON array — often a faster replacement for the application doing the same "group children under parent" join.
1h ago 0
JavaScript
Slugify String
Converts any string into a URL-safe slug: lowercases it, replaces accented characters with ASCII equivalents, strips all non-alphanumeric characters (except hyphens), and collapses multiple hyphens into one. Ideal for generating URL slugs from blog titles, product names, or user input.
1h ago 0