...extend in Ruby, there is a misconception that extend would add methods to the singleton class of a ruby object as stated in many posts on this topic. But in...
...fact, it is added to the ancestors chain of the singleton class! Even though it is technically not the same, practically this can be considered the same in most use...
Ruby has a set of methods to convert an object to another representation. Most of them come in explicit and implicit flavor. explicit implicit to_a to_ary
to_s to_str to_i to_int There may be even more. Don't name your methods like the implicit version (most prominently to_hash) but the...
Looking at the source code of the validates_numericality_of validator, it becomes clear that it converts the attribute in question to either an integer or float: if configuration[:only...
...any of your users as this is only broken in the most extreme case shown above...
...a minifier that is good enough for most cases. If you're looking to squeeze out as many bytes as possible, you can consider compressing with Terser instead.
...will increase your build times significantly, but produce the smallest output: Terser (3 pass) Terser (1 pass) esbuild application.js 163.6 kB 163.7 kB 181.6 kB application.js (gzipped)
...text option were able to find nodes based on rendered text, even if it spans over multiple elements in the HTML. Imagine a page that includes this HTML: Hi!
Even though the text is separated by a tag in the HTML, it is matched until Capybara 2 which used to "squish" text prior to the comparison...
...utilities provided are query methods, user interactions, dom expectations and interacting with components of several frontend frameworks, which allows us to worry less about the details happening in the browser...
...find a necessity to use methods like waitFor, because your code itself may trigger something asynchronous (e.g. animations or setTimeout). Let's see what the docs state on this method...
makandra's development process Learn about our process. The squares represent the state of the issue in Linear: In particular you should understand: Why do we have a process?
...is an issue (formerly: story)? What metrics does our process optimize for? How to divide large requirements into issues. When is an issue too small, when is it too large...
...for their gem version, while npm only allows 3 digits and a pre-release suffix. To map gem versions and npm versions, Rails is going to use a naming scheme...
7.0.1.1 7.0.101 7.0.0.rc1 7.0.0-rc1 The old scheme Earlier Rails used the following scheme, which didn't work well with version ranges in your package.json:
...index is not as global as you might think. Actually, it is scoped to a so-called "stacking context". z-indexes only have meaning within their stacking context, while stacking...
...contexts are treated as a single unit in their parent stacking context. This means indices like 99999 should never actually be needed. Creating a new stacking context
git shortlog -s -n [commit-range] -n, --numbered Sort output according to the number of commits per author -s, --summary Suppress commit descriptions, only provide commit count [commit-range]
...tagname.. for "everything after that tag" Example output for spreewald: 60 Tobias Kraze 12 Henning Koch 7 Dominik Schöler 6 Thomas Eisenbarth 5 Martin Straub 3 Minh Hemmer...
Access the Method object Dead simple: Get the method object and ask for its owner: "foo".method(:upcase) # => # "foo".method(:upcase).owner # => String Look up a method's source location...
...Ruby 1.9 adds a method Method#source_location that returns file and line number where that method is defined. class Example; def method() end; end # => nil Example.new.method(:method).source_location...
Using ffmpeg, you can easily re-encode a video to reduce its file size. Command Do it like this: ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -c...
...a copy -movflags +faststart output.mp4 Arguments -i input.mp4 specifies your input file -c:v libx264 specifies H.264 encoding. Use -c:v libx265 for H.265/HEVC. It's an excellent modern encoding...
...tools in the Chrome JavaScript console. Make the whole page editable This is not special to Chrome, but still a clever thing: document.body.contentEditable=true Taking time You can easily measure...
...the time on the console with named timers: console.time('myTime'); // Start timer console.timeEnd('myTime'); // End timer and print the time Reference previously inspected elements (from the Elements panel)
For Selenium tests, your browser starts in your local timezone, or whatever your system's environment specifies. This is usually good enough. To test any timezone-dependent behavior in Chrome...
page.driver.browser.execute_cdp('Emulation.setTimezoneOverride', timezoneId: 'Asia/Tokyo') Important: This change is permanent throughout the browser session. You need to remove the time zone override at the end of each test explicitly...
If you use the selenium-webdriver gem, it will sneakily phone home once every hour whenever you run a browser based feature spec. Check if you're affected
...with Ruby's Time.at.) Opt out You can opt out either globally: # .bashrc export SE_AVOID_STATS=true or project based # spec_helper.rb ENV['SE_AVOID_STATS'] = 'true'
SimpleForm is a great approach to simplifying your forms, and it comes with lots of well-defined input types. However, the :grouped_select type seems to be overly complicated for...
Consider this example, from the documentation: form.input :country_id, collection: @continents, as: :grouped_select, group_method: :countries While that looks easy enough at a first glance, look closer. The...
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...
When defining a trait using the Modularity gem, you must take extra steps to define constants to avoid caveats (like when defining subclasses through traits). tl;dr In traits, always...
...define constants with explicit self. If your trait defines a constant inside the as_trait block, it will be bound to the trait module, not the class including the trait...
...op]=-operators work the same way, but actually they don't. ||= and &&= Those are special cases, because the assignment will only happen if the first variable passes the check (false...
...and true for &&). a ||= b # => a || (a = b) a &&= b # => a && (a = b) But still, if reading a has any side effects, they will take place regardless of to what...
...how to add it to your Rails console. Welcome banner Modern versions of irb show a pretty banner which prints IRB version, Ruby version, a random IRB command hint,
How to disable If you prefer not to see this banner, update your ~/.irbrc (or create, if you don't have one yet) and add: IRB.conf[:SHOW_BANNER] = false...
Set profile.password_manager_leak_detection to false in your Selenium Chrome options to disable password leak detection and suppress the warning. Problem When running Selenium tests with recent...
...a data breach…" This alert can break automated test runs, especially in CI/CD pipelines. Solution You can disable Chrome’s password leak detection to prevent this warning from appearing.
...tasks like filtering large files for arbitrary keywords. When additional context is needed for search results, you might find yourself adding flags like -B5 -A10 to your query. Now, every...
...search result covers 16 lines of your bash. There is another way: You can easily pipe your search results to the VIM editor and cycle through them. Example: Searching for...
...the method __dir__. Read this card for more information about __FILE__ and __dir__. Example Structure: . ├── bin │ ├── format_changelog ├── CHANGELOG.md bin/format_changelog: #!/usr/bin/env ruby changelog_path = ? # How to get the path to...
...Not Disturb" feature to disable notifications and then forget to turn it off. DND stays enabled across reboots, but I usually want it to be switched off the next day...
...on the right, and fill in: Name (Example): Turn off DND Command: gsettings set org.gnome.desktop.notifications show-banners true Click "Add" to save. You can then close the "Startup Applications" window...