This card compares patterns to store trees in a relation database like MySQL or PostgreSQL. Implementation examples are for the ActiveRecord ORM used with Ruby on Rails, but the techniques...

We will be using this example tree (from the acts_as_nested_set docs): root | +-- Child 1 | | | +-- Child 1.1 | | | +-- Child 1.2 | +-- Child 2 | +-- Child 2.1 | +-- Child 2.2

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

...of pain like me, you can get to Xfce's native window manager by saying: xfwm4 --replace

You are not using javascript tests The file is served from a public folder (not via controller) Problem description If you deliver files from a public folder it might...

...be that the Content-Disposition header is not set. That's why the following spreewald step might raise an error: Then I should get a download with filename "..." expected: /filename...

makandra dev

...Ruby. def and define_method differ in which one they use. def Ruby keyword, starts a method definition Opens a new, isolated scope. Variables defined outside are not accessible inside...

...and vice versa. Defines an instance method on the receiver (specified before the method name, e.g. def object.foo); implicit receiver is the default definee The default definee is not self...

Database connections are not thread-safe. That's why ActiveRecord uses a separate database connection for each thread. For instance, the following code uses 3 database connections: 3.times do

...a new connection end end These three connections will remain connected to the database server after the threads terminate. This only affects threads that use ActiveRecord. You can rely on...

DirectUpload allows you to upload files to your file storage without having to wait for the form to submit. It creates AJAX requests to persist the file within your form...

...and wraps them in a little API. This card will show you how to use it in order to create in-place file uploads with progress and a remove button...

...a request, you want to keep track of how much of the runtime was spent waiting on it, how many calls it took, and the ratio of input to output...

...catches prompt bloat, runaway tool-call loops, and regressions from model changes just by scrolling the log. The same pattern applies to any slow external API you want visibility on...

If you want to know your public key's fingerprint, do this: ssh-keygen -lf ~/.ssh/my.key.pub This may be necessary to authenticate your key on GitHub because of recent events...

...them (to pull etc): ERROR: Hi foobear, it's GitHub. We're doing an SSH key audit. Please visit https://github.com/settings/ssh/audit/... to approve this key so we know it...

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. There are two different ways of "inverting a scope": As an example, consider the following model...

xaprb.com

...result is mutual exclusivity that works in a distributed environment, and it’s dead simple to implement. Ruby implementation An implementation as a Rubygem seems to be with_advisory_lock...

...It has support for MySQL, PostgreSQL and SQLite. Unfortunately, it has a horrible caveat in MySQL: With MySQL (at least <= v5.5), if you ask for a different advisory lock within...

...Rubygems page for your Gem (example). Here are some values you can fill: Gem::Specification.new do |s| s.name = 'my-gem' s.homepage = 'https://github.com/makandra/my-gem' s.metadata = { 'source_code_uri' => s.homepage,

...tracker_uri' => s.homepage + '/issues', 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md', 'rubygems_mfa_required' => 'true', } ...

makandra dev
unpoly.com

A lot has changed for everyone who builds software since our last release. Many of us now write code together with AI agents. This release makes Unpoly work better for...

...can run code through Unpoly callbacks if your CSP allows 'unsafe-eval', if it uses 'strict-dynamic' (which trusts every script that Unpoly inserts), or if you have no CSP...

Browsers come with a set of built-in elements like or . When we need a new component not covered by that, we often build it from and tags. An alternative...

...custom element. Custom elements will be ignored during HTML validation, but their children will still be validated. Styling new elements Browsers will give unknown elements a default style of display...

...update your window title whenever you switch directories, simply specify a PROMPT_COMMAND environment variable. set-window-title() { echo -en "\033]0;$(pwd | sed -e "s;^$HOME;~;")\a" } if [[ "$PROMPT...

...COMMAND" ]]; then export PROMPT_COMMAND="$PROMPT_COMMAND;set-window-title" else export PROMPT_COMMAND=set-window-title fi You may put that into your ~/.bashrc to persist and automatically activate...

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

...as a wildcard for n characters. Overriding the fingerprint from within the application (with the sentry-ruby gem) You can also set a custom fingerprint from within the application:

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

SELECT pg_size_pretty(pg_database_size('some-database')); Example SELECT pg_size_pretty(pg_database_size('cards_p')); ---------------- 13 GB (1 row) SELECT pg_database_size('cards_p');

------------------ 13524832927 (1 row) Related PostgreSQL: Show size of all databases PostgreSQL: How to show table sizes

If you need to implement newsletter sending, rapidmail is a solid option. Support is very fast, friendly and helpful, and the initial setup is simple. Since rapidmail works via SMTP...

...you can simply ask the Ops team to configure SMTP credentials for your application. You also do not need to use rapidmail’s built-in newsletter feature. Instead, you can...

SVG files often contain redundant information, like editor metadata or hidden elements. When esbuild handles your static assets, you can easily optimize SVG files using svgo as a plugin. Here...

...is how to do it. Adding svgo as an esbuild plugin Add the svgo package to your project's package.json Adjust your esbuild.config.js like so: const esbuild = require('esbuild')

...you know from "How to tell ActiveRecord how to preload associations (either JOINs or separate queries)", you can tell ActiveRecord explicitly if it should use a LEFT OUTER JOIN or...

...a separate query to preload associations. Here is some special case, where a simple includes is not possible. For the diagram below we want to sort the rides by the...

Pie sometimes does not properly redraw elements upon changes. This often happens when the change comes from somewhere further up the DOM. Consider something like: Active element Inactive element

li .content { -webkit-box-shadow: #666 0px 2px 3px; -moz-box-shadow: #666 0px 2px 3px; box-shadow: #666 0px 2px 3px; behavior: url(/PIE.htc); background: white; } li.active .content...

...all the world to admire. For private gems this is very bad. To make sure this cannot happen, rubygems 2.2+ allows you to restrict eligible push hosts: Gem::Specification.new 'my...

...gem', '1.0' do |s| # ... s.metadata['allowed_push_host'] = 'https://gems.my-company.example' end In case you already messed up, follow these instructions to get your gem removed. Of course, it's not...

When you create e.g. a sidebar box that contains headlines and paragraphs, the final paragraph's margin in that box will create an undesired 'bottom padding' inside that box.

...is a Sass mixin that you can apply to such boxes. It makes the last child's bottom margin disappear: =hide_last_margin >*:last-child margin-bottom: 0