Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
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.
HTML Semantic Article Structure
`<article>` for self-contained content (blog post, comment, news item). Each article gets its own header, body, and (optionally) footer. Helps screen readers, RSS, and Google understand structure.
Rust reqwest POST JSON
Send a JSON body by calling `.json(&value)` — serde handles serialization. Read the response body or status code afterwards.
Rust Threads with thread::spawn + join
Native OS threads with `std::thread::spawn`. The returned `JoinHandle` lets you wait for the thread and get its return value. Use `move` to transfer ownership of captured variables.
Bash Print Environment Variables Matching Pattern
Quick audit of env vars by prefix — useful when debugging containerized apps that read from `STRIPE_*`, `DB_*`, etc.
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.
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.
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.
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.
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.
Kotlin String Templates
Embed expressions inside double-quoted strings with `$var` or `${expr}`. No printf/format needed for 95% of cases. Raw strings (triple-quoted) skip escape processing for multiline / regex / SQL.
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.
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.
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.
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.
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.
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.
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.