...has a very different disk usage on it's nodes you can use these steps to rebalance the shards. Attention Before we begin it's important to understand how Elasticsearch/OpenSearch...
...defines balance: The balance of the cluster depends only on the number of shards on each node and the indices to which those shards belong. It considers neither the sizes...
...be a quick fix for an existing app. It also ensures that future uploaders get safe-ish defaults when the developer forgets to define an allowlist for concrete uploaders (see...
...you can also go with this more relaxed CSP: Content-Security-Policy: default-src 'self'; script-src 'none'; object-src 'none' While this does not fix users uploading executables etc...
...full-app localization before and assign an hour estimate to each of these points. Static text Static strings and template text in app must be translated: Screens, mailer templates, PDF...
...templates, helpers, sometimes models. Use the native Rails I18n API. Avoid Gettext if possible. Native I18n has good integration with Rails (you already have it!), but you need to come...
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...
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...
...more complicates it is easier to understand and to process. Note: In case a string does not match the pattern, .match will return nil. With Ruby 2.4 the result of...
...transformed to a Hash with named_captures. This allows you to use methods like slice or fetch on the result. Example with a multiple assignment PRODUCT_PATTERN = /\A(.+) S\/N...
...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...
...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
TypeScript basically uses structural typing, which is conceptually quite similar to duck typing, but with static compile-time type checking. We'll explore what this means in practice.
...a superset of JavaScript, meaning TypeScript compiles down to native JavaScript syntax and checks type consistency only at compile time. Idea of Structural Typing TypeScript only wants to know whether...
...but does not have to be. It's actually very easy when done right. Summary (tl;dr) Here's the short version: Define a table_name_prefix method in the...
...not define any table_name_prefix in ActiveRecord classes inside of it. If this sounds familiar, we have a card about using it already. This card explains why you want...
...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...
...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...
...this matter, as the image rendering depends on multiple factors. At least the operation system, browser or image viewer software and monitor influence the resulting image colors on your screen...
...possibility to upload images, they will most likely contain tons of EXIF metadata and sometimes exotic color profiles like eciRGB. We want to get rid of the metadata, as it...
Sometimes you want git to ignore certain files that appear on your machine. You can do this in 3 ways: Per project, in the project's .gitignore file
Downsides of per-project .gitignore entries While it might be tempting to set it per project (other devs might benefit from it), you need to do it each...
Migrating data from a legacy into a new system can be a surprisingly large undertaking. We have done this a few times. While there are significant differences from project to...
...project, we do have a list of general suggestions. Before you start, talk to someone who has done it before, and read the following hints: Understand the old system
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...
Jasmine specs for the frontend often need some DOM elements to work with. Because creating them is such a common task, we should have an efficient way to do it...
...Let's say I need this HTML structure: item 1 item 2 This card compares various approaches to fabricating DOM elements for testing. Constructing individual elements While you can use...
...intrinsic width of your content play together. The attached article explains the differences. In summary: If a flex-basis is set, that is used as the basis
...basis is set, the width is used as the basis If neither flex-basis nor width is set, the content's computed width is used as the basis
This is an attempt to list some of those things: On the server Always optimize: Don't do stupid things with the database. Avoid "n + 1" queries. Don...
...Use form models. Optimize on demand: Don't optimize without knowing what's actually slow. Measure first, for example by using a performance monitoring tool like NewRelic, Scout, AppSignal, Skylight...
...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...
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...
This is a presentation from 2019-01-21. Summary We want to move away from jQuery in future projects Motivations are performance, bundle size and general trends for the web...
...can polyfill the missing pieces Unpoly 0.60.0 works with or without jQuery Is jQuery slow? From: Sven To: unpoly@googlegroups.com Subject: performance on smartphones and tablets Hello I just used your...
...cases beyond that to make your life easier. For this cheatsheat I tried to structure the most useful commands by different use cases, such that a practical oriented overview of...
...some commands I added some tips for their usage and further details on their subcommands For most of the commands shortly explained here, there are some examples along with a...
By default, Rails views escape HTML in any strings you insert. If you want to insert HTML verbatim, you need to call #html_safe. However, #html_safe does not "unescape...
...a string. It merely marks a string as safe for unescaped insertion. How html_safe works Calling html_safe on a String returns a new object that looks and acts...