#​586 — January 13, 2022

Read on the Web

Ruby Weekly

How a Routine Gem Update Ended Up Creating $73k of Accidental Subscriptions — The creators of a SaaS product noticed odd behavior after a seemingly innocuous update that exposed a major code smell in their source. I love this kind of transparency about production issues from our community, but it’s also a good example of being careful about your dependencies as the ground could move from beneath you..

Julien Khaleghy

Benchmarking CRuby, MJIT, YJIT, JRuby and TruffleRuby — A comparison of various Rubies across multiple benchmarks (such as optcarrot, erubi, and others) showing that TruffleRuby is very much in a league of its own, sometimes 33x faster than the next Ruby. As always, take benchmarks with a pinch of salt and run your own when you need to.

Benoit Daloze

Secure Redis Hosting from RedisGreen — The latest Redis features, instrumented and scaled with the tools teams need as they grow.

RedisGreen sponsor

▶  RubyConf 2021: A History of Compiling Ruby — Chris (perhaps best known for his work on TruffleRuby) gives us a look into the surprising number of Ruby compilers, the approach taken by each, which compilers are still interesting, and the future of compiling Ruby. You'll learn something here!

Chris Seaton

Homebrew, Rosetta, and Ruby — Aaron has been working on some projects recently that depend upon x86 but he’s now rolling on Apple’s new M1 CPU.. what to do? Set up a development environment that uses Apple’s Rosetta to bridge the gap, including with Ruby.

Aaron 'tenderlove' Patterson

IN BRIEF:

Jobs

Ruby/Rails Developer (Remote Friendly) in Beautiful Norway — We build startups and do GOOD tech. A digital democracy startup, a renewable energy startup, a green airport taxi startup. Join us <3
Rubynor

Ruby on Rails Developer — We’re looking for developers to work on large-scale projects and collaborate with clients to improve their products, using RoR.
Saeloun

Find Ruby Jobs 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

📕 Articles & Tutorials

Creating and Testing gRPC Server Interceptors in Ruby — gRPC hasn’t made too much headway in the Ruby community, so Ilija helps us take a smart first step by providing an approach to unit and integration testing server interceptors (think, middleware).

Ilija Eftimov

Simulating Geolocation with Capybara and Headless Chrome — Not something a lot of people will need to do, but a nice writeup of something tricky. We love helpful posts like this.

Karl Entwistle

DHH: 'I Won't Let You Pay Me for My Open Source' — This loooong essay began life as DHH’s RailsConf 2019 keynote but resonates well today in the environment of paying for open source and maintainers sometimes burning out or struggling to find business models for their work.

David Heinemeier Hansson

Complete Peace of Mind Rails Hosting — If you need hands-off, rock solid hosting for your Rails app, OpsCare is for you. We keep your app running, 24 hours a day, 7 days a week with a worldwide team.

OpsCare by reinteractive sponsor

Ruby SDK Code Generation using Smithy — The AWS SDK For Ruby team has unveiled smithy-ruby, a toolchain to create Ruby SDKs based on Smithy-defined models. Smithy is a language for defining services and SDKs in an environment agnostic way to make interoperability easier. There are a few moving parts but this post does a good job of explaining.

Matt Muller (AWS)

Explained: binding.pry vs Byebug vs Debugger — This is a 2019 post updated to account for the addition of the new, built-in debugger (debug) shipping in 3.1 and helped me pause and step through the confusion around debuggers.

Pawan Dubey

'That's Not a Memory Leak, It's Bloat' — Because inefficient code isn’t necessarily the same as broken code.

Sudara Williams (Engine Yard)

Losing Your Way with the Safe-Navigation Operator — The safe-navigation operartor (&.) can save you some characters, but it can also lead to some not-so-nice surprises…be sure you’re using it correctly.

Domhnall Murphy

How Ruby's method_missing Works — As seen used by many a DSL implementation near you..

Jason Swett

Single Attribute In-Place Editing with Rails and Turbo
Josef Strzibny

Rails 7 Adds Better Support for Custom Enum Types in Postgres
Swaathi Kakarla

🛠 Code & Tools

A Ruby Implementation of Wordle, the Word Guessing Game — Play a CLI-based Ruby clone of the game that everyone, on Twitter at least, seems to be playing. 🟩 🟩 🟩 🟩 🟩

Jonathan Thom

ruby-oembed: An oEmbed Consumer Library for RubyoEmbed is a type of URL-specific metadata numerous Web sites support (such as when linking to YouTube videos or tweets).

Magnus Holm, et al.

Single Cov 1.7: Actionable Code Coverage — Catch coverage issues before making PRs or easily add coverage enforcement for legacy apps.

Michael Grosser

Shortcut Puts the Agile in Agile and the “Can” in Kanban

Shortcut (formerly Clubhouse.io) sponsor

Inline SVG: Embed SVG Documents Into Rails Views and Style Them with CSS — Works with Rails 5 through 7 and adds helper methods that can read and display SVG documents via Sprockets or Webpacker as appropriate.

James Martin

Faraday 1.9.3: A Flexible HTTP Client Library — Where Faraday differs from many other HTTP client options is how it supports multiple backends and has a middleware concept for processing the request/response cycle. v1.9.3 adds back Ruby 2.4 support which was dropped before.

Olson, Hobson, et al.

Ruby on Jets 3.1: A Ruby Serverless FrameworkGitHub repo.

Tung Nguyen

ruby-macho: Pure-Ruby Library for Parsing Mach-O (macOS and iOS Executables) Files
Homebrew Project

excon 0.90.0: A Fast, Simple HTTP 1.1 Client for Ruby
excon

💡 Tip of the Week



Time in a timezone

Did you know that Time.at and Time.now take an optional in: keyword parameter? The in: parameter is a zone, which is most often either a String offset from UTC (for example "+03:00") or a TimeZone. A TimeZone is an object which has both a :utc_to_local and a :local_to_utc method defined on it. Rails, for example, exposes an ActiveSupport::TimeZone object. In a Rails console we can run:

ActiveSupport::TimeZone.new("fiji")
# => #<ActiveSupport::TimeZone:
@name="Fiji", @tzinfo=#<TZInfo::DataTimezone:
Pacific/Fiji>, @utc_offset=nil> 

What if we're not in a Rails repo? The ActiveSupport::TimeZone object internally wraps a TZInfo::Timezone which comes from the tzinfo gem. So if we're not in a Rails repo, we can instead install this gem and then get a timezone through it:

require 'tzinfo'

TZInfo::Timezone.get("Africa/Johannesburg")
# => #<TZInfo::DataTimezone: Africa/Johannesburg>

Okay, so we now have our TimeZone object. Let's see how we can use it with the new in: keyword parameter:

require 'tzinfo'

jo = TZInfo::Timezone.
                get("Africa/Johannesburg")

Time.now(in: jo)
# => 2022-01-10 16:42:07.959145 +0200

And of course, we can still use String offsets too:

Time.now(in: "+03:00")
# => 2022-01-10 17:53:08.908918 +0300

One less well known new feature in the Ruby 3.1 release is an update to the Time class. In addition to Time.at and Time.now taking the in: keyword parameter, as of Ruby 3.1, Time.new also takes this parameter:

Time.new(2022, 01, 10, in: jo)
# => 2022-01-10 00:00:00 +0200

As we all know, timezones can be difficult to manage. Hopefully the in: parameter makes this a little easier!

This week’s tip was written by Jemma Issroff.