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...
...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...
When you need the DOM node of a tag (e.g. to read extra attributes, or to modify the DOM near it), you can usually reference it via document.currentScript. However, document.currentScript is unsupported in ancient browsers, like Internet Explorer 11 or wkhtmltopdf's Webkit engine. If you are not running async scripts, you can easily polyfill it: document.scripts[document.scripts.length - 1] It works because document.scripts grows with each tag that was evaluated. That is also the reason why this solution will not work reliably for async code. Demo: https://codepen.io/foobear/pen/poRLxQm
...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', } ...
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...
...you to find a parental element using CSS or XPath. If you previously did something like this: field.find(:xpath, './ancestor::div[contains(@class, "form-group")]') ..and prefer CSS, you may...
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:
...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...
...you read this file with the Nokogiri default (DOM) parser, it creates a tree structure with all branches and leaves. It allows you to easily navigate through it via css/xpath...
The only problem is that if you read the whole file into memory, it takes a significant amount of RAM. It is really ineffective to pay for a server...
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...
The shell variable PS1 holds your bash prompt. You might want to change it to serve your needs best. Here is how to: General non-printing escape sequences in your...
=> ✔ mycomputer ~/projects/platforms master > _ # Arne's epic timestamped prompt with return status indicator and status-colored (green if fresh, or red if unstaged, or yellow if staged) git branch:
...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...
...by default, effectively allowing anyone to upload an unlimited amount of files to your storage. The DirectUploadController from @rails/activestorage bypasses your form controller because it uploads the file using an...
...AJAX request that runs directly, before any form roundtrip happens. This is a comfortable solution to allow in-form uploads with progress, errors etc. Otherwise, the file would be uploaded...
...Saving files to a directory that is not shared between deploys or servers If you save your uploads to a made up directory like "RAILS_ROOT/uploads", this directory goes away...
...after every deploy (since every release gets a new). Also this directory is not shared between multiple application servers, so your uploads are randomly saved to one local filesystem or...
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...
git checkout is the swiss army of git commands. If you prefer a semantically more meaningful command for restoring tasks, use git restore instead. With this command you...
... do unstaging - git restore --staged ... discard staged changes - git restore --staged --worktree ... discard unstaged changes - git restore ... restore deleted files - git restore ... restore historic versions - git restore --source
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
...babysitting Claude Code (default mode) and giving the LLM a loaded gun (bypassPermissions / --dangerously-skip-permissions). When the agent proposes a tool call that requires confirmation, a secondary Claude instance...
...receives it to decide whether to confirm or deny: Generally speaking, reversible, reading commands like git diff are allowed while irreversible commands like an rm -rf are prevented.
Getting parseable output back from an LLM has two halves: shaping the request, then parsing the response. Even with Ollama's format: parameter set, models leak conversational preamble like Sure...
Message types Ollama's chat endpoint takes a messages array with four roles: system, user, assistant and tool. The following message pattern works well for us: one system message...
...building a web application, one is tempted to claim it "done" too early. Make sure you check this list. Different screen sizes and browsers Desktops, tablets and mobile devices have...
...state while requests are loading. If you cannot implement this for every interaction, focus on slow-loading links and forms. Use Responsive Images to give each user only the image...
Hybrid search runs a vector query and a keyword query in parallel against the same documents and merges the two ranked search results. Reach for it once either approach alone...
...performs better with extracted keywords ("parental leave department"), unless you have a very elaborate analyzer (stop-word filter, stemming, language-aware tokenization, etc.). Document and Query Embeddings need different instructions...
When you want to find out the data type of an attribute, you can just use ActiveRecord's columns_hash...
...it's present inside the first 4k of you page. If you put it somewhere in the bottom of your head section (or in the body) move it to top...
...UA-Compatible is ignored if it's put inside IE conditional comments. Also, you shouldn't have any text before the doctype declaration. If you've got any HTML comments...