guides.rubyonrails.org

ActiveRecord offers an explain method similar to using EXPLAIN SQL statements on the database. However, this approach will explain all queries for the given scope which may include joins or...

Output will resemble your database's EXPLAIN style. For example, it looks like this on MySQL: User.where(id: 1).includes(:articles).explain EXPLAIN for: SELECT `users`.* FROM `users`  WHERE...

makandra dev

...an event handler, there are multiple methods to cancel event propagation, each with different semantics. event.preventDefault() Only prevents the default browser behavior for the click, i.e. going to a different...

...url or submitting a form. When invoked on a touchstart event, this also prevents mouse events like click to be triggered. event.stopPropagation() Prevents the event from bubbling up the DOM...

relishapp.com

In RSpec you can tag examples or example groups with any tags you like simply by saying describe ReportCreator, slow: true do # .. end describe ReportCreator do it 'generates reports', slow...

# ... end end You can then only run examples with these tags. rspec --tag slow rspec -t slow # Using the parallel_tests gem rake "parallel:spec[,,--tag slow]"

makandra dev

When RSpecs runs the first feature spec, you may see log output like this: Capybara starting Puma... * Version 6.5.0, codename: Sky's Version * Min threads: 0, max threads: 4

...on http://127.0.0.1:39949 You can disable this behavior by tweaking Capybara's Puma server in your spec/support/capybara.rb: Capybara.server = :puma, { Silent: true } Note You don't need to configure this...

This is a small example on how you can check if your Postgres index can be used by a specific query in you Rails application. For more complex execution plans...

...it might still be a good idea to use the same path of proof. 1. Identify the query your application produces query = User.order(:last_name, :created_at).to_sql

...to read the The framework field guide - Fundamentals, the first of a three part series to learn the basics of frontend technologies. I can highly suggest it for learning the...

...fundamentals. 'The framework field guide' is written by Unicron Utterances and there side has many high quality articles on web development and computer science related to programming. The Framework Field...

makandra Operations
baeldung.com

...measurement metrics in Linux. These are the differences: Code Name Description vsz virtual memory size Total amount of memory a process may hypothetically access. Includes swapped memory, memory from external...

...libraries and allocated memory that’s not used. rss resident set size Total amount of non-swapped used physical memory. Includes memory from external shared libraries. pss proportional share size...

Why string sorting sucks in vanilla Ruby Ruby's sort method doesn't work as expected with special characters (like German umlauts): ["Schwertner", "Schöler"].sort # => ["Schwertner", "Schöler"] # you probably expected...

...Schöler", "Schwertner"] Also numbers in strings will be sorted character by character which you probably don't want: ["1", "2", "11"].sort # => ["1", "11", "2"] # you probably expected...

If you need to convert an SVG source to PS or EPS, the most common suggestion on the interwebs is to use Inkscape from the commandline. Inkscape is a fairly...

...converting is CairoSVG. CairoSVG is available on most Linux distros through their package management systems, e.g. apt install cairosvg on Ubuntu. It has few dependencies (most importantly Python 3 and...

When you have an Angular directive that transcludes content, you might want to do something in case there is no content inside your element, like showing some default content.

...you can not do something like default goes here . Angular will always empty that element's text, even if there is nothing to transclude. But you can use your directive...

Jasmine has long standing support for writing asynchronous specs. In days gone by we used the done callback to achieve this, but these days it is possible to write much...

...more readable specs. Async specs As a first example, say we want to check that some form disables the submit button while working. // bad (how we used to do it...

...core and available in all ruby versions without the need to install anything. This serializes complete ruby objects including id, object_id and all internal state. Marshal.load deserializes a string...

...to an object. A deserialized object cannot be saved to database directly as the the dumped object was not marked dirty, thus rails does not see the need to save...

Finding changes When you're looking for a specific change in Git, there are multiple axes you can choose: git log -- path/to/file lists all commits that touch a file

...log -S some_string lists all commits where "some_string" was added or removed Note that you can do most of these things with Git tools as well, e.g. tig...

...have 2 HTML boxes. The first one has a margin-bottom of let's say 30px and the second one a margin-top of 20px. After rules of collapsing margins...

...too. For example child elements with margins also collapse with margins of the previous sibling of the parent box. Nevertheless there are some exceptions where the behavior of vertical collapsing...

api.rubyonrails.org

ActiveSupport (since 4.1) includes test helpers to manipulate time, just like the Timecop gem: To freeze the current time, use freeze_time (ActiveSupport 5.2+): freeze_time To travel to a...

...specific moment in time, use travel_to: travel_to 1.hour.from_now Important When freezing time with #travel_to, time will be frozen (like with freeze_time). This means that your...

Element finding is a central feature of Capybara. Since #find is normally used to get elements from the current page and interact with them, it's a good thing that...

...some Capybara drivers (e.g. Selenium) will wait an amount of time until the expected element shows up. But if Capybara cannot #find it at all, you'll get an error...

developer.mozilla.org

❌ Bad example Let's take a look at a common example: Clear Search The HTML above is being activated with an Unpoly compiler like this: up.compiler('[filter]', function...

...const queryInput = filterForm.querySelector('[filter--query]') function resetQuery() { queryInput.value = '' queryInput.focus() } up.on('click', resetQuery) }) The Clear search button has three issues: It cannot be focused with the keyboard It cannot be pressed...

makandra dev

...is just awesome. Install via apt-get or brew. Handy commands t ("tree"): Directory-structure based access. You'll see the current directory annotated with the latest change date and...

...date and author. d ("diff"): Like ENTER on a commit, but arrow keys will scroll the diff! /: Search current view (e.g. commit list, diff). Jump to next hit with n...

Don't sum up columns with + in a sql-query if NULL-Values can be present. MySQL and PostgreSQL cannot sum up NULL values with the + value. The sum value...

MySQL: mysql> select 1 + 2 + 3; +-----------+ | 1 + 2 + 3 | +-----------+ | 6 | +-----------+ 1 row in set (0,00 sec) mysql> select 1 + NULL + 3; +--------------+ | 1 + NULL + 3 | +--------------+ | NULL...

...popup on all browsers. When you integrate a date picker popup, remember to also set autocomplete="off" on the text input that opens the calendar on click. Otherwise the autocomplete...

...suggestions will cover the calendar box and make it unusable: If you are using a tool like Unpoly you might want to set autocomplete="off" in the JavaScript that also...

If the project team consists of at least 2 members, do a daily standup. It should not take much longer than 15 minutes. Format Tell everyone else

if there are new developments everyone needs to know about A "still working on X, will probably be done today" is totally fine. No need to tell...

It might sometimes be useful to check whether your Rails application accesses the file system unnecessarily, for example if your file system access is slow because it goes over the...

...or modification times, whereas your application could determine all this from your database. Introducing strace One option it to use strace for this, which logs all system calls performed by...

makandra dev

Sometimes you might want to check a short link for it's destination before clicking on it. Additional you get information about the redirects. Use the magic + at the end...

...of the short url! Google: https://goo.gl/TXe0Kx => https://goo.gl/TXe0Kx+ Since the original publication of this post, Google's URL shortening service goo.gl has been discontinued. Bitly:

Using rem only ever makes sense when the root font size is dynamic, i.e. you leave control to the user. Either by a) respecting their user agent defaults, or...

...by b) offering multiple root font sizes in your application. By defining @media queries in rem, they will accommodate to the root font size of your page. At a larger...