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.

A gotcha of Ruby variable scoping

Ruby local variables are visible after conditional branches, so a missing assignment can yield nil instead of an error and silently produce blank output.

Compare library versions as "Gem::Version" instances, not as strings

String comparison can misorder gem and Ruby versions, letting newer releases slip past checks; Gem::Version gives reliable semantic version comparisons.

How to write complex migrations in Rails

Complex Rails schema changes need SQL, embedded migration models, or adapter helpers when simple add_column and update calls cannot handle existing data safely.

Working on the Linux command line: Use the `tree` command instead of repeated `cd` and `ls`

Directory trees are easier to inspect with tree than repeated cd and ls, especially for nested structures. Depth limits and shell aliases keep output manageable.

Your browser might silently change setTimeout(f, 0) to setTimeout(f, 4)

Nested zero-delay timers are clamped by browsers, so repeated setTimeout(f, 0) calls can run several milliseconds late, especially in background tabs.

How to speed up JSON rendering with Rails

Slow Rails JSON endpoints often waste time in JBuilder, loading full records, and Ruby object allocation. pluck, database aggregation, and cached materialized views can cut response time dramatically.

RubyMine: Adjust Code Templates

RubyMine test file generation can produce excessive boilerplate, and file templates let you tailor the output to project needs.

Protected and Private Methods in Ruby

Ruby method visibility differs from Java: private allows only implicit calls, while protected permits access between instances of the same class or subclasses.

Advisory: Excel converts CSV entries to formulas

Spreadsheet apps can interpret CSV cells beginning with =, +, -, or @ as formulas, turning exported user input into a security risk.

How to: Ensure proper iconfont rendering with Webpack

Custom icon fonts can render as garbled characters after switching from Sprockets to Webpack because CSS charset detection changes. Adding a UTF-8 BOM or an explicit charset can prevent intermittent display failures.

How to query GraphQL APIs with Ruby

GraphQL APIs return nested data through one endpoint, and Ruby can query or mutate them with plain HTTP requests without adding graphql-client.

Rails npm packages will use an uncommon versioning scheme

Rails npm packages need a version mapping from 4-part gem releases to npm’s 3-part semver, so package ranges keep working across patch and prerelease builds.

JavaScript: Humanizing durations

Format durations into the nearest human-readable unit with locale-aware pluralization using Intl.NumberFormat, defaulting to German.