If you want to see how long your database queries actually take, you need to disable MySQL's query cache. This can be done globally by logging into a database...
SET GLOBAL query_cache_type=OFF; and restart your rails server. You can also disable the cache on a per query basis by saying SELECT SQL_NO_CACHE...
...open a dialog with the route to your dialog's view. tinymce.init({ // ... toolbar: 'myCustomButton', setup: function(editor) { editor.ui.registry.addButton('myCustom Button', { icon: 'document-properties', tooltip: 'Further describe your button here', onAction...
...insertContent', content: linkTag, }); window.parent.postMessage({ mceAction: 'insertContent', content: ' ', }) window.parent.postMessage({ mceAction: 'close' }); }) function buildLinkTag(form) { // do stuff } }) See here for more commands...
Similar to the Webpack Bundle Analyzer, Chrome's new Lighthouse feature … … shows a visualisation of your JavaScript bundles. It's compatible with sourcemaps and is great for understanding large JavaScript...
...in development. It also works on production code, where its usefulness depends on the structure of the productive Javascript code. Warning This will only work when your bundler emits source...
Chromedriver (or selenium-webdriver?) will not reliably scroll elements into view before clicking them, and actually not click the element because of that. We've seen this happen for elements...
...a 40px button). Our assumption is that the element is considered visible (i.e. Capybara::Selenium::ChromeNode#visible? returns true for such elements) but the Selenium driver wants to actually click...
The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...
...this example we are using %s identifier to replace strings. class Fetcher FIND_URI = 'https://someapi.com/3/search/record?query=% s&include_many=% s&language=en-US&page=1' # some public methods
Sometimes you want to write a test for a business rule that's based on multiple variables. In your goal to cover the rule thoroughly, you start writing tests for...
...each permutation of all variables. Quickly it blows up into something unsustainable. With n variables for the business rule, you get 2n permutations/test cases. This is manageable with 2 variables...
...version understands? Did you double-check your @font-face declarations with all the hacky syntax that is required? Compare them with other declarations you find on the web.
...same name? This usually leads to trouble, but there are workarounds. Do IE's security settings prevent the download of webfonts? (see below) IE Security Settings can prevent font download...
You have an async function that rejects: async function failingFunction() { throw new Error("Something went wrong") } When you call that function in a test, your test will fail:
}) The failure message will look like this: Unhandled promise rejection: Error: Something went wrong You can fix this by expecting the state of the returned promise:
...in "Comment" with: """ This is a long comment. With multiple lines. And paragraphs. """ The step definition is part of the spreewald gem
...what git checkout and git reset do. Git basics A commit holds a certain state of...
...a directory and a pointer to its antecedent commit. A commit is identified by a so-called ref looking something like 7153617ff70e716e229a823cdd205ebb13fa314d. HEAD is a pointer that is always pointing...
In CI test runs I noticed that string sorting order changed after switching from a debian-based PostgreSQL docker image to one that is based on Alpine Linux.
...sorting: bar Bar foo Foo Alpine image sorting: Bar Foo bar foo Explanation Alpine Linux is a very slim linux distribution that results in small docker image sizes (roughly 100MB...
Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for...
Git can help you to find the next git tag that was set in the branch. This usually has the name of the version in it (as the...
Sometimes you may want to print files from the command line, especially when you have lots of them. You can use lp for that. To print a single example.pdf file...
...on your default printer, simply say: lp example.pdf lp accepts multiple filenames, so to print all PDF files in the current directory: lp *.pdf You can specify a printer via...
See the attached link for a useful overview of modern (and classic) DOM API methods, like matches, contains, append, cssText, etc. You will still need to look up some documentation...
...e.g. on how to modify a ClassList, but it's still better than browsing interfaces and superclasses of Element on MDN without knowing what to look for. When coming from...
Just found out about a great feature in Rails that seems to be around since Rails 2. Start a console with the --sandbox (or -s) parameter: rails console --sandbox
...database will be rolled back on exit. Warning Changes beyond the database (deleting files, sending emails, etc) cannot be rolled back...
Web forms can be made much more usable with a few HTML attributes. Short summary: type: Tells browsers about the input data type. Mobile browsers will select a virtual keyboard...
...based on this value. Some browsers will add simple validation, e.g. for type email. inputmode: Direct hint about the virtual keyboard to use. Inferred from type, but can be very...
If you're on Ruby 2.3+ there's a <<~ operator to automatically unindent HEREDOCs: str = <<~MESSAGE Hello Universe! This is me. Bye! MESSAGE If you have an older Ruby, you...
...can use the String#strip_heredoc method from ActiveSupport. See Summarizing heredoc in ruby and rails for an example. Technically, it looks for the least indented line in the whole...
...you want to clean up this code with the modularity gem, you might try something like this: class Foo does 'bar' end module BarTrait as_trait do class Bar
...you would have to change all references accordingly, which is quite unpleasant. You can solve it like that: module BarTrait as_trait do class self::Bar end end end
...file download links in an end-to-end test can be painful, especially with Selenium. The attached download_helpers.rb provides a download_link method for your Capybara tests. It returns a...
details[:disposition] # => 'attachment' or 'inline' details[:filename] # => 'report.txt' details[:text] # => file content as string details[:content_type] # => 'text/plain' Features Compared to other approaches this helper has many useful features...
...a web developer, you know Google Analytics (GA). Probably you've dropped the GA snippet into more than one website, maybe you've even used its Javascript API to implement...
...configurable without changing anything in the application's code base (and much more beyond, see below). Only prefer GTM if the customer requests it, or if he is updating his...
...flaky tests. You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist the result of your test runs to a file. This is...
...necessary to be able to rerun examples. Add this to your spec/spec_helper.rb : config.example_status_persistence_file_path = 'spec/examples.txt' Rerun all failed examples using --only-failures bundle exec rspec --only-failures...
...lot less than you think. "private" does not apply to class methods defined on self This does not make anything private: class Foo private def self.foo 'foo' end end
...need to use private_class_method instead: class Foo def self.foo 'foo' end private_class_method :foo end "private" does not apply to define_method This does not make anything...
...to accept nested attributes for a record that is not an association, e.g.: class Site < ActiveRecord::Base def home_page @home_page ||= Page.find_by_name('home') end does 'accept_nested...
...attributes_for_member', :home_page end It has some limitations: Only works for singular member references ("belongs to"), not for a collection of references ("has many") No support for deletion...
You can use three different versions of the regular expression syntax in grep: basic: -G extended: -E(POSIX) perl: -P (PCRE) Difference between basic and extended: In basic regular expressions...
...the meta-characters '?', '+', '{', '|', '(', and ')' loose their special meaning; instead use the backslashed versions '?', '+', '{', '|', '(', and ')'. Difference between extended (POSIX) and perl (PCRE): E.g. \d is not supported in POSIX.