YJIT is Ruby's default just-in-time compiler. It is considered production-ready since Ruby 3.2 (source). To activate YJIT you need two steps: Your ruby binary needs to...
...be compiled with YJIT support. You need to enable YJIT. Getting a Ruby with YJIT support We usually install Ruby with tools like rbenv or asdf. This compiles the ruby...
The benefit of the Rails asset pipeline is that it compiles your stylesheets and javascripts to a single file, respectively. However, the consequences are startling if you don't understand...
...all your asset libraries in the same folder, which quickly becomes confusing as your set of assets grows. To overcome this, we have two different solutions. Custom solution
...and how to normalize them. In the example below, the Movie#title attribute is stripped from leading and trailing whitespace automatically: class Movie < ApplicationRecord normalizes :title, with: -> { _1.strip } end
...a class. Which could look like this: class Movie < ApplicationRecord normalizes :title, with: Normalizers::StripNormalizer end The with keyword accepts any callable object that takes the attribute’s value as...
Goals After finishing this lesson you should be able to read and write simple Ruby programs. Gain an understanding of the following concepts: Working with basic datatypes: String, Integer...
Classes and inheritance The difference between class methods and instance methods (def self.method vs. def method) Modules and include Code blocks ("procs", "lambdas") Input and output Simple regular...
Tested on Ubunut 22.04 1. Opener script Create a file ~/.local/bin/coverage_zip_opener with: #!/bin/bash tmp_folder="/tmp/coverage-report-opener" if [ -z "$1" ] then echo "Usage: coverage_zip_opener [filename]" exit -1 fi
index_filename=$(find /tmp/coverage-report-opener -name "index.html" | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2- | head -1) if [ -z "$index_filename" ] then echo "No index file...
You want to prevent input to a form field, but all the solutions have side effects: The [readonly] attribute is only available for text fields, but not for checkboxes, selects...
...all kinds of fields, but will no longer include the field value in the submitted form data. pointer-events: none still allows keyboard input, and does not indicate disabledness visually...
We structure our CSS using the BEM pattern. Our naming convention for blocks, elements and modifiers has evolved over the years. This card shows our current style and various alternative...
...styles that you might encounter in older projects. The difference between the various styles are mostly a matter of taste and optics. I do recommend to not mix styles and...
The :test adapter doesn't respect limits_concurrency configuration. Switch to :solid_queue adapter in your test to verify blocking behavior. Job Configuration class MembershipJob < ApplicationJob limits_concurrency(key: ->(membership...
...assert_enqueued_jobs(2, only: MembershipJob) # Both enqueue, but we haven't proven the second will block end The solution test('limits concurrency second job with same membership is blocked...
...investigate by running that example again using rspec . However, this does not work with shared examples, since Rspec doesn't know in which context the shared example should be run...
...But there is a different way: You can run the shared example using the -e, --example option. It takes a string value and runs all scenarios containing that substring in...
...write complex migrations in Rails Discuss with your mentor Instead of migrations, could we simply log into the production server's SQL console and alter tables there whenever we need...
...Actor#total_movies: This field should cache the total number of movies an actor stars in Actor#first_movie_id: This field should cache the first movie to which the...
In MovieDB, add a new field “Principal filming location”. In a movie’s show view, geocode that location and show a Google map centered around it
...E2E feature that tests that the map shows the correct location. Hints The purpose of this lesson to learn interacting with external APIs from JavaScript. Even though this exercise can...
...offset, e.g. Thu, 28 Mar 2019 16:00:00 CET +01:00. Ruby's stdlib TZInfo also has time zones, but with different identifiers. Unfortunately, not all timezone codes can...
...time zone has a pretty abbreviation. In such cases, you'll end up with a semi-broken offset identifier that humans won't understand. What to do?
...driver_opts directly. However, this is deprecated and will be removed in version 4 of selenium-webdriver. Version 5.x will drop support for passing the service options as hash...
...Option 2: Connect tests to a manually started chromedriver Warning This does not work with selenium-webdriver > 4 anymore. You can pass in a specific port as attribute of the...
Some browsers render PNG images with color profiles and other shenanigans, some don't. The cleanest way to have consistent colors across browsers is to convert all your images to...
...a standard color profile, strip the image's original profile and attach the standard profile. If you can't be bothered to convert color profiles, a quicker (but less effective...
...use heredoc to avoid endlessly long lines of code that nobody can read. Heredoc strings preserve linebreaks and can be used like this: def long_message puts(<<-EOT)
...a very long message... Sincerely, foobear EOT end <<-EOT will be somewhat of a placeholder: anything you write in the line after you used it will be its value until...
...is great when dealing with JSON data. Check out the official jq Manual. Content Select only specific keys Modify keys Set default value Filter by key name Delete specific keys...
...Overwrite/add nested key value Select only specific keys Command jq '.[] | { Name, OriginString }' Input [ { "Id": 1, "Name": "foobar.net", "OriginString": "/FOOBAR/foobar.net" }, { "Id": 2, "Name": "barfoo.baz", "OriginString": "/FOOBAR/barfoo.baz" } ] Output { "Name": "foobar.net", "OriginString": "/FOOBAR/foobar.net...
This RailsCast demonstrated a very convenient method to activate VCR for a spec by simply tagging it with :vcr. For RSpec3 the code looks almost the same with a few...
...minor changes. If you have the vcr and webmock gems installed, simply include: # spec/support/vcr.rb VCR.configure do |c| c.cassette_library_dir = Rails.root.join("spec", "vcr") c.hook_into :webmock end RSpec.configure do |c...
This is a short overview of things that are required to upgrade a project from the Asset Pipeline to Webpacker. Expect this upgrade to take a few days even the...
Cleanup Remove all gems you used for assets and the Asset Pipeline itself, e.g. sass-rails, uglifier, autoprefixer-rails, sprockets-rails, jquery-rails, bootstrap-sass and many more.
Option 1: Creating a self-signed certificate with the openssl binary As igalic commented on this gist. openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout server.key...
make it an X.509 certificate, not a Certificate Signing Request. Option 2: Creating a self-signed certificate with the mkcert binary The linked tool mkcert helps you to setup...
If you're using a Redis cache in Rails (e.g. :redis_cache_store), it's possible to configure additional parameters for your Redis connection. Example config for Rails 7.2
...store = :redis_cache_store, { pool: { timeout: 0.5 }, read_timeout: 0.2, # default 1 second write_timeout: 0.2, # default 1 second # Attempt two reconnects with some wait time in between reconnect_attempts...
...universe multiverse deb-src http://de.archive.ubuntu.com/ubuntu/ yakkety-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu yakkety-security main restricted universe multiverse deb-src http://security.ubuntu.com/ubuntu yakkety-security...
10 http://de.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 Packages 10 http://security.ubuntu.com/ubuntu yakkety-security/main amd64 Packages 2:7.4.1829-1ubuntu2 10 10 http://de.archive.ubuntu.com/ubuntu yakkety/main...
...s possible you get this "error" message: *** [err :: example.com] There are no Phusion Passenger-served applications running whose paths begin with '/var/www/example.com'. *** [err :: example.com] This is just because there were...
...no running passenger process for this application on the server which could be restarted. It's not a real error. The application process will start if the first request for...
...not necessary to add a version constraint next to your packages in the package.json. Since all versions are saved in a lockfile, everyone running yarn install will get exactly the...
...within the yarn install command: Before: unpoly@^2.7.2: version "2.7.2" resolved "https://registry.yarnpkg.com/unpoly/-/unpoly-2.7.2.tgz#55044c08bce0984c000f7cd32450af39271727de" integrity sha512-jfBbBRBQMCZZcNS6fckKpFunfdiTDBXW8yxRKqLs09jSrYYUDPd+YuyDoXjABXOro0aDUIMcmyTc7moc1/Z5Tw== After: unpoly@x: version "2.7.2" resolved "https://registry.yarnpkg.com/unpoly/-/unpoly-2.7.2.tgz#55044c08bce0984c000f7cd32450af39271727de" integrity sha512-jfBbBRBQMCZZcNS6fckKpFunfdiTDBXW8yxRKqLs09jSrYYUDPd...
...loading associations. By preloading associations you can prevent the n+1 query problem that slows down a many index view. You might have noticed that using :include randomly seems to...
...involved table with a condition like...
...WHERE id IN (123, 125, 170). Execute a single query for a huge table joined from all involved tables. ActiveRecord prefers option 1, probably...