SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
721–750
of
770
public snippets
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.
2h ago
0
Bash
Watch a File for Changes (no inotify dep)
inotifywait is great when available, but on systems without inotify-tools you can poll mtime. Cheap enough to use in dev/CI workflows.
2h ago
0
HTML
Favicon Set (SVG + PNG fallbacks)
Modern favicon setup: one SVG that scales, an ICO fallback for old browsers, and an apple-touch-icon for iOS home screens. Skip the 12-file <link> dump from favicon generators of yore.
2h ago
0
Go
Static File Server
`http.FileServer` serves a directory; combine with `http.StripPrefix` to mount it at a URL path. One line for the most common static-asset use case.
2h ago
0
Java
ReentrantLock — Beyond synchronized
`ReentrantLock` does what `synchronized` does, plus: tryLock with timeout, fair queueing, interruptible acquire, multiple condition variables. Use when synchronized's rigidity bites.
2h ago
0
Rust
Atomic Counter (lock-free)
For shared counters and flags, `AtomicU64` / `AtomicBool` etc. are much faster than `Mutex`. Operations like `fetch_add` are single CPU instructions on most architectures.
2h ago
0
Kotlin
observable — Listen for Property Changes
`Delegates.observable(initial) { prop, old, new -> ... }` fires a callback every time the property changes. Useful for state-tracking, simple observability without a full reactive lib.
2h ago
0
Go
sync/atomic — Lock-Free Counter
For simple counters and flags, atomic ops are much faster than `sync.Mutex`. Go 1.19+ added typed wrappers (`atomic.Int64`) — clearer than the raw functions.
2h ago
0
Bash
Backup File With Timestamp
Keep a versioned copy of a config or log before modifying it. Avoid `cp file file.bak` which overwrites old backups; use a date-stamped name.
2h ago
0
SQL
Indexes — B-tree, Partial, Composite
Indexes are the difference between a 50ms query and a 50s one. Composite indexes match queries that filter / sort on the columns in order; partial indexes skip irrelevant rows for big space savings.
2h ago
0
Bash
Read Single Keystroke Without Enter
For menus and confirm prompts where you want one-key response (no need to press Enter). -n 1 reads exactly one character, -s silences the echo.
2h ago
0
Bash
Safe Bash Script Template
Start every script with the same skeleton: strict error mode (errexit, nounset, pipefail), an IFS reset, and a main() function. Catches silent failures that have lost engineers weeks of debugging.
2h ago
0
PHP
Measure Code Block Execution Time
Time a closure with microsecond precision and return both its result and the elapsed milliseconds. Great for quick perf experiments without pulling in a profiler.
2h ago
0
SQL
IS DISTINCT FROM — Null-Safe Equality
`=` returns NULL when either side is NULL. `IS DISTINCT FROM` (and its inverse `IS NOT DISTINCT FROM`) treat NULLs as equal to themselves — the right tool for change detection.
2h ago
0
Bash
Split String into Array on Delimiter
Use IFS + read or readarray to split safely. Don't use word-splitting tricks — they break on edge cases (empty fields, spaces in values).
2h ago
0
Bash
Pad String to Fixed Width
Pad strings left or right so columnar output lines up. printf gets you about 95% of what you need; the helpers wrap it for readability.
2h ago
0
Bash
Disk Space Alert
Cron-friendly script that checks disk usage on each filesystem and emails (or webhooks) if any partition exceeds a threshold.
2h ago
0
Bash
Print Environment Variables Matching Pattern
Quick audit of env vars by prefix — useful when debugging containerized apps that read from `STRIPE_*`, `DB_*`, etc.
2h ago
0
Bash
Tar Archive with Timestamp
Pack up a directory with a date-stamped filename for easy backups. -z for gzip, -j for bzip2, -J for xz (smallest, slowest).
2h ago
0
Bash
Print a Boxed Banner
Wrap a string in a Unicode box for important headers. Auto-sizes to the longest line. Helps milestone messages stand out in long CI logs.
2h ago
0
PHP
Dump Variable to Browser (var_dump replacement)
A nicer var_dump-style dumper that wraps output in <pre> with monospaced font for browser inspection. Drop-in replacement for var_dump while debugging.
2h ago
0
Kotlin
Property Delegation by Map
Delegate a property to a `Map<String, V>` — reading the property fetches by name; writing stores by name. Quick way to back a class with a config map.
2h ago
0
TypeScript
Template Tag for Safe HTML
Build HTML strings with a tagged template literal that auto-escapes every interpolated value. Eliminates a class of XSS bugs without pulling in a templating library.
2h ago
0
Rust
Custom Display + Debug Implementation
`Debug` (for `{:?}`) is usually derived. `Display` (for `{}`) is hand-written and goes through the same `std::fmt::Formatter` API.
2h 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).
2h ago
0
Bash
OS / Distro Detection
Read /etc/os-release for distro info — it's the standard on every modern Linux. Branch deploy scripts on distro to pick apt vs. dnf vs. apk.
2h ago
0
Bash
Detect Whether Running as Root
Several scripts must run as root (or refuse to). EUID is more reliable than `whoami == root` because sudo without -E may change one but not the other.
2h ago
0
SQL
CREATE TABLE with Constraints
Declare data integrity rules right in the schema — primary keys, foreign keys, unique constraints, NOT NULL, CHECK constraints, defaults. The DB enforces them so application bugs can't corrupt your data.
2h ago
0
SQL
RANK / DENSE_RANK
`RANK` leaves gaps after ties (1, 2, 2, 4); `DENSE_RANK` doesn't (1, 2, 2, 3). `ROW_NUMBER` is always unique. Pick by what tied rows should produce.
2h ago
0
TypeScript
Generic Constraints with `extends`
Generics start unbounded — you can't access any properties of `T`. `T extends { … }` adds a constraint so the body can safely use known shape, while callers can still pass in narrower types.
2h ago
0
1
…
23
24
25
26