A recent patch level Ruby update caused troubles to some of us as applications started to complain about incompatible gem versions. I'll try to explain how the faulty state...

...care of a few things: The new Ruby version is installed The Bundler version stated in the Gemfile.lock is installed Geordi is installed (for database dumps) The gems of the...

Whenever you have to deal with randomness in a jasmine test there are some spy strategies to help you out! Let's say we have a method Random.shuffle(array) to...

...shuffle an array randomly and a class that uses shuffle within the constructor. returnValue & returnValues it('shuffles the array', () => { spyOn(Random, 'shuffle').and.returnValue([3, 2, 1])

...for an option like Yarn's --frozen-lockfile which validates that. Here is what seems to be the way to do it. Using npm clean-install Running npm clean-install...

...versions while npm clean-install will complain. You can use npm ci as a shortcut for npm clean-install. Combine with a cache The idea of a "clean install" is...

When using Rails to truncate strings, you may end up with strings that are still too long for their container or are not as long as they could be. You...

...did not use it. Since Firefox 7 you can! Note that this only works for single-line texts. If you want to truncate tests across multiple lines, use a JavaScript...

To set a cookie in your test browser for cucumber tests, you need to know which driver you are using. Use the step below according to your driver.

...to "([^\"]+)"$/ do |key, value| headers = {} Rack::Utils.set_cookie_header!(headers, key, value) cookie_string = headers['Set-Cookie'] Capybara.current_session.driver.browser.set_cookie(cookie_string) end Note that Rack::Utils is only used to...

Sometimes we write plain SQL queries in migrations so we don't have to mock ActiveRecord classes. These two migrations do the same: class Migration1 < ActiveRecord::Migration[5.2]

...Migration2 < ActiveRecord::Migration[5.2] def up add_column :users, :trashed, :boolean update("UPDATE users SET trashed = #{quoted_false}") end end The plain SQL migration is less code, but has a...

When giving a presentation where you do some coding, the font size you usually use is probably a bit too small and makes code hard to read for users on...

...smaller screens or low-bandwidth connections when the image quality is lower. Here are two solutions. Presentation Mode RubyMine offers a "Presentation Mode" which you can use. Simply navigate to...

Most browsers have built-in drag and drop support for different page elements like text and images. While this may be useful in most situations, it may become annoying in...

...functionality. This does no longer work. You may now achieve this by explicitly preventing the startdrag-event:

const noDragElement = document.querySelector('no-drag-pls') noDragElement.addEventListener('dragstart', event => event.preventDefault())

github.com

When internationalizing your Rails app, you'll be replacing strings like 'Please enter your name' with t('.name_prompt'). You will be adding keys to your config/locales/*.yml files over...

...the right place is a challenging task. The gem i18n-tasks has you covered. See its README for a list of things it will do for you. Note

Select2 is a fantastic library for advanced dropdown boxes, but it depends on jQuery. Alternatives Tom Select There is a selectize.js fork called Tom Select. It is well tested, comes...

...with Bootstrap 3, Bootstrap 4 and Bootstrap 5 styles and is easy to use. You might miss some advanced features. Known issues: Dynamic opt-groups in AJAX requests are not...

makandra dev

This is for people recovering from Subversion. Get an existing from the server for the first time git clone git@example.com:repositoryname See what's changed git status Check in locally...

...git commit -m "good description" Push local commits to the server git push Get and merge updates from the server git pull Stage a file for the next local commit...

Starting Terminator with split screens is quite simple: Just store a layout and start Terminator with the --layout option. However, if you want to run custom commands in your terminals...

...command exits. You accomplish this by tweaking bash to run a command before actually starting. Pimp your .bashrc Add this to the end of .bashrc: # hack to keep a bash...

Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag these posts with a limited number of tags. The following...

...In most cases you want to use Option 4 with assignable values. The basic setup for all options looks like this: config/routes.rb Rails.application.routes.draw do root "posts#index" resources :posts, except...

In Rails, we usually have a mailer setup like this: class MyMailer < ActionMailer::Base def newsletter mail to: 'receiver@host.tld', from: 'sender@host.tld', subject: 'My mail' end end If you want to...

...Rails will print the mail's text representation to your log/development.log. You may also save this output as-is to an .eml file and open it with your mail client...

makandra dev

...listen to other events. Quirks The "default behavior" in this case is not to show an alert, and preventing this default means the alert is being shown. In ancient browsers...

...customize the alert text, but this is no longer possible. You might want to set event.returnValue = true, as a truthy returnValue was necessary to trigger the alert in Chrome...

Some users might use Adblock Plus or similar browser plugins to reduce the number of ads displayed. If you run into an issue that your application or part of an...

...our web apps. But if your application uses iframes or is embedded in another site it's more prone to it. Blocked elements most of the time appear to the...

...a new callback to your model that (e.g.) caches some data when it is saved. Now you need to run that callback for the 10000 existing records in the production...

Write a clever migration, possibly by embedding the model into the migration script. Open the Rails console after deployment and re-save every single record. You should probably...

...t easily customizable. Example usage /slackfont Comic Neue to use "Comic Neue" (if installed) /slackfont system-ui to use your desktop's system font in Slack. /slackfont (without an argument...

...the default font. Some fonts may be unavailable If you installed Slack through Snap, only system-wide installed fonts (i.e. fonts located in /usr/share/fonts/ or /usr/local/share/fonts/) are available.

...multiple custom ways to format Dates or DateTimes. This often leads to duplicated format strings, wrong formats and unnecessary introduction of new formats. to_fs also supports to refer to...

...those formats by name e.g. to_formatted_s(:iso_8601) or to_formatted_s(:short). to_fs is an alias for to_formatted_s. Those names are defined in Time...

github.com

The issue: You are using stub_const to change a constant value for your test. stub_const "SomeClass::CONST", 'test' All of a sudden, tests fail with undefined method 'some...

...method' for # . The reason When using stub_const before the Class containing the constant has been loaded, a module is automatically created with the name. Since RSpec does no autoloading...

Plot graphs in Ruby WebGraphviz renders in your browser via JavaScript (to store the rendered graph, extract the SVG using your browser's DOM inspector) GraphViz with DOT: Online...

...graphviz.christine.website/ or offline https://makandracards.com/makandra/1589-auto-generate-state_machine-graphs-as-png-images Balsamiq Draw.io Excalidraw Asciiflow Google Presentation Egon.io: Domain storytelling with replay functionality (good to visualize and present flows) Gnuplot Ruby Bindings: Especially for more...

...optimize the experience. Using capistrano-rails capistrano-rails is a Gem that adds Rails specifics to Capistrano, i.e. support for Bundler, assets, and migrations. While it is designed for Asset...

...Pipeline (Sprockets) assets, it can easily be configured for Webpacker. This brings these features to the Webpacker world: Automatic removal of expired assets Manifest backups # config/deploy.rb # No need to include...

atlassian.com

Git log offers useful options for filtering. This card provides a short overview. By message Only commits that include a specific string in their commit message git log --grep="tracker...

By file Only commits that introduced changes to a specific file git log -- foo.rb bar.rb Note In case the file was renamed or moved the --follow option can be...

...Before merging back: reinstate reverted features in a temporary branch, then merge that branch. Scenario Consider your team has been working on several features in a branch, made many changes...

...fix them, if necessary. Maybe tests were added that expect the removed functionality as a side-effect. Merge the master into your branch regularly, especially when you have multiple teams...