...and Redis.current=: `Redis.current=` is deprecated and will be removed in 5.0. If your application still uses Redis.current, you can only fix it by no longer using it. Here is how...

...There is probably already a constant like REDIS_URL that you use to configure Sidekiq or similar. So just use that one. redis = Redis.new(url: REDIS_URL) redis.get('example') # instead...

...you store files for 500k records, that store_dir's parent directory will have 500k sub-directories which will cause some serious headaches when trying to navigate the file system...

...still only have 500 directories inside /app-root/public/users/avatar/. And inside each of them, at most 1000 sub-directories. But I have millions of files If you expect to store a lot...

It's possible to implement simple custom RuboCop cops with very little code. They work exactly the same like existing rubocop cops and fail the pipeline if they find an...

...offense. This is handy for project specific internal rules or conventions. The following cop looks at every ruby file and searches for TODO or WIP comments and adds an offense...

...automatically. If you delete records regularly, this may be an annoyance. Here is a solution which was adapted from the Carrierwave GitHub wiki and cleans up any empty parent directories...

class ExampleUploader < CarrierWave::Uploader::Base storage :file after :remove, :remove_empty_container_directory def store_dir # You implemented this in your uploaders already. end def remove_empty...

Let's say you want to find the element with the text hello in the following DOM tree: hello world You might think of XPath's contain() function: page.find(:xpath...

...contains(text(), 'hello') and not (./*[contains(text(), 'hello')])]") With jQuery jQuery has a custom selector :contains() that you can use in the same fashion: $(":contains('hello'):not(:has(:contains('hello...

Compiling Sass is probably the slowest part of your build, so this is worth a try if you're using Sass...

...If you're using the sass npm package to compile your SASS/SCSS, consider switching to sass-embedded. It should be a drop-in replacement in a large app and it...

The Web Animations API has great browser support, and you should be using it to animate DOM elements from JavaScript, or to control or wait for CSS animations.

...Its API probably a bit different from how your favorite frontend framework animates, but simple enough to get used to. Like for CSS animations, you specify keyframes to animate. This...

sitepoint.com

$number = $length / 1px // => 13 Converting a unit the result of an addition or subtraction between two numbers of different units is expressed in the first member’s unit

...the desired unit: $duration: .21s $duration-in-milliseconds: 0ms + $duration // => 210ms An example is storing a transition duration as CSS custom property to read it from Javascript. By converting the...

makandra dev
developer.mozilla.org

The standard way to abort async code is that your function takes a AbortSignal { signal } property. The caller can use this signal to send an abort request to your function...

...with a new DOMException('Message here', 'AbortError') when canceled. This already has good browser support and can be polyfilled on older browsers. Example Here is an async function countDown(). It...

When filling out forms in Selenium tests, Chrome shows the (usual) bubble, asking to store those credentials. While the bubble does not interfere with tests, it is annoying when debugging...

...tests. Here are two ways to disable it: Option 1: prefs You can set profile preferences to disable the password manager like so: prefs = { 'credentials_enable_service' => false, 'profile.password_manager...

makandra Curriculum

...rules for Rails Beautiful controllers Relearning ActiveRecord User interactions without a database Creating a system for growth Dealing with fat models A home for interaction-specific code Extracting service objects...

...As naming convention when extending models with ActiveType::Record[User]. Instead just pick whatever substantive best describes the extended class. Note that we prefer the verbose notation of parent namespaces...

nolanlawson.com

In my experience, the most common sources of memory leaks are APIs like these: addEventListener. This is the most common one. Call removeEventListener to clean it up. setTimeout / setInterval. If...

...you create a recurring timer (e.g. to run every 30 seconds), then you need to clean it up with clearTimeout or clearInterval. (setTimeout can leak if it’s used like...

When you send automated emails from a noreply@-address, and the recipient has an out of office enabled, the autoreply bounces and they get an additional email with an error...

...To prevent the recipient's auto-response and the following error message you can set the email header Auto-Submitted: auto-generated in your mailer, for example like this:

rspec.info

...group using Ruby's def keyword or define_method method: describe "example" do def sum(a, b) a + b end it "has access to methods defined in its group" do...

...expect(sum(3, 4)).to be(7) end end The helper method is also available to groups nested within that group. The helper method is not available to parent or...

If you have a single node elasticsearch instance and indices with replicas enabled your cluster state will be yellow. If you have replica shards they should be moved to a...

...different node for high availability purposes. With a single node this can't be accomplished. So you either build a ES cluster or you disable the replicas. Building a cluster...

...some beyond 50MB. Unless you need to offer this large files, you should always shrink uploaded files to a reasonable resolution. class ImageUploader < CarrierWave::Uploader::Base process resize_to_limit...

Our preferred way of testing ActiveRecord is to simply create/update/destroy the record and then check if the expected behavior has happened. We used to bend over backwards to avoid touching...

...the database for this. For this we used a lot of stubbing and tricks like it_should_run_callbacks. Today we would rather make a few database queries than have...

...the cogwheel icon (or press F1 when focusing the dev tools) to open the settings overlay. Under "Preferences", in the "Appearance" section, find the "Panel layout" option. Set it to...

Alternatively, press Ctrl+Shift+P and search for "panel layout". Wat? Vertical means that the DOM tree is next to the styles/etc panel, like so:

github.com

...to lock a user in devise. Using the lockable module Customizing the user account status validation when logging in. It depends on your requirements which methods works best.

...user on soft delete We recommend to use option 2 when you want to couple the lock to the model's soft delete logic. Option 1 might also work when...

To query for identical arrays independent of their order you have to either: Sort both the query and database content. If you're on Rails 7.1 you can use...

...the new normalizes macro for this. This solution would still use any indexes on the column. Check for inclusion in both directions, as implemented by the where_array_matches method...

If validations failed for a record, and you want to find out if a specific validation failed, you can leverage ActiveModel's error objects. You rarely need this in application...

...name (e.g. :blank for :presence, :taken for :uniqueness). You may also use where to see all errors of an attribute: >> user.errors.where(:email) => [#<ActiveModel::Error attribute=email, type=blank, options={}>]

In interactive commands, Git allows the user to provide one-letter input with a single key without hitting enter (docs). # Enabled this feature globally git config --global interactive.singlekey true

...enable this feature locally for a single repository git config interactive.singlekey true This allows you to hit "y" instead of "y + ENTER" to move to the next hunk.

A page scanned upside down or sideways has the potential to confuse OCR engines and vision LLMs. While both are often capable of handling such inputs, the overall extraction quality...

...Detecting and correcting the image orientation does not require extra hardware on our web servers, it just adds a bit of complexity to the overall pipeline. Approach Tesseract ships with...

The functions below pack your current work (diffs, full repos, or specific commits) into XML/Diff files, which are then load into your clipboard as File Uploads. My...

nvm exec 22 npx repomix@latest \ --ignore "$dyn_ignores" \ --output "$out_dir/$base_name.xml" \ --split-output "2mb" \ --quiet local files=() if compgen -G "$out_dir/$base_name*.xml" > /dev/null...