Copy-to-clipboard button with Stimulus

Copy buttons are everywhere (invite links, API keys, CLI commands). With Stimulus, I keep it tiny and resilient: use navigator.clipboard.writeText when available, and fall back to selecting a hidden input for older browsers. I also provide immediate f

Result and ? operator for clean error propagation

Rust's Result<T, E> forces you to handle errors explicitly, but the ? operator makes it ergonomic. When a function returns Result, using ? automatically returns early with the error if it's Err, or unwraps the value if it's Ok. This replaces ver

SwiftUI custom shapes and paths

Custom shapes enable unique UI designs beyond standard views. Conforming to Shape protocol requires implementing path(in:) that returns a Path describing the geometry. I use path methods like move(to:), addLine(to:), addArc(), and addCurve() to draw c

Redis caching for expensive computations

Redis provides a fast, in-memory cache for expensive computations that don't change frequently. I use Rails.cache with the Redis store to cache things like trending posts calculations, aggregated statistics, or external API responses. The fetch method

SwiftUI GeometryReader for dynamic layouts

GeometryReader provides parent view size and coordinates, enabling dynamic layouts that adapt to available space. The reader passes a GeometryProxy with size and coordinate space info. I use it for responsive designs—calculate grid columns based on wi

A reusable respond_to block for turbo_stream + html

Once you’ve built a few Hotwire controllers, you notice the same respond_to shape repeated. I extract a small helper (a concern) that yields a respond_to block and centralizes the “default HTML redirect” pattern. This keeps controllers readable and re

Django logging configuration for production

Proper logging is critical for production debugging. I configure loggers for different apps and libraries. I use file handlers for persistence and console handlers for development. Log rotation prevents disk fill-up. I set appropriate levels (DEBUG, I

Audit logging for sensitive operations

Audit logs provide accountability and forensic capabilities for sensitive operations like permission changes, data deletion, or financial transactions. I store audit events in a dedicated table with who performed the action, what changed, when it occu

Background job retry strategies

Not all background job failures should be retried the same way. Transient failures like network timeouts benefit from exponential backoff, but bugs in code or invalid data should fail immediately after a few attempts. Sidekiq provides retry configurat

Notifications dropdown that live-updates with Turbo Streams

For a notifications dropdown, I keep the list server-rendered and let Turbo Streams keep it fresh. The dropdown content sits in a turbo_frame_tag (so you can also navigate to a full notifications page), and the unread badge is a separate small target

Django middleware for request ID tracking

Adding unique request IDs helps trace logs across distributed systems. I generate a UUID for each request and attach it to both the request object and response headers. I also add it to the logging context so all log entries for that request include t

JWT authentication with refresh tokens

Stateless authentication with JWT tokens simplifies horizontal scaling but introduces security concerns around token lifetime and revocation. I use short-lived access tokens (15 minutes) combined with longer-lived refresh tokens stored in an encrypted