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

Showing 151–180 of 770 public snippets

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.
5m 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.
6m ago 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.
6m 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.
6m ago 0
PHP
Discord Webhook Notification
Same idea as Slack but for Discord webhooks — supports rich embeds with a title, description, and color. Useful for dev/ops dashboards or bot integrations.
6m ago 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.
6m 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.
6m ago 0
Bash
Confirm Prompt (y/n)
A reusable yes/no prompt with a configurable default and a single-keystroke read. Returns 0 for yes, non-zero for no.
6m ago 0
Bash
List Authors by Commit Count
Quick repo stats: who has done what. Add --no-merges if you don't want to count merge commits.
6m ago 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.
6m ago 0
Rust
if let / while let
When you only care about one variant, `if let` is shorter than `match`. `while let` keeps looping as long as the pattern matches — great for draining iterators or option-returning APIs.
7m ago 0
Bash
Uppercase / Lowercase / Title Case
Bash 4+ has built-in case conversion via parameter expansion. No need for `tr` or `awk` for most cases.
7m ago 0
Bash
Reset Branch to Match Remote
Throw away local commits and resync to origin. Destructive — make sure no local work is at risk first.
7m ago 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.
7m ago 0
Bash
Run Command with Timeout
`timeout` (GNU coreutils) kills a command after N seconds. Returns exit code 124 on timeout — let the caller distinguish "timed out" from "failed for other reasons."
7m ago 0
PHP
Pluck Column From Array of Rows
Extract a single column from a list of associative arrays into a flat list. Common transformation for SELECT results — equivalent to array_column with optional indexing key.
7m 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.
7m ago 0
Python
pathlib Quick Reference
Forget os.path.* — pathlib.Path is the modern, OS-aware way to work with paths. Operator overloading for joins, attribute access for components, methods for reads/writes/iterations.
7m ago 0
PHP
Word Count (UTF-8 aware)
Count words in a string in a way that works for any Unicode script — including those without ASCII whitespace. Built on the \p{L}\p{N} Unicode regex categories.
7m ago 0
Bash
Stash With a Message
`git stash` without args is hard to grep through later. Always pass a message — your future self will thank you.
7m 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.
7m ago 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.
7m ago 0
Go
rate.Limiter — Token-Bucket Rate Limiting
`golang.org/x/time/rate` provides a battle-tested token-bucket limiter. Use to enforce "N requests per second with bursts up to B" — for per-IP throttling, external API rate limits, etc.
7m ago 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.
7m 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.
7m 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.
7m 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.
8m ago 0
JavaScript
Simple State Machine
A lightweight finite state machine that defines valid states and allowed transitions between them. Attempting an invalid transition throws an error. Supports entry/exit hooks per state for side effects. Useful for modelling UI flows (idle → loading → success/error), auth states, and multi-step forms.
9m 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.
9m 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.
9m ago 0