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) { // ... } }

Use the click method on the DOM element: let link = document.querySelector('a') link.click()

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

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

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:

github.com

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

developer.mozilla.org

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

github.com

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

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

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

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

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

stackoverflow.com

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

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

I recently stumbled upon the Rails feature composed_of. One of our applications dealt with a lot of addresses and they were implemented as 7 separate columns in the DB...

...and Rails models. This seemed like a perfect use case to try out this feature. TLDR The feature is still a VERY leaky abstraction. I ran into a lot of...

...rails_performance (https://github.com/igorkasyanchuk/rails_performance) provides a lot of valuable information with very little setup cost. It only needs Redis which we use in the majority of our applications anyway...

Only problematic requests (> 500 ms) Longer history than "Recent requests" The "500 Errors" screen self-explanatory and hopefully always empty The "Custom Events" screen Let's you easily add...

My RubyMine (and it seems like many other Java GUI applications) crashes the Compiz window decorator almost every time on exit. This also seems to happen for the Unity decorator...

...Update: The commited fix from below seems to have made it into the stable Ubuntu repository. Easy mode You can restore window decorations by executing this command: gtk-window-decorator...

...operators typeof and instanceof which work very differently. JavaScript has some primitive types, like string literals, that are not objects (as opposed to Ruby, where every value is an object...

...Some values are sometimes a primitive value (e.g. "foo") and sometimes an object (new String("foo")) and each form requires different checks There are three different types for null (null...

jsfiddle.net

When you need test images, instead of using services like lorempixel or placehold.it you may generate test images yourself. Here we build a simple SVG image and wrap it into...

...a data: URI. All browsers support SVG, and you can easily adjust it yourself. Simply set it as an image's src attribute. JavaScript Simple solution in modern JavaScript, e.g...

Defining one callback several times in the same class behaves different in ActiveRecord and ResourceController. While in ActiveRecord the callbacks are enqueued, they overwrite each other in ResourceController. ActiveRecord - a...

...common practice class Post < ActiveRecord::Base does 'post/behavior' before_validation :do_something end module Post::BehaviorTrait as_trait do before_validation :do_something_else end end do_something_else and...

...is hard coded. A popular example is extension_allowlist, which returns an array of strings and let's you only upload files that have a filename with an extension that...

...matches an entry in that array. Another useful validation can be size_range, which gives you a little bit of control over how your storage gets polluted.

Here is a bash script that I use to auto-configure displays on Ubuntu 24.04 with Xorg. Background Ubuntu always sets the primary display to the 1st (i.e. internal) display...

...bottom-aligned (the default would be aligned at their top edges). As an oddly specific bonus (you may not need this), I adjust my internal display's resolution when connected...