Dev Helpers

Developer journal

Articles

Worked examples, implementation notes and small experiments across ten developer topics.

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.

Get the last day of a month

Day zero of the following month falls on the final day of the requested month. Date handles the year rollover for December.

Replace every occurrence

Replacing just the first delimiter leaves mixed formatting in an identifier. replaceAll makes the intended scope explicit.

Encode a Unicode JSON document

JSON text and transport bytes are separate representations. Encode the text as UTF-8 before measuring or sending a byte payload.

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.

Use quotient and remainder

A page number and offset are the quotient and remainder of the same division. divmod returns both from one operation.

Pad an identifier

Padding belongs to the display form of an identifier. Keeping IDs as strings preserves meaningful leading zeroes.

Check expected values with assertions

Assertions make assumptions visible in tests. Python can disable them in optimized execution, so required input validation deserves an explicit exception.

Fluid width with a maximum

A fluid container needs a small-screen width and a large-screen maximum. Outer gutters should remain visible at both extremes.

Square aspect ratio

A square ratio reserves equal sides even before media loads. Fit rules decide whether rectangular content is cropped or letterboxed.

Minimum inline size

A logical minimum inline size protects a component from collapsing beyond its usable width. An overly large minimum can force overflow.

Minimum block height

Minimum block size reserves space along the writing mode's block axis. Content can still make the element grow.

Tailwind CSS

All articles →

Selection background swatch

The selection variant lets a component specify its own selected-text colours. Readability depends on the selected foreground as well as the highlight.

Skew a label

A skew utility changes the painted shape without allocating extra room for the slanted edge. A separate inner wrapper can keep lettering upright.

Horizontal flex row

Flex utilities define the row but children can still resist shrinking. Inspect long labels before adding more breakpoints.

Perforated tear line

A perforated divider can use an arbitrary background value when a standard border lacks the desired spacing. Keep the pattern in one reusable class list.

Maximum reading width

A max-width utility constrains a reading column even when its parent occupies the whole viewport. Font size still determines how many characters fit.

Compare two literal lists

Set operations compare rows under SQL's rules for duplicates. Check whether the result represents membership or the number of occurrences.

Count jobs per active day

Grouping timestamps by day produces counts only for days present in the data. A continuous chart may need a calendar series as well.

Read the previous duration

LAG retrieves a prior row's value within an ordered window. The first row lacks a predecessor and usually needs its own display rule.

Match one character

A single-character wildcard expresses a different constraint from a variable-length wildcard. Decide whether punctuation in a search pattern is literal.

Alias a result column

An alias defines the name visible to query consumers. It can decouple an API field from a table's internal naming.

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.

Capture positional arguments

Process arguments include runtime and entry-point information before user arguments. Slice off those positions before interpreting input.

Detect an unhandled event name

An event name can exist without listeners at the point of inspection. Listener checks are snapshots of registration state.

Detect ASCII-only bytes

An ASCII check operates on bytes. A string that looks simple after display normalization may still require multibyte encoding.

Reject fractional cent amounts

A numeric type cannot by itself guarantee whole cents. Validate integrality where money enters the typed part of the application.

Infer route names from a registry

A route registry can drive both lookup and allowed route names. Type the keys from the registry so a removed route cannot survive in a separate union.

Infer a tuple element union

Indexing a tuple's type by number yields a union of its element types. Literal inference determines how precise that union becomes.

Create an object with a computed flag

A computed property name derives an object's key from a runtime value. Keep its allowed names narrow if downstream readers expect a fixed set.

Check for dangling dependency names

References between tasks can be well typed yet point to nonexistent names. Validate membership in the actual set of task IDs as a separate step.

UI Components

All articles →

Article byline

A byline combines authorship and dates without competing with the headline. Use a machine-readable time value alongside the visible date.

Audio episode transcript card

An episode transcript serves readers who cannot or prefer not to play audio. Identify speakers in text and keep the transcript easy to navigate.

Split editorial hero

A split editorial hero needs a deliberate reading order when columns collapse. Place essential copy where it remains intelligible without the accompanying image.

Inline success message

A success message works best beside the action that just completed. Keep it available long enough for someone navigating by keyboard to find it.

Quantity stepper input

A quantity stepper needs minimum and maximum behaviour as well as visible controls. Typed input and button input should converge on the same value.

Full-width section divider

A full-width divider can separate groups without becoming another heading. Consider whether the boundary is semantic or purely decorative.

Percentage meter

A percentage meter needs both a bounded visual fill and a meaningful textual value. Handle a zero denominator before dividing.

Vertical typesetting sample

Vertical typesetting changes the reading direction and available inline space. Treat the sample text as content so it remains selectable and accessible.

Square cover crop

A square image crop gives a card grid consistent geometry. The crop anchor determines whether the most important part of a photo survives.

Batch weight summary

Batch weight combines quantity and unit weight. Convert all measurements to the same unit before aggregating them.

Ordered milestone summary

An ordered milestone summary should preserve the sequence's meaning when names wrap. Use distinct labels for completed, current and upcoming work.

Billable increment rounding

Billing in increments requires a clear rounding policy. Derive the number of blocks before formatting a monetary amount.

Free bin volume

Free storage volume depends on consistent dimensions and units. Derive capacity and usage in the same unit before formatting a human-readable summary.

Draft preview indexing

Draft pages need deliberate indexing metadata. An indexing directive controls crawler intent, while access to unpublished material needs a separate permission check.

Party size allocation

Allocating a party into groups is an integer problem. The remainder determines whether another group is needed and how full it will be.

Locale preserving contact link

Localized links should retain the active language segment. Validate supported locales before inserting user-controlled segments into a destination.

Preferred unit label

Unit preferences might arrive from a cookie, query or default setting. Validate the chosen value before incorporating it into a label.

Bindery dispatch estimate

A dispatch estimate needs a clear starting date and handling-time rule. Disclose what happens on non-working days if the estimate is shown to customers.