More in Web & CSS
A semantic, accessible form field
Web & CSS
The label is tied to the input by id, and the hint is announced with it via aria-describedby.
Visually hidden, still read aloud
Web & CSS
Hides a label from sight while leaving it in the accessibility tree. display:none would remove it from both.
Responsive grid without media queries
Web & CSS
auto-fill with minmax reflows on its own, so the column count follows the container rather than a breakpoint list.
Centre a box, two ways
Web & CSS
Grid is one line. Flex is three and gives you control over the axes separately.
Respect a reduced-motion preference
Web & CSS
One rule that disables animation for people who asked their system for less of it.
Responsive images that do not blow the bandwidth budget
Web & CSS
srcset lets the browser pick; sizes tells it how wide the image will actually be rendered.
Random picks
Read a file into a string in Go
Systems
os.ReadFile replaced ioutil.ReadFile in 1.16 and is the one-liner for small files.
Context with a timeout in Go
Systems
Cancels the request and everything downstream of it after two seconds. The defer is not optional.
Count lines of code by extension
Shell
A quick census of a repository without installing a tool for it.
Hash and verify a password in PHP
PHP
password_hash picks the algorithm and the salt. Never store anything a hash function can reverse.
Escape output in a PHP template
PHP
htmlspecialchars with the flags spelled out, because the defaults have changed between versions.
Retry with exponential backoff and jitter
Python
Backs off on each failure and spreads retries out, so a recovering service is not hit by every client at once.
Generate a strong random secret
Security
For session keys and tokens. Never reach for a password generator or a UUID for this.
Security headers for an Express app
Security
The handful worth setting even when you are not using a framework that sets them for you.