Best practices: Writing a Rails script (and how to test it)

Posted 3 months ago by Dominik Schöler.

A Rails script lives in lib/scripts and is run with bin/rails runner lib/scripts/.... They are a simple tool to perform...

Bash: How to count and sort requests by IP from the access logs

Posted 3 months ago by Emanuel.

87.140.79.42 - - [23/Jan/2024:09:00:46 +0100] "GET /monitoring/pings/ HTTP/1.1" 200 814 "-" "Ruby" 87.140.79.42 - - [23/Jan/2024:09:00:46 +0100] "GET...

Bash: How to grep logs for a pattern and expand it to the full request

Posted 3 months ago by Emanuel.

I, [2024-01-21T06:22:17.484221 #2698200] INFO -- : [4cdad7a4-8617-4bc9-84e9-c40364eea2e4] test

open-next-failure: An alias to speed up test debugging

Posted 4 months ago by Michael Leimstädtner.

Getting an entire test suite green can be a tedious task which involves frequent switches between the CLI that is...

Capistrano 3: Running a command on all servers

Posted 4 months ago by Dominik Schöler.

This Capistrano task runs a command on all servers. bundle exec cap production app:run cmd='zgrep -P "..." RAILS_ROOT/log/production.log...

Debug MiniMagick calls in your Rails app

Posted 6 months ago by Dominic Beger.

Most of our applications use CarrierWave for file uploads. CarrierWave has an integrated processing mechanism for different file versions with...

How to make sure that manual deploy tasks (scheduled in Pivotal Tracker) are executed on deploy (with Capistrano)

Posted 6 months ago by Dominik Schöler.

We regularly have tasks that need to be performed around a deploy. Be it to notify operations about changed application...

CarrierWave: Processing images with libvips

Posted 9 months ago by Henning Koch.

When you write your next CarrierWave uploader, consider processing your images with libvips instead of ImageMagick. Reasons for libvips

How to pretty print all values in a Redis database

Posted 9 months ago by Emanuel.

With this Ruby script you can print all values in a Redis database to your console (derived from this bash...

Sidekiq 7: Rate limiting with capsules

Posted 11 months ago by Emanuel.

Sidekiq 7 adds a new feature called capsules. Use cases: a chrome queue limited to 1 for e.g. PDF processing...

Sass: get rid of deprecation warnings in dependencies

Posted Over 1 year ago by Daniel Straßner.

TLDR: sass >= 1.35.0 has the option quietDeps to silence deprecation warnings from dependencies. quietDeps: If true, the compiler must not...

Git: Restore

Posted Over 1 year ago by Julian.

tl;dr git checkout is the swiss army of git commands. If you prefer a semantically more meaningful command for...

How to fix "Exit with code 1 due to network error: ProtocolUnknownError" with wkhtmltopdf

Posted Over 1 year ago by Tobias Kraze.

New versions of wkhtmltopdf dissallow file:// URLs by default. You can allow them by passing --enable-local-file-access.

Converting SVG to other vector formats without Inkscape

Posted Over 1 year ago by Arne Hartherz.

If you need to convert an SVG source to PS or EPS, the most common suggestion on the interwebs is...

How to debug issues with zeitwerk and Rails

Posted Almost 2 years ago by Emanuel.

In case you have trouble with the zeitwerk autoloader, you can check out the documentation Autoloading and Reloading Constants and...

How to get information about a gem (via CLI or at runtime from Ruby)

Posted About 2 years ago by Arne Hartherz.

When you need information about a gem (like version(s) or install path(s)), you can use the gem binary...

Generating an Entity Relationship Diagram for your Rails application

Posted About 2 years ago by Arne Hartherz.

This card explains how to generate an entity relationship diagram for your Rails application. We also show how to limit...

Using feature flags to stabilize flaky E2E tests

Posted Over 2 years ago by Henning Koch.

A flaky test is a test that is often green, but sometimes red. It may only fail on some PCs...

Git shortcut to rebase onto another branch

Posted Over 2 years ago by Michael Leimstädtner.

Inspired by recent "git shortcut" cards I figured it would be nice to have one of these for rebasing a...

Git shortcut to fixup a recent commit

Posted Over 2 years ago.

git --fixup is very handy to amend a change to a previous commit. You can then autosquash your commits with...

NVM: How to automatically switch version when changing directories

Posted Almost 3 years ago by Arne Hartherz.

The Node Version Manager allows installing multiple NodeJS versions and switching between them. By default, it does not automatically switch...

How to generate and test a htpasswd password hash

Posted About 3 years ago by Daniel Straßner.

Generate a password htpasswd -Bn firstname.lastname This will ask you for a password and use bcrypt (-B, more secure) and...

Delivering Carrierwave attachments to authorized users only

Posted About 3 years ago by Dominic Beger.

To attach files to your records, you will need a new database column representing the filename of the file...

The Ruby Object Model

Posted About 3 years ago by Dominic Beger.

In Ruby (almost) everything is an Object. While this enables a lot of powerful features, this concept might be confusing...