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.
How to combine unknown CSS selectors
Combining unknown CSS selectors safely fails when a selector list appears; :where() and :not() preserve correct matching without breaking lists.
JavaScript: Listening to a class getting added
Detecting when a CSS class is added can be done with a MutationObserver, useful for reacting to DOM state changes on selected elements.
How to ask a (mobile) browser about the true visual viewport
Pinch-zoom, the on-screen keyboard, and other overlays can shift the actually visible page area beyond the layout viewport. VisualViewport exposes the visible region for positioning and tracking.
How to start Terminator with split screens and custom commands running
Start Terminator with split panes and predefined commands while keeping shells open after the command exits.
JavaScript: Testing the type of a value
JavaScript value checks are inconsistent across primitives, objects, arrays, null, undefined, and NaN; the right test depends on whether you need type, instance, or property presence.
How to Work With Time Zones in Rails
Rails uses configurable time zones, while Ruby time APIs follow the server zone and can return wrong results. Time.zone keeps date and time handling consistent.
Avoiding Test-Case Permutation Blowout - Steven Hicks
Business-rule tests with multiple variables can explode into 2n permutations. An n+1 pattern keeps coverage manageable while making individual cases easier to follow.