SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
751–770
of
770
public snippets
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.
Jun 16, 2026
0
Kotlin
Data Classes — Records Done Right
`data class` auto-generates `equals`, `hashCode`, `toString`, `copy`, and `componentN` (destructuring). Replaces boilerplate POJOs / Records / classes-with-lombok in one line.
Jun 16, 2026
0
Bash
Substring + Find/Replace (parameter expansion)
Bash's ${var:offset:length} and ${var//pattern/replacement} let you do most string operations without ever spawning sed. Faster, and the syntax is portable across modern shells.
Jun 16, 2026
0
Go
net/url — Build Query Strings Safely
Stop concatenating `?a=1&b=2` by hand. `url.Values` (a `map[string][]string`) escapes correctly, handles repeated keys, and `url.URL.String()` renders the canonical form.
Jun 16, 2026
0
PHP
Atomic Counter with flock
A single-file counter that survives concurrent increments correctly using flock + read-modify-write inside the locked region. Useful for crude visitor or job-id counters when you don't want a DB.
Jun 16, 2026
0
Kotlin
Sealed Classes — Closed Type Hierarchies
`sealed` restricts subclassing to the same module. Combined with exhaustive `when`, the compiler enforces handling of every variant — refactor-friendly state machines.
Jun 16, 2026
0
Java
Records — Concise Data Classes (Java 16+)
`record` generates a constructor, accessors, `equals`, `hashCode`, and `toString` from a one-line declaration. Replaces 50 lines of POJO boilerplate. Records are implicitly final and immutable.
Jun 15, 2026
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.
Jun 15, 2026
0
Go
flag — Stdlib CLI Parser
The `flag` package is the minimal-dep CLI parser shipped with Go. Sufficient for many tools; reach for `spf13/cobra` or `urfave/cli` for subcommands and richer UX.
Jun 15, 2026
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.
Jun 15, 2026
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.
Jun 15, 2026
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.
Jun 15, 2026
0
PHP
UTF-8 Safe substr / strlen
Wrap mb_* with sensible defaults so you stop accidentally chopping multi-byte characters in half. Defensive helpers for projects where input is not guaranteed ASCII.
Jun 15, 2026
0
JavaScript
UUID v4 Generator
Generates a RFC 4122 compliant version-4 UUID. Uses crypto.randomUUID() in modern environments (Node 14.17+, all modern browsers) and falls back to a Math.random()-based implementation for older runtimes. The fallback is suitable for non-security-critical IDs such as UI element keys and local correlation IDs.
Jun 15, 2026
0
SQL
INNER JOIN — Match Rows in Both Tables
Returns rows where the join condition matches in BOTH tables. The default JOIN. Use table aliases (`u`, `o`) for readability when joining 3+ tables.
Jun 15, 2026
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.
Jun 15, 2026
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.
Jun 14, 2026
0
Bash
Default Value for Unset Variable
Three parameter-expansion idioms for "use this if the variable is empty / unset". Replaces the verbose `if [[ -z "$VAR" ]]; then VAR=default; fi` everywhere.
Jun 14, 2026
0
SQL
NULLS FIRST / NULLS LAST
Control where NULLs land in an `ORDER BY`. PostgreSQL/Oracle default NULLs to LAST in ASC, FIRST in DESC; MySQL/SQL Server flip it. Be explicit if it matters.
Jun 14, 2026
0
Go
Prepared Statement Reuse
For repeated queries (loops, bulk inserts), prepare once and re-use. The driver caches the parsed query and saves a round trip per invocation.
Jun 13, 2026
0
1
…
24
25
26