...project, as a developer you need to follow the following guidelines (e.g. by using something like this issue checklist template). In order to reduce the number of rejects we get...

...from clients, we want to review all code written before it goes to the staging server. Note: This process is tailored to our specific needs and tools at makandra. While...

The Node Version Manager allows installing multiple NodeJS versions and switching between them. By default, it does not automatically switch versions when entering a directory that holds a .nvmrc file...

...COMMAND feature. So here is my take on it. Note that it is much shorter, it probably does a few less smart things, but has been working great for me...

These steps are now part of Spreewald. The step definitions below allow you to test the filename suggested by the server: When I follow "Export as ZIP"

...absence of error end end end Standard validations can be tested with less code The shoulda-matchers gem gives you some RSpec matchers to test the application of standard Rails...

...validations. Under the hood should-matchers uses the same recipe as outlined above (set invalid state, run validations, check for message, etc.), but your tests will have a lot less...

Sometimes you want to find the inverse of an ActiveRecord scope. Depending on what you want to achieve, this is quite easy with Rails 7, and a bit more complicated...

...with Rails 6 and below, or when the inverse scope may contain NULL values. [1] There are two different ways of "inverting a scope": As an example, consider the following...

Rails has configurable time zones, while Ruby is always in the server's time zone Thus, using Ruby's time API will give you wrong results for...

...zones, because their existence is a fact. You can, however, tell Rails the only single time zone you'll need is the server's. config.time_zone = "Berlin" # Local time zone...

Sentry offers a UI to define custom fingerprint and stack trace rules at https://sentry.io/settings/projects/$project-id/issue-grouping. Fingerprint rules have this syntax: 1 or more key:value conditions, followed by...

...exception(self, fingerprint: [self.class.name]) end end Overriding the fingerprint from within the application (with the sentry-ruby gem) You can also set a custom fingerprint from within the application:

makandra dev

...partial template. # _weather.html.erb The weather is <%= condition %> # index.html.erb render partial: 'weather', locals: { condition: 'good' } Since this is a common use-case, there's a shorthand way of rendering the partial...

...Notice that it's not possible to mix the explicit partial: 'template' and the shorthand arguments for defining local variables. So either use longform variant or the shorthand variant, but...

...good to know them all, but we recommend Option 0 or Option 1. Option 0: Sub-query with conditions from a scope You may also pass the existing User.active scope...

...the joined table: Post.where(user: User.active) This will make a single query. It uses a sub-query, which is slow in MySQL, but fast in PostgreSQL: SELECT * FROM posts WHERE...

makandra dev

...features, this concept might be confusing for developers who have been programming in more static languages, such as Java or C#. This card should help understanding the basic concepts of...

...you might think of a "container" that holds metadata, variables and methods. Metadata describes stuff like the object's class or its object_id which uniquely identifies it. From an...

Speaker today is Henning Koch, Head of Development at makandra. This talk will be in German with English slides. Introduction As web developers we work with JavaScript every day, even...

...that inherits all properties form User's // child prototype and may then be extended with Student-specific methods. Student.prototype = Object.create(User.prototype) Student.prototype.isEnrolled = function() { return typeof this.studentNumber === 'number' }

Note: Modern Rails has two build pipelines, the asset pipeline (or "Sprockets") and Webpacker. The principles below apply for both, but the examples shown are for Sprockets.

...your application uses many assets, such as images, javascripts and stylesheets. Without your intervention, the browser will request these assets again and again on every request. There is no magic...

...external commands from within Ruby, but the most powerful ones are Open3.capture3 and Open3.popen3. Since those can do almost everything you would possibly need in a clean way, I prefer...

...to simply always use them. Behind the scenes, Open3 actually just uses Ruby's spawn command, but gives you a much better API. Open3.capture3 Basic usage is require 'open3'

mysqlperformanceblog.com

MySQL will use the index when your query is well-formed: mysql> EXPLAIN SELECT * FROM users WHERE email = 'foo@example.com'; +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len...

...ref | rows | Extra | +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+ | 1 | SIMPLE | users | const | index_users_on_email | index_users_on_email | 768 | const | 1 | | +----+-------------+-------+-------+----------------------+----------------------+---------+-------+------+-------+ However, indexes are not used if you are passing incorrect data types...

makandra dev

...to load fast it's recommended to optimize images. Ideally an image's file size should be as small as possible while still being of decent quality. This card demonstrates...

...tools for image optimization Use identify to fetch information about pictures. convert can change size/quality and strip meta information. Both commands are supplied by ImageMagick. $ identify in.jpg in.jpg JPEG 294x440...

...response includes caching headers like Expires or Cache-Control, their validity depends on the server's Date header if present. Otherwise, the browser uses its local time. This can lead...

...for authentication. The cookie for this feature might include an Expires attribute, specifying its validity: Set-Cookie: remember_me=abc123; Expires=Fri, 15 Dec 2023 12:00:00 GMT

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

By default parallel_tests will spawn as many test processes as you have CPUs. If you have issues with flaky tests, reducing the number of parallel processes may help.

...Flaky test suites can and should be fixed. This card is only relevant if you need to run a flaky test suite that you cannot fix for some reason. If...

makandra dev
makandracards.com

...have a README that gives the reader a quick overview of the project. Its size will vary as projects differ in complexity, but there should always be some introductory prose...

...for a developer to read when starting on it. Purpose That's already the main purpose of a project README: Give a new developer a quick overview of the project...

Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and code from gems might use one or the other.

Your life will be easier if your application does not need to support time zones. Disable them like this: config.time_zone = 'Berlin' # Your local time zone config.active_record.default_timezone...

This raises "Could not find first Keyword": describe Keyword do it { should validate_uniqueness_of(:text) } end Do this instead...

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

makandra Curriculum

...debugging console if developer tools are already open. Do this. Note that since JavaScript is single-threaded, you cannot interact with your app's frontend while the debugging console is...

...inspect the current DOM. In a @javascript scenario, observe the current frontend state in the Selenium-controlled browser. If you run E2E tests in headless Chrome, you may need to...

makandra dev

...following places and uses the first implementation it finds: Methods from the object's singleton class (an unnamed class that only exists for that object) Methods from prepended modules (Ruby...

...from the object's class Methods from included modules Methods from the class hierarchy (superclass and its ancestors) Example Let's say we have the following class hierarchy: class Superclass...