Sometimes it's nice to have some coloring in your logs for better readability. You can output your logs via tail and pipe this through sed to add ANSI color...

...containing "FATAL" in red and all lines with "INFO" in green: tail -f /path/to/log | sed --unbuffered -e 's/\(.*INFO.*\)/\o033[32m\1\o033[39m/' -e 's/\(.*FATAL.*\)/\o033[31m...

...good UI design, you should always be able to come up with a default. Since the user interface makes up 70% of a typical web application, this is closely related...

...and a "user" are both human beings, it's rarely practical to have them share a model or inheritance hierarchy. Try to model everything as CRUD (regardless of whether a...

Splitting up commits makes the process of reviewing often easier, since you can create several merge requests or review every commit one by one. So when you find out that...

...refactoring along the current changes, you can use one of the following processes to split up the changes into several commits in a logical order: #1 Splitting up the last...

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...

...the bottom of a file, or a long test file that was split in many. Fortunately, Git offers a special highlighting mode that directs the reader's attention to relevant...

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

You need to update a lof gems. Make sure you don't have any version constraints in your Gemfile or your bundle update won't do anything!

...cucumber_priority: bundle update cucumber_priority Upgrade spreewald: bundle update spreewald Upgrade cucumber_factory: bundle update cucumber_factory Upgrade parallel_tests: bundle update parallel_tests Even on the latest version...

...hints on best practices to maintain your tasks in larger projects. Rake Tasks vs. Scripts The Rails default is using rake tasks for your application tasks. These live in lib/tasks...

...case you want to avoid rake for your tasks and just use plain ruby scripts, consider lib/scripts/* as folder. Keeping tasks slim For readability and testing it's easier to...

...of different file types including: Ruby (business logic) HTML fragments (layouts and views) CSS/Sass/SCSS (styles) JavaScript (client-side behavior) Static media (images, fonts, videos) Except for the Ruby part, all...

...your application assets cachable in Rails The assets pipeline history The section "network" of "JavaScript Start-up Optimization" Sprockets: Everything You Should Know About the Rails Asset Pipeline

If you are using our opscomplete.com hosting we can set all environment variables mentioned below for your deployment on request. If you're lucky DO_NOT_TRACK=1 opts...

...are collecting data only after you opt into that. ng analytics --global disable Storybook https://storybook.js.org/docs/configure/telemetry npm run storybook -- --disable-telemetry npm run storybook -- --disable-crash-reports export STORYBOOK...

makandra Curriculum

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...

...will tell you if there are any and you should not commit when you see them. So go ahead and switch your editor/IDE to automatically remove them for you.

Note that except for RubyMine, the following changes will remove trailing white-space on all lines, not only those that you changed. While this should not be a...

makandra dev

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...

Simplecov is a code coverage tool. This helps you to find out which parts of your application are not tested. Integrating this in a rails project with rspec, cucumber and...

Add it to your Gemfile and bundle group :test do gem 'simplecov', require: false end Add a .simplecov file in your project root: SimpleCov.start 'rails' do

...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...

# features/support/database_cleaner.rb DatabaseCleaner.clean_with(:deletion) # clean once, now DatabaseCleaner.strategy = :transaction Cucumber::Rails::Database.javascript_strategy = :deletion Cucumber & Rails 2 The latest available cucumber-rails for Rails 2 automatically uses database...

...off. To have database_cleaner work correctly: Add the attached database_cleaner.rb to features/support/ Make sure features/support/env.rb contains the following lines in this order: # features/support/env.rb require 'features/support/database_cleaner' require 'cucumber/rails/active_record' require 'cucumber/rails/world...

If your app does not need to support IE11, you can use most ES6 features without a build step. Just deliver your plain JavaScript without transpilation through Babel or TypeScript...

...and modern browsers will run them natively. Features supported by all modern browsers include: fat arrow functions (() => { expr }) let / const class async / await Promises Generators Symbols Rest arguments (...args)

bundler.io

Bundler so far ignored the version specified under BUNDLED_WITH in the Gemfile.lock. This had two annoying consequences: If the bundler version on your system was lower than in the...

...and had to manually install the correct version. If the bundler version on your system was higher than in the Gemfile.lock, bundler silently updated the version in the Gemfile.lock to...

...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...

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...

...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...

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.

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...

makandra Operations

...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...

developer.chrome.com

The File System Access API is a new capability of modern browsers that allows us to iterate over selected folders and files on a user's machine. Browser support is...

...not great yet, but if the feature is only relevant for e.g. a single admin user it could still be worth using it prior to wider adaption instead of building...