When RubyMine reports Rubocop returning "exit code -1", upgrading Rubocop can be the fix: gem install rubocop "The logs" can...

postgresql.org

There is no such thing as a "default order" of rows in database tables. For instance, when you paginate a...

mtlynch.io

...boring style violations. When you demonstrate an appreciation for constructive criticism, your reviewer provides better feedback . Make others better: Your code review techniques set an example for your colleagues. Effective...

If you expect method calls in RSpec 3, be aware that the argument matchers use very liberal equality rules (more...

makandra dev
interfaces.rauno.me

A list of implementation details that make for a better / expected user experience. Have these in mind when implementing a web design. This document outlines a non-exhaustive list of...

makandra dev

While most Rails Apps are tied to at least one external REST API, machine-to-machine communication via GraphQL is...

The sidekiq-rate-limiter gem allows rate-limiting Sidekiq jobs and works like a charm. However, it needs to be...

Array.wrap wraps argument in an array, unless it is array-like already. The behaviour is a bit saner than Array[...]. Array.wrap(nil) # => []

" foo bar \n \t boo".squish # => "foo bar boo" Time.current, Date.current, DateTime.current behaves like .now or .zone.now depending on whether a time zone is set

Given you have a strict CSP that only allows elements from your own domain: Content-Security-Policy: script-src 'self' This will block JavaScript handlers inlined as attribute into your HTML elements. Clicking on the following link will only log an error with a strict CSP: click me click me Solution 1: Move the handler into your JavaScript The recommended solution is to move the handler from the HTML to the allowed JavaScript file that we loaded via . In the example above we could invent a new [data-alert] attribute with the alert message: click me Then our JavaScript intercepts clicks on elements with that attribute: document.addEventListener('click', function(event) { let link = event.target.closest('[data-alert]') if (link) { let message = link.dataset.alert alert(message) event.preventDefault() } }) Solution 2: Allow that one handler in your CSP Some browsers allow the CSP directive script-src-attr. This lets you allow the hashes of actual JavaScript code. The SHA256 hash of alert('hello') is vIsp2avtxDy0157AryO+jEJVpLdmka7PI7o7C4q5ABE= (in Base64). We can allow this one event handlers like this: Content-Security-Policy: script-src 'self'; script-src-attr 'unsafe-hashes' 'sha256-vIsp2avtxDy0157AryO+jEJVpLdmka7PI7o7C4q5ABE=' Note the sha256- prefix. This event handler now works when clicked: click me But any other script will still be blocked: click me Dealing with legacy browsers Currently (November 2023) about 75% of browsers support script-src-attr. Here is a forward-looking compromise that many users use with new CSP features: Have a liberal CSP with old directives supported by all browsers Make your CSP stricter with new, more specific directives for browsers that support it The CSP spec supports that approach in that using newer, more specific directives disable older, more general features. In our case this means: For old browsers, allow all inline scripts For new browsers, disallow inline scripts but allow inline handlers with given hashes Here is a CSP directive that works like this: Content-Security-Policy: script-src 'self' 'unsafe-inline'; script-src-elem 'self'; script-src-attr 'unsafe-hashes' 'sha256-vIsp2avtxDy0157AryO+jEJVpLdmka7PI7o7C4q5ABE=' Old browsers will only use script-src. New browsers will use script-src-elem (for tags) and script-src-attr (for inline event handlers), which override the more liberal rules from script-src.

...Capybara see the print stylesheet Capybara always requests as the screen medium. The step belows reloads the current page with a query param we will use in our layout to...

In long diffs, it can become impossible to spot small changes in larger blocks of moved code. This may be either a method that was moved from the top to...

In development, we store files using ActiveStorage's disk service. This means that stored files are served by your Rails...

On Chrome, Firefox and modern Safari, document.scrollingElement will return the element. The behavior varies on legacy browsers that we no longer support: Old Safari versions, document.scrollingElement will return...

...update cucumber Make sure you have a recent version of geordi (it doesn't belong in your Gemfile!): gem install geordi Check if you're using Transforms Transform is no...

github.com

You can hook into Slack when using Capistrano for deployment. The slackistrano gem does most of the heavy lifting for...

tl;dr The :is() pseudo selector - specificity of its most specific argument - matches against a comma-separated list of selectors...

Same requests are recorded only once in vcr. Replaying a test fails, if you trigger the same request multiple times...

tl;dr The :where() pseudo selector - zero specificity - matches against a comma-separated list of selectors. Example Compound selectors like...

use Postgres' lower() function add an index on lower(email) Probably the best approach is to just convert emails (and usernames) to lowercase within Rails. Popular authentication libraries...

...to be performed around a deploy. Be it to notify operations about changed application behavior, be it to run a little oneline script after the deploy. Most database-related stuff...

makandra dev

While debugging a SPF record I found spf-record.de to be very helpful. it lists all IPs that are covered by...

Some users might use Adblock Plus or similar browser plugins to reduce the number of ads displayed. If you run...

...in development + test, but keep action_on_unpermitted_parameters = false in production, your application behaves different between these environments. On the other hand it forces to fix these errors in...

...Parameters).to receive(:action_on_unpermitted_parameters).and_return(false) for tests, that should behave exactly like in production...

web.archive.org

...any cleanup yourself. Why? Understand this: before(:context) is run when the context/describe block begins, before(:context) is run outside of transactions, so data created here will bleed into other...