In Rubocop you might notice the cop Style/CaseEquality for e.g. this example: def foo(expected, actual) expected === actual end In case expected is a Regex, it suggests to change it...

...foo(expected, actual) expected.match?(actual) end In case expected is a Regex or a String, you need to keep ===. Otherwise the actual expression is always converted to a regular expression...

When you want to filter records in a model where a string column roughly matches a given term, you can use PostgreSQL’s trigram similarity search. Writing a fuzzy query...

User.where("similarity(name, ?) > 0.3", "John") This finds all users where the name is similar to "John" with a similarity score above 0.3. You can tune the threshold:

To update your Rubygems to the latest available version, type the following: gem update --system Note that you have a separate Rubygems installation for each Ruby version in your RVM...

...or rbenv setup. Updating one does not update the others. Ruby 1.8.7 If you are using Ruby 1.8.7 you cannot use the latest version of Rubygems. Type the following to...

makandra dev

This card shows you how to format a card's content using Markdown. We use the Commonmarker interpreter, so here are examples for its dialect. Formatting **Bold** Bold _Italics_

Add a new line for a paragraph. Headlines Underline headlines with an equals sign or dash -- or start a line with a hash symbol: Hello World ----------- Lorem ipsum...

to create a Gallery that has a name and has_many :images, which in turn have a caption to offer the user a single form to create...

...with any number of images immediate uploads with a progress bar per image a snappy UI Enter jQuery File Upload. It's a mature library that can do the job...

developer.mozilla.org

Container queries enable you to apply styles to an element based on the size of the element's container. If, for example, a container has less space available in the...

...surrounding context, you can hide certain elements or use smaller fonts. Container queries are an alternative to media queries, which apply styles to elements based on viewport size or other...

When you need to see the content of a page (i.e. not all the HTML but the relevant text body) you can do pp (html_content) pp will format the...

...html String human readable pretty printed where html_content can be replaced by one of the following commands: Rails body or response.body Capybara: page.driver.html.content page.body Webrat: Nokogiri::HTML(response.body).content...

...a remote API, check out the VCR gem as an alternative to Webmock or stubbing hell. The idea behind VCR is that is performs real HTTP requests and logs the...

...in a .yml file. When you run the test again, requests and responses are stubbed from the log and the test can run offline. It's a great way to...

Rails comes with a Rake task notes that shows code comments that start with "TODO", "FIXME", or "OPTIMIZE". While it's generally not good practice to leave them in your...

...not yet available. To keep track of them, run rake notes. Its output looks something like this: $ rake notes app/controllers/frontend/media_documents_controller.rb: * [ 6] [TODO] should be part of a publication workflow app/helpers/frontend/slider_helper.rb...

...messages should include the ID of the issue your code belongs to. Our preferred syntax prefixes the issue title with its ID in brackets, e.g. [FOO-123] Avatars for users...

...When I go to the dashboard And console Then I should see "Hans Peter" AfterStep @slow-motion Waits 2 seconds after each step Example: @slow-motion Given there is a...

When I go to the dashboard Then I should see "Hans Peter" AfterStep @single-step Waits for a keypress after each step Example: @single-step Given there is...

...with modern CSS features In the past, you might have resorted to bulky JavaScript solutions or CSS hacks like transitioning between max-height: 0 and max-height: 9999px. All of...

...them were awkward and/or have several edge cases. With modern CSS, there is actually a way to do it properly: Just use a display: grid container which transitions its grid...

github.com

If you have ... an object that defines to_hash (may well be a simple Hash instance) and pass it to a method with optional arguments and keyword arguments

...it is not set as the first optional argument. Instead, Ruby calls to_hash on the object and tries to match the result to keyword arguments. If the hash contains...

makandra dev

gem install foobar --version="=2.3.0.alpha2" Also bundle update will never update a stable version to a pre-release version unless the user explicitly requests it in the Gemfile...

...gem 'foobar', '=2.3.0.alpha2' A note on Semantic Versioning Semantic Versioning has a naming convention for pre-releases that is incompatible with that from RubyGems. In Semantic Versioning, the version...

When you do a bitwise copy using the dd tool you will not see any output until it completes or an error occurs. However, you can send a command signal...

...to the process to have it show its progress so far. From another terminal, simply call (be root or use sudo): pkill -USR1 dd This makes dd write something like...

You can scale background images in CSS to the container size using background-size (Demo). Commonly, we use contain or cover because we want to preserve the image's aspect...

If you do not want to do that, simply provide scaling values for X and Y: background-size: 100% 100% (a simple 100% would mean 100% auto and respect...

When you need to store structured data (like Ruby hashes) in a single database column with ActiveRecord, a simple way is to use PostgreSQL's jsonb columns. ActiveRecord will automatically...

...serialize and deserialize your Hash to and from JSON, and you can index JSON paths for fast reads. As an alternative, ActiveRecord::Store offers a way to store hashes in...

jQuery's deferred objects behave somewhat like standard promises, but not really. One of many subtle differences is that there are two ways to chain callbacks to an async functions...

...is done, which only exists in jQuery: $.ajax('/foo').done(function(html) { console.debug("The server responded with %s", html); }); There is also then, which all promise libraries have:

...need to use XPath, you can have Nokogiri help you out on creating it. Simply use Nokogiri's xpath_for: Nokogiri::CSS.xpath_for('#foo') # => ["//*[@id = 'foo']"] Nokogiri::CSS.xpath_for('#foo...

...bar:nth-of-type(2)') # => ["//*[@id = 'foo']//*[contains(concat(' ', @class, ' '), ' bar ') and position() = 2]"] Since XPath is more powerful you may still need to do some hardcore XPath hacking eventually...

Fresh Chrome installations now show a "Choose your search engine" popup in Europe. This might make your Cucumber tests fail. Fortunately there is a flag to disable the popup. Add...

...the following option to your chromedriver setup code: options.add_argument('--disable-search-engine-choice-screen') I found this flag in Peter Beverloo's list. Background: This was experienced locally with...

Boot partitions from installations prior to the 16.04 era are terribly small. When you install updates and encounter errors due to a full /boot partition, consider risizing it.

...can't do the steps described below, ask someone experienced to help you out. This has worked 100% so far. 1 out of 1 tries. ;) Scenario A: There is unassigned...

...take the content-box for the element's shape, i.e. without margin, padding and border. shape-outside: content-box Set the margin where you want it, e.g. 10px left and...

Set the shape-margin to the same size as the margin. Note that the shape-margin can never exceed the (rectangular) margin-box of an element! --margin: 10px;

You can say: $(element).is(':visible') and $(element).is(':hidden') jQuery considers an element to be visible if it consumes space in the document. For most purposes, this is...

Emulate jQuery's implementation : element.offsetWidth > 0 && element.offsetHeight > 0; jQuery > 3 Query 3 slightly modifies the meaning of :visible (and therefore of :hidden). Emulate jQuery's implementation: !(window.getComputedStyle(element...

In Rails 3.1+, instead of defining a separate up and down method you can define a single method change: class AddComparisonFieldsToReport < ActiveRecord::Migration def change add_column :reports, :compare, :boolean...

...update "UPDATE reports SET compare = #{quoted_false}" add_column :reports, :compare_start_date, :date add_column :reports, :compare_end_date, :date end end Migrating up works as expected: