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

Showing 721–750 of 770 public snippets

Python
SQLAlchemy 2.0 — Basic Select
The modern SQLAlchemy 2.0 style: typed Mapped[] columns, the new `select()` API, and Session.scalars() for clean row access. Replaces the legacy Query syntax.
1h ago 0
SQL
BETWEEN — Range Filtering
`BETWEEN a AND b` is inclusive on both ends. Cleaner than `col >= a AND col <= b`. For dates, watch for end-of-day vs midnight boundaries.
1h ago 0
HTML
Details / Summary — Native Accordion
`<details>` is the built-in "click to expand" widget. Free keyboard navigation, search-engine-indexable content (open or closed), no JS needed. Style with CSS to match your design.
1h ago 0
Go
strconv — String ↔ Number Conversions
`strconv.Atoi` / `Itoa` for the common int<->string case; `ParseFloat`, `ParseBool`, `Quote` for everything else. Always handle the error — strings can be anything.
1h ago 0
PHP
Highlight Search Term in Text
Wrap every case-insensitive occurrence of a search term in <mark> tags for quick visual highlighting in search results. Properly escapes HTML so user input cannot inject markup.
1h ago 0
TypeScript
isWithinInterval — Date Range Check
Inclusive check that a date falls between two boundaries. Tiny but constantly useful for filtering rows by date range, validating bookings, etc.
1h ago 0
TypeScript
const Assertions for Literal Types
`as const` freezes a value as deeply readonly and infers the narrowest possible literal types. Replaces enums for most use cases — better tree-shaking, no runtime cost.
1h ago 0
PHP
Start / End of Day, Week, Month
Snap a DateTime to the start (00:00:00) or end (23:59:59) of its day, week, or month. Builds on DateTimeImmutable for value-safety.
1h ago 0
PHP
Soft-Delete Pattern
Mark rows as deleted instead of removing them. A small helper class keeps the WHERE deleted_at IS NULL filter out of every query you write.
1h ago 0
HTML
Product Page with Schema.org Markup
Marking up a product page with the Schema.org `Product` type unlocks Google's rich snippets — price, rating, availability appear directly in search results. JSON-LD is the recommended format.
1h ago 0
Bash
Trim Whitespace from String
Strip leading and trailing whitespace without spawning sed or awk. Uses extglob + parameter expansion — much faster in tight loops than a subshell.
1h ago 0
Bash
Trap Signals for Cleanup
Use `trap` to delete temp files / kill background workers when the script exits — even on Ctrl-C or an unhandled error. Single most-undervalued bash feature.
1h ago 0
PHP
Parse Link Header for Pagination
Parse the standard HTTP Link header (RFC 5988) into a relation → URL map. Lets you follow rel="next" pagination in APIs like GitHub without manually building URLs.
1h ago 0
PHP
Cursor-Based Pagination
Cursor (keyset) pagination is faster than OFFSET on large tables — and immune to dupes/skips when rows shift. Pass the last seen ID and direction; get the next page.
1h ago 0
PHP
Send Plain Email via mail()
A thin wrapper around PHP's mail() with proper headers (From, Reply-To, Content-Type with UTF-8). For anything serious reach for PHPMailer or Symfony Mailer — this is fine for transactional one-offs.
1h ago 0
Go
strings.Builder — Efficient Concatenation
Building strings with `+` allocates O(n²) memory. `strings.Builder` writes to an internal buffer with a single final allocation — orders of magnitude faster in loops.
1h ago 0
Java
Jackson — Annotations (rename, ignore, etc)
Field-level annotations let you map between snake_case JSON and camelCase Java, skip nulls, never serialize secrets, set defaults on missing fields.
1h ago 0
Java
Singleton via enum
`enum` with a single value is the simplest correct singleton implementation: lazy, thread-safe, serialization-safe, reflection-safe. Joshua Bloch's recommendation in Effective Java.
1h ago 0
HTML
Time Element with datetime Attribute
`<time datetime="...">` lets you display a human-friendly date while giving machines an ISO-8601 timestamp. Used by browsers, Schema.org parsers, and screen readers.
1h ago 0
PHP
Format Duration in Seconds
Render a number of seconds as a human-friendly duration like "1h 23m 45s" — automatically trimming leading zero units. Handy for elapsed-time displays in dashboards.
1h ago 0
TypeScript
Date Range Generator
Yield each day (or step) between two dates as a Date object. Generator-based so consumers can `break` early without computing the whole range.
1h ago 0
Bash
Wait For Service With Timeout
Block until a TCP port accepts connections, with a deadline. Used everywhere in docker-compose entrypoints — wait for the DB to be ready before running the app.
1h ago 0
HTML
Open Graph + Twitter Card Tags
How your page renders when shared to Facebook, LinkedIn, Slack, Discord, X. Every public page needs these — they dramatically improve click-through on shares.
1h 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.
1h ago 0
Rust
mpsc Channel Between Threads
`std::sync::mpsc` is the standard cross-thread channel. Multiple producers, single consumer. Send any `Send` type; the receiver blocks on `recv()` until something arrives.
1h ago 0
Kotlin
Room — Android Database
Room is the official Android persistence library — annotation-driven, compile-time SQL verification, coroutine + Flow integration out of the box.
1h ago 0
Rust
tokio::spawn — Independent Tasks
`spawn` runs a future on the runtime as an independent task — fire-and-forget, or `.await` the returned `JoinHandle` to get its result. Equivalent to threads but multiplexed onto the worker pool.
1h ago 0
Kotlin
Enums with Properties and Methods
Kotlin enums can carry constructor properties and define methods — including abstract methods overridden per constant. Way more expressive than Java enums.
2h ago 0
Kotlin
groupBy and partition
`groupBy` returns a `Map<Key, List<T>>` keyed by what the lambda returns. `partition` is a special-case `groupBy` for booleans — returns `(matching, nonMatching)` Pair.
2h ago 0
Kotlin
Sequences — Lazy Collections
A `List` materializes every intermediate `map`/`filter` result. A `Sequence` processes ONE element through the whole pipeline at a time — better for big inputs or short-circuiting (`first`, `take`).
2h ago 0