High-level data types with "composed_of"
Rails composed_of bundles several columns into one value object, but immutability, validation, caching, and form handling remain fragile.
How to allow testing beforeunload confirmation dialogs with modern ChromeDrivers
ChromeDriver 127 closes beforeunload prompts immediately in HTTP sessions; BiDi mode with unhandled_prompt_behavior: { default: 'ignore' } keeps them open for automated tests.
Optimizing images for the web
Fast webpages need smaller image files without visible quality loss; resizing, stripping metadata, and using formats like WebP can greatly reduce size.
Don't require files in random order
File loading order from Dir.glob can vary by file system and break code that depends on load sequence. Sorting the matched paths or using sort: false in Ruby 3 makes it predictable.
Git: How to configure git to push only your current branch
Prevent accidental multi-branch pushes by setting push.default to current; it pushes only the checked-out branch, but new remote branches may need tracking setup.
Rails: How to stub the env in Rails 7+
Rails 7.1 adds Rails.env.local?; stubbing Rails.env with a plain string can fail, while ActiveSupport::EnvironmentInquirer keeps environment checks working.
esbuild: Compressing JavaScript harder with Terser
Terser can shrink JavaScript bundles further than esbuild's minifier, at the cost of noticeably longer build times.
A simple example with a GIN index in Rails for optimizing a ILIKE query
ILIKE searches in PostgreSQL can be slow without trigram indexing; a GIN index with pg_trgm can replace sequential scans with bitmap index scans.
Logging multiple lines in Rails without making filtering your logs difficult
Multi-line Rails logs are hard to filter because only the first line gets tagged. Logging each line separately keeps request IDs and timestamps on every line.
How to: Benchmark an Active Record query with a Ruby script
Benchmarking Active Record queries needs repeated runs and cache clearing to measure realistic PostgreSQL performance; a Ruby script can report percentile timings.
Your Rails sandbox console
rails console --sandbox lets you test database changes in a console session and automatically rolls them back on exit, while file and email actions remain permanent.
Understanding race conditions with duplicate unique keys in Rails
validates_uniqueness_of can still allow duplicate records under concurrent requests; a unique database constraint prevents the race and turns collisions into ActiveRecord::RecordNotUnique.
Devise: Don't forget to lock users with soft delete
Soft-deleted users can stay authenticated in Devise unless account activity checks are tied to the trash state. Customizing active_for_authentication? blocks sign-in and protects password reset flows.
Terser is good at minifying JavaScript
Terser compresses JavaScript aggressively, merging branches, inlining small functions, and folding constants to cut output size further than expected.
HTML/CSS: "transparent" is not a color
transparent in gradients can turn into gray in older browsers because it is treated as black with 0% opacity. Use transparent white with rgba(255,255,255,0) for backward compatibility.
PostgreSQL and its way of sorting strings
PostgreSQL string ordering follows the C library locale rules, so letters are compared before spaces and punctuation, and case is grouped together.
Run all RSpec tests edited or added in the current branch
Run only edited or newly added RSpec files in the current branch by diffing against master, which speeds feedback on focused test changes.
Jasmine: Use `throwUnless` for testing-library's `waitFor`
Flaky waitFor tests can fail when Jasmine expectations do not throw, preventing retries. throwUnless and throwUnlessAsync turn failed checks into exceptions for reliable waiting.
Jasmine: Dealing with Randomness
Random behavior in Jasmine tests makes results unstable unless spyOn controls dependent calls. returnValue, returnValues, and callFake keep shuffles predictable.
Rails credentials: Always use the bang version
Missing secrets can stay unnoticed in some environments and break behavior later. Using ! on Rails.application.credentials and Rails secrets raises immediately when a value is absent.
Implementing a custom RuboCop cop
Project-specific RuboCop rules can flag conventions and stop the pipeline with little code, such as banning TODO and WIP comments in Ruby files.
Be very careful with 301 and 308 redirects
301 and 308 redirects can be cached by browsers indefinitely without cache control, making later changes impossible unless users clear their cache.
Rails: Prefer parsing dates with Date.strptime()
Date.parse guesses date formats and can accept invalid input, producing unexpected dates. Date.strptime validates against an explicit pattern and avoids ambiguous parsing.
Rails SQL Injection Examples
Unsafe ActiveRecord query methods can expose applications to SQL injection when raw SQL is built from untrusted input.