If the project you're working on has, say, 39 repositories and counting in GitLab and you need all the repos checked out for some reason, here's how to...

...a personal access token for GitLab that has the API permissions. In your terminal, store this key in an env variable. For each group you want to check out:

Sometimes you'll find yourself with a set of tasks that require similar code for different models. For example, if you start working at a new application that allows CRUDing...

...pears and apples, each commit might look similar to this: commit 41e3adef10950b324ae09e308f632bef0dee3f87 (HEAD -> ml/add-apples-12345) Author: Michael Leimstaedtner <michael.leimstaedtner@acme.com> Date: Fri Aug 11 09:42:34 2023 +0200 Add Apples...

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

...the following content: class AddAttachmentToNotes < ActiveRecord::Migration[6.0] def change add_column :notes, :attachment, :string end end Don't forget to rename the class and change the column details to...

...you access http://yourpage.com/system/attachments. 3) Using expiring URLs There are also option to generate self-expiring URLs, which might be a good compromise between performance and safety. It is...

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

relishapp.com

In most projects I know, Cucumber test suite speed is not an issue. Of course, running 350 features takes its time, but still each test for itself is reasonably fast...

...There is nothing you can do to fundamentally speed up such a test (of course, you should be using parallel_tests). However, in projects that go beyond clicking around in...

If you already selected an element and want to get its parent, you can call find(:xpath, '..') on it. To get the grand-parent element, call find(:xpath, '../..'). Example

...href]).to eq("http://twitter.com/") About XPath There is a good overview on XPath syntax on w3schools. But as XPath expressions can get quite complex and hard to understand for...

...updates all your gems at once. Given that many gems don't care about stable APIs, this might break your application in a million ways. To stay sane, update your...

...This ensures that your libraries are up-to-date while it's easy to spot major version bumps which may break the app. Projects that have not been updated in...

bibwild.wordpress.com

...is much more than a lightweight wrapper around Ruby's net/http. In particular: A single HTTPClient instance can re-use persistent connections across threads in a thread-safe way.

...a custom and configurable SSL certificate store (which you probably want to disable by default) Manages cookies Can make asynchronous requests (spins off a thread internally) Allow to set a...

...that's not a float! This occurs because JavaScript uses double precision floats to store numbers. So according to IEEE floating point definition only numbers between...

...and 2^53 - 1 (9007199254740991) can safely be represented in JavaScript. Number.MAX_SAFE_INTEGER will return the largest integer that can accurately be represented. For arbitrary large numbers (even...

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

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

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

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

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

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

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

...an error if your application logic ever violates it. class User < ApplicationRecord has_one :session, dependent: :destroy end class Session < ApplicationRecord belongs_to :user end create_table :users do |t...

end create_table :sessions do |t| t.references :user, null: false, foreign_key: true, index: { unique: true } # Don't forget the uniqueness here t.timestamps

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

makandra dev

...instead of using the UI or creating records in the Rails console. This approach saves time and gives you useful defaults and associations right out of the box.

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={}>]

Cucumber up to version 2 had a neat feature called Step Argument Transforms which was dropped in favor of Cucumber 3 ParameterTypes. While I strongly encourage you to drop your...

...keep the exact same functionality of your old Transforms while writing them in the style of new ParameterTypes. Why would I want to keep my Transforms? Transforms allowed you to...

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

puppet.com

...agent manually. Example: # exec resource: exec { "update_rubygems_${user}_${version}": command => "${home}/.rbenv/shims/gem update --system ${version}", unless => "${home}/.rbenv/shims/gem -v | /bin/grep ${version}", } This does execute rbenv commands. If puppet runs...