#​559 — July 1, 2021

Read on the Web

Ruby Weekly

YouPlot: CLI Tool to Draw Plots on the Terminal — A bit random, but I was struck by how neat this little Ruby-powered terminal-based plotting tool was. I encounter so many such tools written in Rust or Go nowadays that seeing one in Ruby is a delight. The underlying plotting library is unicode_plot.rb if you want to pull off similar things in your own code.

Red Data Tools

Stripe's CEO Mentions Their In-House 'Ruby Compiler' — Am I impressed at the CEO of a company valued at $95bn tweeting about Ruby? Yes, I admit it. In short, this is just a tweet, but Stripe (who also build Sorbet) claims to have an ‘in-house Ruby compiler’ yielding 22-170% more performance than CRuby when powering Stripe’s API server.

Patrick Collison on Twitter

Fast Rails Deployment on Bare Metal Servers — Maxihost & Cloud 66 have partnered to make deploying and managing Rails applications on bare metal servers faster and easier. Get the power and flexibility of bare metal with the speed and simplicity of Cloud 66.

Cloud 66 + Maxihost sponsor

GitHub Copilot: An AI 'Pair Programmer' — A project that GitHub has been working on in the background for some time with OpenAI. It’s a VS Code extension that uses machine learning to suggest useful code snippets as you type – it works really well with Ruby and I've had a lot of fun playing with it. I'll be sharing a post with how it works, specifically for Rubyists, next week.

GitHub

Creating Google-Like Letter Avatars with ERB-Generated SVGs — You don’t need a graphics library to create simple avatars, as SVG can be generated on the fly with ERB, as shown here. Interesting approach.

Karol Bąk

IN BRIEF:

📕 Tutorials

Set Up a Docker Container To Test Your Rails App — This is a use case tailor made for containers, which enables consistent environments and simple dependency mocking leading to more reliable tests.

Milap Neupane

▶  Configure Anything with Dry::Configurable — Stop rolling your own config classes and use this threadsafe, flexible, simple-to-use gem that handles just about any use case you can imagine.

Hanami Mastery

Using Multiple Databases in a Single Query in Rails Apps — You’re probably never going to need to do this, but if you do.. Postgres’s FDWs are very handy and will even let you work with other databases that aren’t Postgres.

Karol Galanciak

Rails 7 Adding Audio Metadata Support to ActiveStorage — Rails 6.2 added a mechanism for extracting metadata from images and videos, but Rails 7 will go a step further with audio, to get things like length and bit rate by calling out to ffprobe, a part of FFmpeg.

Deepak Mahakale

Free eBook: Efficient Search in Rails with Postgres — Speed up a search query from seconds to milliseconds and learn about exact matches, trigrams, ILIKE, and full-text.

pganalyze sponsor

Using Redis Hashes for Caching in Railsredis_hash_store lets you use Redis hashes for caching.

Omar Bahareth

Back to Basics: Boolean Expressions — The truth is out there.

Joël Quenneville

▶  Discussing WNB.rb and Creating a Community — A chat with Jemma Issroff (who writes our tips of the week), Emily Giurleo and Sylwia Vargas about WNB.rb, a monthly Ruby meetup for women and non-binary people, and what it takes to build community generally.

The Ruby on Rails Podcast podcast

Calculate the Standard Deviation of a Ruby Array
Andy Croll

▶  From Zero to Sidekiq Hero
Paweł Dąbrowski

Jobs

Engineering Manager @ Nebulab (Remote) — Join our distributed team and build high-volume eCommerce applications in a workplace made by developers for developers.
Nebulab

Hint is Hiring — We are on a mission to help all software teams reach their full potential. You can help.
Hint

Find a Job Through Hired — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers.
Hired

🛠 Code and Tools

premailer-rails: CSS Styled Emails Without HasslePremailer is a drop-in-and-it-works gem that makes styling emails easy by applying CSS rules without you having to write all the styles inline. We use it as part of the Ruby Weekly production pipeline, but premailer-rails opens it up to Action Mailer too.

Philipe Fatio

Introducing idnx: Converts Internationalized Domain Names into Punycode — Punycode is a way to represent Unicode with the limited ASCII character set.

HoneyryderChuck

Still Not On Rails 6.1? FastRuby.io Can Help

FastRuby.io | Rails Upgrade Services sponsor

HTTP.rb 5: The Fast Ruby HTTP Client — My favorite Ruby HTTP library nowadays. The 5.0 release switched to the llhttp parser, improved modern Ruby support, added HTTP 1XX code response support, and more.

http.rb team

Amoeba: Easy Cloning of Active Record Objects (Including Associations) — An extremely old library but recently updated and boasting Rails 6 compatibility.

Vaughn Draughon

ValidEmail2 4.0: ActiveModel Validation for Email — Check the legitimacy of email addresses including MX lookup and checking against a list of disposable email services.

Micke Lisinge

SidekiqUniqueJobs: Ensure Uniqueness of Your Sidekiq Jobs
Mikael Henriksson

💡 Tip of the Week

String Formatting

We often need to format strings to appear a certain way. This week, we'll cover several formatting and minor manipulation methods on Strings:

  • String#ljust and String#rjust both take an integer argument, and an optional padding argument. If the length of the string is smaller than the integer, they'll return a new string of the length of the integer, padded with the padding argument repeated to fill the space, or spaces ( ) if no argument is passed. String#ljust padds on the right of the string, and String#rjust pads on the left:
"This string needs a length of 35"\
                 .ljust(35, "asdf")
=> "This string needs a length of 35asd"

"This string is already longer than 35"\
                              .ljust(35)
=> "This string is already longer than 35"
  • String#center behaves the same as String#ljust and String#rjust except it pads on both sides (with extra padding on the right in the case of an odd number of padding characters:
"String".center(10)
=> "  String  "
  • String#delete_prefix takes a parameter of the prefix to delete, and does exactly what it claims. It is also faster than String#sub or String#gsub:
"id_12345".delete_prefix("id_")
=> "12345"

If the prefix doesn't exist, it will return the original String:

"12345".delete_prefix("id_")
=> "12345"
  • String#delete_suffix works just like String#delete_prefix except it deletes from the end of the string:
"uploaded_image_12.pdf"\
               .delete_suffix(".pdf")
=> "uploaded_image_12"

Please note that the \ formatting is used to prevent the email width going too wide on mobile :-)

This week’s tip was written by Jemma Issroff.