#538 — February 4, 2021

Read on the Web

💡 We're taking a one week break from the new Tip of the Week section to take the opportunity to interview Sam Aaron of the Sonic Pi project which has just had a new release :-) Check that out at the end of this issue.
Peter Cooper, editor

Ruby Weekly

Sonic Pi 3.3 Released: The Rubyish Live Coding Music Synth — There’s a full interview with Sonic Pi’s creator at the bottom of this issue, but basically Sonic Pi lets you do live music related coding in a dialect of Ruby. It’s really fun and here’s a 4-minute video showing how it works. 3.3 adds Big Sur support, some new synths and effects, and general improvements.

Sonic Pi

Writing an Instant Poll Rails App in a Single File — You might be surprised how little code it takes to create a functional Rails app. We were. Here’s the actual code.

Darren Broemmer

Ship Your Updates 2x Faster — Get build times under 10 minutes, deploy more often, and stay ahead of the competition.

Semaphore sponsor

Super Bombinhas 1.0: A Ruby-Powered Platform Game — We’ve linked this a few times in the past year as it’s a surprisingly slick platform game developed in Ruby – not something you see very often! It’s just hit 1.0 and is considered ‘finished’ by its creator. Enjoy the code or just enjoy the game at itch.io.

Victor David Santos

gem.wtf: A Short URL to Jump to RubyGem Repos — A neat little service that’s perhaps best explained with an example: gem.wtf/nokogiri will take you to Nokogiri’s repo. Handy if you're using a gem and want to quickly look up its issues, search the source, etc.

Zeke Sikelianos

The RailsConf 2021 CFP — This year RailsConf (April 13-15) is a virtual three-day event and proposals for speaking are due February 15th, so check out these guidelines and submit your talk today.

Ruby Central

Quick Bits

📘 Articles & Tutorials

Parallelism in Ruby with Ractors — Another look at the new Ractor API introduced by Ruby 3.0, complete with basic examples and a visual explanation.

Lorenzo Barasti

Behind the Scenes of Devise — There are loads of articles on Devise (the popular authentication library) but this one digs into the code and how it uses Warden for much of its heavy lifting.

Ariel Juodziukynas

Ruby Garbage Collection Deep Dive: GC::INTERNAL_CONSTANTS — Jemma might not be writing a tip for us this week but she’s written a somewhat technical blog post about what some of Ruby’s garbage collection settings mean.

Jemma Issroff

Free eBook: Speed Up a Search Query from Seconds to Milliseconds

pganalyze sponsor

Converting a Two Character ISO Country Code to an Emoji Flag — OK.. that’s a clever little trick.

Andy Croll

3 Practical Uses of Ruby's method_missing Worth Knowing — Handling errors, delegating methods, and building DSLs. You know, the usual.. :-)

Emmanuel Hayford

Debugging an Assertion Error in Ruby — When Tenderlove writes a blog post, it’s an insta-click, no? You’re almost certainly never going to run into the issue he had here in the guts of MRI, but I’m glad he’s taking care of it(!)

Aaron 'Tenderlove' Patterson

Using Postgres Partial Indexing from Rails“Postgres has a nice feature where you can index only the values you want to query on. Today I learned that Rails has a nice shortcut for taking advantage of said feature.”

John Nunemaker

Understanding the bcrypt Hashing Function and Its Role in Rails — A nice overview of why we hashing (and salting) followed by a quick look at how Rails uses bcrypt to hash passwords.

Emmanuel Hayford

How to Completely Uninstall and Reinstall Homebrew-Based Postgres — Is Postgres erroring with “could not read block 39” or “bad address”? If you installed Postgres via Homebrew on a Mac, here’s the quickest way to wipe the slate clean with a fresh install

Justin Searls

The Goodies in Rails Event Store 2.x

Tomasz Wróbel

🛠 Code and Tools

WorkingHours: A Gem to Do Time Calculations with Working Hours — For example, 1.working.day.from_now or Date.new(2014, 12, 28).working_day?

