~/writing

Luiz Kowalski :: dev blog

Notes on Ruby, Rails, infrastructure, and the small choices that make code easier to change.

#6fce33Double-click to submit form pattern with Stimulus (revisited)A follow-up on the double-click-to-confirm button component, now rebuilt as a ViewComponent with a Stimulus sidecar controller. Shows how overlapping text with CSS grid keeps the button width stable during the confirm animation, plus a caveat about long confirmation strings.#3adf1e"Double-click to submit" pattern with StimulusInspired by a confirm-by-double-clicking pattern seen in CasaOS, this post recreates it with a small Stimulus controller. It swaps the button text on first click and submits on the second, then adds stimulus-use's clickOutside to cancel the pending confirmation.#a12281Traefik with Kamal: Tips and TricksClears up a common Traefik misconception: you don't need new entrypoints to expose extra services like Grafana on a subdomain, just new routers and services. Walks through enabling the internal API dashboard and the routing rules that connect a Host rule to a Docker service.#44f1c1Production-Grade (ish) Rails deployment on Hetzner with KamalA two-server Kamal deployment on Hetzner: one exposed web server, one locked-down accessories server for Postgres, Redis, and backups, reachable only via SSH jump host. Covers the Terraform setup for provisioning, splitting background jobs by priority, and configuring Traefik for automatic SSL.#a08a9fTaming complex Service Objects with dry-rbUses dry-validation to turn a Service Object's loose params hash into an explicit, self-documenting contract with typed, required/optional fields and business rules. Also covers custom dry-types, coercion, and how this compares to Sorbet.#4f8a11Using concurrent-ruby in a Rails applicationExplains how the GVL still allows I/O-bound work to run in parallel via concurrent-ruby's Future, and how to safely combine it with Rails' Executor. Covers wrapping threads in executor.wrap and using permit_concurrent_loads to avoid autoloading deadlocks.#3e0608Validating Mandrill webhook signature on Ruby on RailsHow to verify Mandrill's X-Mandrill-Signature header in a Rails controller by HMAC-SHA1 signing the webhook URL and raw POST params. The key gotcha: you must use request.request_parameters, not Rails' parsed params, since Mandrill signs the raw mandrill_events string.#36ec95Encapsulation in Ruby on RailsArgues that ActiveRecord getters/setters aren't real encapsulation, since callers still need to know about an object's internal fields to mutate it. Proposes using DDD's Aggregate pattern so that all state changes happen through the owning model instead of leaking into other classes.#5504bdA simple solution to scalability problems: Event SourcingBuilding an Untappd clone in Kotlin and Spring to explore event sourcing and CQRS. Covers organizing code into independent domains connected only through events, dispatching events via AbstractAggregateRoot, and the eventual-consistency trade-offs that come with async listeners.#9d3bc6Deploying Spring Cloud Netflix apps on KubernetesA walkthrough of deploying a Eureka server, a Hystrix dashboard with Turbine, and a microservice to a Kubernetes cluster. Covers Dockerizing each Spring Cloud Netflix component, exposing them with kubectl, and verifying the circuit breaker under load with siege.