Writing
I write short notes on tools and habits that help with day-to-day engineering.
2025
- Handle money in JS with integer centsStore prices as integer cents so totals add without the 0.1 + 0.2 drift, and format with Intl.NumberFormat only for display.
- Escape HTML with a tagged templateWrite a tagged template that escapes HTML text, joins arrays and accepts markup from trusted strings.
- Predict console.log order: microtasks before timersPredict the output of a short script by following synchronous code, the microtask queue and a zero-delay timer.
- Template literal types for typed route stringsDerive parameters from a literal route so TypeScript catches missing or misspelled keys at the call site.
- Omit a property from each union memberUse a distributive conditional type to omit a shared property and preserve narrowing on the resulting union.
- Reduce layout shift when fonts swapMatch a local fallback to your web font to reduce layout shift during font swaps.
- Use logical properties for RTL layoutsUse logical CSS properties for spacing and offsets that should follow the reading direction.
- Replace the padding-top hack with aspect-ratioGive a responsive iframe a 16:9 aspect ratio without a percentage-padding wrapper.
- Schedule repo upkeep with git maintenanceRegister a clone with git maintenance, run a named task such as prefetch by hand, and see what git maintenance start needs from the system.
- Inspect merge conflict fixes with --remerge-diffgit show --remerge-diff redoes a merge and diffs it against the commit, so conflict fixes and extra edits made while resolving become readable.
- Build fluid typography with clamp()Pick two viewport widths and two font sizes, work out the vw slope and rem intercept by hand, and clamp() holds the size between them.
- A localStorage hook with useSyncExternalStoreUse useSyncExternalStore to share a localStorage value across components and render a fallback on the server.
- Pick the right Testing Library queryUse accessible roles and names to query React components and diagnose a mismatch from Testing Library's error.
- Why Object.keys returns string[]See why Object.keys returns string[] and use an explicit list of typed keys to index a known set of properties.
- Never lazy-load your LCP imageFind the image that drives Largest Contentful Paint and measure how eager loading changes its request timing.
- Add a retry button to an error boundaryA React error boundary stays on its fallback until you reset it. Add a reset method that clears the error state and re-renders the children.
- Keep the original error with causePass the caught error as cause when you rethrow so Node can show the original failure alongside your message.
- Reuse conflict resolutions with git rerereEnable git rerere to reuse a conflict resolution the next time Git recognizes the same conflict.
- structuredClone vs JSON copy: what breaksCompare what JSON copying and structuredClone do with dates, collections, cycles, functions and class instances.
- Try a CSS fix with DevTools overridesUse Chrome DevTools Local Overrides to test a stylesheet change in your browser before deploying it.