Adrien S

Launch: Scheduled Autoscaling on Heroku — Don’t fear another slowdown. Autoscale based on request queues and background job latency, now on your schedule.

Rails Autoscale sponsor

Introducing Sqlcommenter: An Open Source ORM Auto-Instrumentation Library — An open source library that enables ORMs to augment SQL statements before execution, with comments containing information about the code that caused its execution. Available for certain ORMs in Python, Java, Node.js and Ruby. GitHub repo.

Bala Chandrasekeran (Google Cloud)

Database Cleaner 2.0: Strategies for Cleaning Databases in Ruby — A very long standing project but it’s still getting updated :-)

Ben Mabey

Cucumber 5.3.0: Run Automated Tests Written in Natural Language


💻 Jobs

Full-Stack Engineer (Rails, JavaScript, AWS) — We’re looking for an experienced engineer, open to working remote, to work on one of our new products: Zinc, a cloud-based, real-time communication application.


Backend Engineer (Ruby on Rails) — Remote — We’re looking for devs with a passion for Rails and building for scale. No sprinting, no scrumming, work normal hours.


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.


ℹ️ Interested in running a job listing in Ruby Weekly? There's more info here.

Sonic Pi is easily one of my favorite Ruby-related projects. It's a live musical coding environment where anyone (not just Rubyists) can write code to create music live, including doing live DJ sets. Sam's talk at GOTO 2018 demonstrated the concept well.

With a new Sonic Pi release out this week, I wanted to take the opportunity to catch up with Sam and ask him a few questions about how the project is going:

What inspired you to start the Sonic Pi project almost ten years ago?

I had already been working on live coding music systems (primarily Overtone) for a number of years. I was working as a researcher at the University of Cambridge Computer Laboratory the same year the Raspberry Pi computer was launched. My grant had run out, and I was about to return to being a professional programmer when a small budget was available for a 3-month project to build a prototype system that could help children engage in the new UK CS curriculum. I proposed to build a simplified version of Overtone and got the project: Sonic Pi was born.

You've mentioned that parts of Sonic Pi are being rewritten in Erlang. What prompted this change and will it make any difference to Rubyists enjoying Sonic Pi so far?

Erlang has been part of Sonic Pi for many years now as our well-timed MIDI and network message (OSC) scheduler was written in it originally by the late Joe Armstrong - one of Erlang’s co-creators. An important aspect of Erlang is that it runs on a VM called the BEAM which is built for soft realtime systems with high concurrency, low latency and low jitter. This is precisely what a live music system needs. We are therefore moving more of the critical IO parts of the app into Erlang to benefit from the BEAM’s amazing performance. It turns out that Erlang also has a very similar threading model to Sonic Pi’s so it also makes sense to eventually move much of that to the BEAM which has been much more battle-tested than my Ruby code.

With respect to Rubyists enjoying Sonic Pi - it’s important to point out that whilst Sonic Pi is built on top of Ruby as a DSL, it isn’t Ruby and we don’t support much of Ruby’s behaviour. We also want to have the opportunity to move the DSL to another host language should that prove to be a good engineering choice in the future.

What's the most unusual sort of composition you've seen someone pull off with Sonic Pi?

I’ve seen people re-create entire classical works, compose their own operas, make extremely heavy metal music and also beautiful ambient pieces with Sonic Pi. However, the most unusual composition was by an amazing educational group from Finland who used it to code an entire mechanical orchestra of well-timed robots playing symbols, drums and other percussion to accompany some nice synth riffs. It was huge fun to watch.

Other than using Sonic Pi, is there any way Rubyists can help out?

I think the best way people can help out is to play with it, have fun and use it to share the joy of creative code with everyone they know - especially those that don’t yet code. I’d also recommend people join our friendly community.

Techno or drum'n'bass?

For coding, techno — for dancing, DnB.

Dr. Sam Aaron is the creator of Sonic Pi. He also has a Patreon which is a fundamental part of how he's able to continue his work.