2.ordinalize # => "2nd" 1002.ordinalize # => "1002nd" 1003.ordinalize # => "1003rd" -11.ordinalize # => "-11th" -1001.ordinalize # => "-1001st...
...external commands from within Ruby, but the most powerful ones are Open3.capture3 and Open3.popen3. Since those can do almost everything you would possibly need in a clean way, I prefer...
...to simply always use them. Behind the scenes, Open3 actually just uses Ruby's spawn command, but gives you a much better API. Open3.capture3 Basic usage is require 'open3'
When storing floating-point numbers such as prices or totals in an SQL database, always use a DECIMAL column. Never use FLOAT or kittens will die. DECIMAL columns are parametrized...
...with a precision and a scale. These parameters describe which numbers can be stored in that column. E.g. a decimal with a precision of 5 and a scale of...
on the bash (issued as postgres user) Start/Stop/Restart PostgreSQL pg_ctl -D $configdir start|stop|restart Start/Stop/Restart the corresponding PostgreSQL using the given configuration directory. The configuration directory should contain...
...the postgresql.conf file. The following example would start the PostgreSQL of our governor instances: pg_ctl -D /var/lib/postgresql/config start PostgreSQL fast shutdown pg_ctl -D $configdir stop -m fast
When testing JavaScript functionality in Selenium (E2E), you may need to access a class or function inside of a evaluate_script block in one of your steps. Capybara may only...
...your tests (and neither in the dev console). The following principles/concepts also apply to Sprockets. Say we have a StreetMap class: // street_map.js class StreetMap { function getLatitude() { // ... } function renderOn(mapElement) { // ... } }
Is your application doing something expensive every few seconds? Maybe an animated slider that rotates images? Maybe you are updating data over the network every five minutes? It's a...
...this if the your document tab is not even visible to the user. This saves your user's battery and data plan. You can ask document.visibilityState or document.hidden whether this...
...records as deleted instead of removing them — and how listing, finding and associations behave for soft-deleted records. You can decide between :dependent and soft delete from the shape of...
...make this more convenient we like to define a scope :active, -> { where(trashed: false) } on soft-deletable models. Controllers should no longer deliver show views or forms for a soft...
...HTML's accepts a single file. You can allow multiple files via . But sometimes, selecting multiple files is not enough and can be cumbersome for the user. Enter webkitdirectory:
...webkitdirectory switches the browser's file picker to select a directory. All files inside that directory, and inside any nested subdirectories, will be selected for the file input.
Spreewald comes with a selector_for helper that matches an English term like the user's profile into a CSS selector. This is useful for steps that refer to a...
...particular section of the page, like the following: Then I should see "Bruce" within the user's profile ^^^^^^^^^^^^^^^^^^ If you're too lazy to manually translate English to a CSS...
Use the click method on the DOM element: let link = document.querySelector('a') link.click()
Code splitting is a feature of esbuild that can keep huge libraries out of the main bundle. How code splitting works Like Webpack esbuild lets you use the await import...
...code on demand: // application.js const { fun } = await import('library.js') fun() However, esbuild's code splitting is disabled by default. The code above would simply inline (copy) library.js into application.js:
Note: We are talking about Machinist 1 here, Machinist 2 may have solved this or might require a different approach. Machinist allows named blueprints (e.g. User.blueprint(:admin)) that inherit from...
...for the vip blueprint go here inherit :premium end ...put the attached code into spec/support/machinist_inherit.rb and require 'spec/support/machinist_inherit' in your blueprints.rb. Note that it might not be sufficient to put...
I was recently asked to optimize the response time of a notoriously slow JSON API endpoint that was backed by a Rails application. While every existing app will have different...
...be used to reproduce the results. I tried to mimic the case where things started out fast but did not scale well: There is an existing Rails App with a...
For my computer science bachelor's thesis I programmed and evaluated a CLI Test Case Prioritization (TCP) tool for makandra. It has been written as a Ruby Gem and was...
...as T2 > T3> T1 > T4 > T5 > T6. Selection of a strategy In the preselection coverage-, search-based, model- and combinations of different prioritization methods. History- and fault-based approaches could...
...method to automatically compute an ETag from the given record, array of records or scope of records: class UsersController < ApplicationController def show @user = User.find(params[:id]) fresh_when @user
...by passing an array of ETaggable objects to fresh_when. class UsersController < ApplicationController def show @user = User.find(params[:id]) # The show template also renders the user's posts. fresh_when...
...manage to find the cause of this behaivour yet, but I think it has something to do with the start order of the nova services. (When nova-network isn't...
...present at nova-compute startup, no rules will be applied at all) You can restart the nova-compute service and nova should insert the rules one by one (you can...
...status code 400) |_http-title: 400 The plain HTTP request was sent to HTTPS port | ssl-cert: Subject: commonName=www.makandracards.com/countryName=DE | Not valid before: 2015-10-14T12...
...Not valid after: 2016-10-14T12:42:03+00:00 |_ssl-date: 2016-08-05T11:33:52+00:00; +9d23h48m18s from local time. | tls-nextprotoneg: | h2
Applications send e-mail for notifications, confirmations and more. This lesson covers Action Mailer, keeping development and staging from sending real mail, and getting mail delivered to the inbox.
...mailer, including attachments, and preview mails during development. You can explain why development and staging must never send real mail, and how to make sure of it, e.g. with an...
...on this lesson in advisor mode. Learning goals You can explain what problem Unpoly solves: SPA-like navigation and interactions on a server-rendered app, with very little JavaScript.
...Rails ships with Hotwire (Turbo and Stimulus) for the same job: updating fragments of a server-rendered page without full reloads. Turbo Drive and Turbo Frames correspond roughly to Unpoly...
...case Ruby does not detected the expected encoding of a file automatically you can specify the known encoding manually. Example with File.open file = File.open('some.bin', encoding: Encoding::ASCII_8BIT)
text.encoding => # Example with File.read text = File.read('some.bin', encoding: Encoding::ASCII_8BIT) text.encoding => # More details about the encoding of strings in Ruby can be found here...
The solution in this card is based on a stack overflow post by Leventix. If you need to make request come from a fixed IP address for the duration of...
...a Cucumber scenario, the code below lets you write this: Given my IP address is 188.174.117.205 Rails 3 Given /^my IP address is "(.*?)"$/ do |ip| ActionDispatch::Request.any_instance.stub(:remote_ip).and...
This looks like it is safe to use: 2.2.1 :001 > a = b = "hello world" "hello world" 2.2.1 :002 > a "hello world" 2.2.1 :003 > b "hello world" 2.2.1 :004 > b = " goodbye...
...happening when we do a = b = "hello world"? First, b is assigned to a String object "hello world", then a is assigned to b. a and b are now assigned...
...number of different versions for Ruby, Rails and many gems. To be able to switch between projects easily, we must control every dependency our applications has. Important
...gem is and where installed gems live, and you can read a gem's source locally (e.g. with bundle open) or on GitHub. You can explain why we need a...
...Thunderbird 3 put there. Though the CompactHeader addon is often claimed to be a solution it does way too much for me -- I like the headers the way they are...
...very well for me (keeps the date and "other actions" menu on the right, see the screenshot below): Open up your profile directory (~/.thunderbird/ /) Create a chrome directory inside it...