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

Showing 691–720 of 770 public snippets

HTML
Visually Hidden Utility (.sr-only)
Hides content from sighted users but keeps it discoverable by screen readers. Use for icon-only buttons, table-row context, and form-status announcements that don't need visible text.
2h ago 0
Bash
Source Multiple Files from Directory
A common ~/.bashrc / ~/.zshrc pattern: split your config into ~/.bashrc.d/*.sh and source them all. Easier than one giant file.
2h ago 0
Bash
Sort an Array
Bash itself doesn't sort arrays — you pipe through `sort`. readarray captures the sorted output back into an array, preserving each element verbatim (including spaces).
2h ago 0
SQL
Gap Detection — Missing Days / Sequences
Find holes in a series — missing invoice numbers, days with no events, gaps in a sequence. Combine `LAG` (or `generate_series`) with a join to spot them.
2h ago 0
Python
Stdlib .env Loader (no dependency)
Parse a `.env` file into a dict and optionally export to os.environ. Skips comments and blank lines, strips surrounding quotes — no python-dotenv dependency needed.
2h ago 0
Go
slices package — Modern Helpers
`slices` (Go 1.21+) ships the iteration helpers everyone wrote by hand for years: Contains, Index, Sort, SortFunc, BinarySearch, Clone, Reverse, Equal, Max/Min.
2h ago 0
SQL
Pivot Without PIVOT (Conditional Aggregation)
Most databases don't have a real `PIVOT` keyword (SQL Server does). The portable answer is conditional aggregation — `SUM(CASE WHEN ...) AS col` for each pivoted value.
2h ago 0
Python
argparse with Subcommands
Standard-library CLI framework. Subcommands (like `git COMMAND`) require a sub-parser per command, each with its own arguments and handler.
2h ago 0
SQL
STRING_AGG / GROUP_CONCAT
Concatenate values across a group into a single delimited string. PostgreSQL/MSSQL use `STRING_AGG`; MySQL uses `GROUP_CONCAT`; SQLite has both.
2h ago 0
Go
maps package — Modern Helpers
`maps` (Go 1.21+) adds Keys, Values, Equal, Clone, Copy — replaces the slice-of-keys boilerplate you used to write to iterate a map deterministically.
2h ago 0
SQL
ROLLUP — Subtotals and Grand Totals
`GROUP BY ROLLUP` adds subtotal rows (with NULL for the rolled-up columns) plus a grand total. Drop into reports without writing UNIONs by hand.
2h ago 0
Java
Stream.reduce — Aggregate to a Single Value
`reduce` collapses a stream to one value: sum, product, max, min, custom accumulation. Two-arg form needs an identity (zero/seed); three-arg form supports parallel streams via a combiner.
2h ago 0
SQL
Window Function vs N+1 Query
Don't fetch a list, then loop in code to count each parent's children. Use a window function or a single GROUP BY — turn 1,001 queries into 1.
2h ago 0
HTML
Audio Element
`<audio>` is video's simpler sibling. Use it for podcasts, music samples, sound effects on play. Same multi-`<source>` pattern for cross-browser format support.
2h ago 0
SQL
SELECT DISTINCT and Counting Uniques
`DISTINCT` removes duplicate rows. Combine with `COUNT(DISTINCT col)` to count uniques in aggregations — different from `COUNT(*)`.
2h ago 0
Kotlin
Variance — in vs out
`out T` (covariant) → producer of T; can be assigned to a wider type. `in T` (contravariant) → consumer of T; can be assigned to a narrower type. Without modifiers, generics are invariant (strict match).
2h ago 0
SQL
Sessionization — Group Events into Sessions
Stitch a stream of events into "sessions" where events more than N minutes apart start a new session. Uses LAG + a SUM-OVER trick to assign session IDs.
2h ago 0
SQL
Cohort Retention Analysis
Group users by their signup week, then count how many were still active in each subsequent week. The classic SaaS retention table — entirely in SQL.
2h ago 0
Bash
Idempotent Append to File
Add a line to a file (e.g., a config or PATH export) only if it isn't already present. Common in install/setup scripts that need to be safe to re-run.
2h ago 0
SQL
LAG / LEAD — Previous and Next Row
Access the row before (`LAG`) or after (`LEAD`) the current one, in the window's order. Perfect for "delta from previous reading", session boundaries, etc.
2h ago 0
Kotlin
Generic Class and Function
`<T>` declares a type parameter. Use it on classes (`Box<T>`) and functions (`fun <T> identity(x: T) = x`). Type bounds (`T : Comparable<T>`) constrain what T can be.
2h ago 0
SQL
FIRST_VALUE / LAST_VALUE
Return the first or last value within a window. Useful for "compare each row to the partition's first/last value" — for example, "how much have we grown since the user's first order?"
2h ago 0
SQL
Moving Average (Window Frame)
Add a frame clause (`ROWS BETWEEN N PRECEDING AND CURRENT ROW`) to compute moving averages, sliding sums, rolling stats — anything that needs a bounded look-back.
2h ago 0
Go
os.Getenv with Defaults
`os.Getenv` returns "" when unset — easy to miss. Wrap it with a typed helper that supplies defaults and parses numerics. Saves boilerplate at every config-read site.
2h ago 0
Kotlin
Pair, Triple, and to() Infix
`Pair<A,B>` and `Triple<A,B,C>` are stdlib lightweight tuples. The `to` infix returns a Pair — used everywhere for map literals.
2h ago 0
SQL
NTILE — Bucket Rows into N Buckets
Assign rows to N approximately-equal-sized buckets based on the ORDER BY. The standard way to compute quartiles, deciles, or any percentile bucket.
2h ago 0
Java
Stream Basics — filter / map / collect
The fluent pipeline for transforming collections. `filter` keeps matching elements, `map` transforms each one, `collect(toList())` materializes the result.
2h ago 0
SQL
Running Totals (SUM OVER)
Window aggregates with an implicit "rows up to here" frame give you running totals, cumulative counts, and ratchet-up metrics. No self-join needed.
2h ago 0
Kotlin
require / check / requireNotNull
Three contract-style assertions in the stdlib: `require` for inputs (throws `IllegalArgumentException`), `check` for state (throws `IllegalStateException`), `requireNotNull` returns the value smart-cast.
2h 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.
2h ago 0