---
title: "Using a Yubikey for 2FA on RubyGems.org"
publication: "Ruby Weekly"
issue: 576
published_at: "2021-10-28"
canonical_url: "https://rubyweekly.com/issues/576"
---

Plus it's a pretty quiet week out there in Ruby land.. |        

#​576 — October 28, 2021 

[Read on the Web](https://rubyweekly.com/issues/576)   

🧶 Some weeks are busy weeks, some weeks are quiet weeks.. this is one of the latter in the Ruby world :-) Luckily Jemma is back with a new _Tip of the Week_ though!
__
_Peter Cooper, your editor_  

Ruby Weekly 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/pk1x79jpgrqid6u3pqwp.jpg)](https://chartkick.com/)  

[Chartkick 4.1: Attractive JavaScript Charts in One Line of Ruby](https://chartkick.com/) — A long standing library (almost 9 years old!) that saves you from fighting with hooking up whatever the latest JavaScript charting libraries are, if you don't want to. [GitHub repo](https://github.com/ankane/chartkick). 

Andrew Kane   

[Publishing Gems Securely with a YubiKey](https://tenderlovemaking.com/2021/10/26/publishing-gems-with-your-yubikey.html) — Package security has continued to pop up as a big issue in several dev communities recently. So adding 2FA to your Rubygems account is the right thing to do, but if you publish a lot, entering OTPs can be a pain, as Aaron _tenderly_ explains. 

Aaron Patterson   [![\](https://copm.s3.amazonaws.com/acc5a357.png)](https://www.appsignal.com/ruby?utm_source=ruby-weekly-sponsored&utm_medium=email&utm_campaign=2021-28-10) 

[Another Bug Bites the Dust](https://www.appsignal.com/ruby?utm_source=ruby-weekly-sponsored&utm_medium=email&utm_campaign=2021-28-10) — Easy-to-use error and performance monitoring tool. Supports 15+ Ruby frameworks (Rails, Sidekiq, Resque, and more). No-brainer pricing, all features are available on all plans. New trial users get a box of Dutch cookies on request. 

AppSignal sponsor   

[Explaining Ruby Fibers](https://noteflakes.com/articles/2021-10-20-explaining-ruby-fibers) — While this post does cover the basics, much of the focus is on now 3.0’s FiberScheduler along with gems like Polyphony are going to make using Fibers much more common. 

Sharon Rosner   

[To Learn a New Language, Read Its Standard Library](http://patshaughnessy.net/2021/10/23/to-learn-a-new-language-read-its-standard-library) — The author of _Ruby Under a Microscope_ is learning [Crystal](https://crystal-lang.org/) (a statically typed, compiled language but that’s _heavily_ inspired by Ruby) using some very simple yet instructive algorithms. 

Pat Shaughnessy   

**QUICK BITS:** 

- [RubyGems 3.2.30](https://blog.rubygems.org/2021/10/26/3.2.30-released.html) has been released.
- Josh Marchello has a [short but sweet love letter](https://jmarchello.com/a-love-letter-to-ruby-and-rails) to Ruby and Rails.     

Jobs  

[Principal Ruby Platform Engineer (Remote - EST Timezone +/- 3 hours)](https://www.linkedin.com/jobs/view/2255010679/?capColoOverride=true) — Interested in Fintech? Join our core team building the AI that will level the playing field for self-directed investors. 
Propelor   

[Senior Software Engineer (Ruby)](https://jobs.lever.co/himama/105106e1-dc69-413e-979c-5d87406d58bc) — Join our highly collaborative team, and build products that empower educators and support children’s learning and development. 
Himama   

[Find Ruby Jobs Through Hired](https://hired.com/join/?utm_source=newsletter&utm_medium=sponsor&utm_campaign=%28b2c%29%28l-all%29%28r-all%29%28cooper-rubyweekly%29&utm_content=find-your-next-job) — 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 

[![\](https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/ourj6qukwmnnncqvtx9i.jpg)](https://blog.arkency.com/less-known-capability-of-rubys-json-dot-parse/)  

[A Lesser Known Capability of Ruby's `JSON.parse`](https://blog.arkency.com/less-known-capability-of-rubys-json-dot-parse/) — Since JSON has no concept of Ruby symbols, hashes are returned with string keys which may be annoying to you. Did you know `JSON.parse` has an option to symbolize keys? 

Szymon Fiedler   

[Testing Your JSON API in Ruby with `dry-rb`](https://t.co/ApYBpsNtRN?amp=1) — Testing JSON responses, especially complex ones, can be tedious and brittle, but using dry-schema and dry-validation makes it _much_ easier. You may want to use this for all your APIs. 

Paul Götze   

[Supporting Fractions in Ruby](https://www.benpickles.com/articles/85-supporting-fractions-in-ruby-rails) — A look at using Ruby’s `Rational` class to perform calculations with fractions but.. as you might’ve guessed, there are gotchas. 

Ben Pickles   

[JavaScript Test Code Coverage in Rails Apps](https://www.fastruby.io/blog/rails/javascript/code-coverage/js-code-coverage-in-rails.html) — Measuring Ruby test code coverage is one thing, but what about for the JavaScript contained within your Rails apps? 

Ariel Juodziukynas   

[Building, Testing, and Deploying Google Cloud Functions with Ruby](https://www.honeybadger.io/blog/building-testing-and-deploying-google-cloud-functions-with-ruby/) — _Google Cloud Functions_ is Google’s answer to AWS Lambda – essentially a serverless platform running functions in the cloud without having to maintain a server. 

Subomi Oluwalana   

[Shortcut Puts the Agile in Agile and the “Can” in Kanban](https://shortcut.com/?utm_source=cooperRubyWeekly&utm_medium=spon_nl&utm_campaign=prospecting&utm_content=kanban) 

Shortcut (formerly Clubhouse.io) sponsor   

▶[Discussing Encryption and Security in Ruby and Rails with Basecamp's Jorge Manrubia](https://rubyrogues.com/encryption-and-security-in-ruby-and-rails-ft-jorge-manrubia-ruby-520) — Jorge Manrubia is a security developer at BaseCamp. He discusses the encryption features added in Rails and explains where they fit into the ecosystem for Hey.com. If you’d prefer to read about his work, [A Story of Rails Encryption](https://world.hey.com/jorge/a-story-of-rails-encryption-ce104b67) is worth checking out. 

Ruby Rogues Podcast podcast   

[Git Bisect: Travel Through Time and Bugs](https://remimercier.com/how-to-use-git-bisect/) — Learning `git bisect` can save tons of time if you don’t know when a bug was introduced to your source code. Binary search, FTW! 

Remi Mercier   

[Being RESTful About Your Routes](https://knowndecimal.com/blogs/points/being-restful-about-your-routes) — A basic intro to REST concepts and how Rails applies them to routes. 

STEFAN VERMAAS   

[An Introduction to Rails Transactions](https://longliveruby.com/articles/introduction-to-rails-transactions) 
Paweł Dąbrowski  

🛠 Code & Tools  

[Gammo: A Pure Ruby HTML5 Compliant Parser](https://github.com/namusyaka/gammo) — Gammo conforms to the WHATWG HTML specification for turning HTML into DOM trees you can work with from your code. Unlike Nokogiri it’s pure Ruby too so may be easier to move about, although in my own experiment it wasn’t particularly fast. 

namusyaka   

[Caffeinate: A Rails Engine for Drip Campaigns/Scheduled Email Sequences](https://github.com/joshmn/caffeinate) — Provides a DSL to create scheduled email sequences which can be used by ActionMailer without any additional configuration. 

Josh Brody   

[Video for Ruby: Build Video in Just Two API Calls](https://mux.com/for/ruby?utm_campaign=q4_sponsorednewsletter_21&utm_source=ruby_weekly&utm_medium=cooperpress_newsletter&utm_content=ruby) — Mux Video is an API-first platform that makes it easy to build beautiful live video that streams everywhere. 

Mux sponsor   

[Opal 1.3: A Ruby to JavaScript Compiler](https://opalrb.com/) — [v1.3.0](https://github.com/opal/opal/releases/tag/v1.3.0) adds support for more Ruby features including `retry`, modern exceptions features, `Kernel#binding`, REPL improvements, experimental support for JavaScript’s `async`/`await`, and more. 

Adam Beynon and Contributors   

[Counter Culture 3.0: 'Turbo-Charged' Counter Caches for Rails Apps](https://github.com/magnusvk/counter_culture) — Boasts improvements over standard Rails counter caches. (I’ve always liked the name of this project.) 

Magnus von Koeller   

[Maxitest 4.1: Minitest, Plus All The Features You Always Wanted..](https://github.com/grosser/maxitest) — Like what? Well, [there’s a list..](https://github.com/grosser/maxitest#features) 

Michael Grosser   

[Sidekiq Statistic 2.0: See Statistics About Your Sidekiq Workers](https://github.com/davydovanton/sidekiq-statistic) 
Anton Davydov   

[Fiddle 1.1: The Official `libffi` Wrapper for Ruby](https://github.com/ruby/fiddle) 
Matz and the Ruby Team       

💡**Tip of the Week** 

   

## The `-p` and `-n` options when running Ruby 

In [a recent _Tip of the Week_](https://rubyweekly.com/issues/574), we learned about the `-e` and `-c` flags we can use when running Ruby from the comand line. Ruby has many more flags we can use as well! (`ruby --help` shows us the full list of flags.) Of note today, the `-n` and `-p` flags both wrap scripts in loops. 

`-n` adds a `while gets` ... `end` loop around our script. `gets` reads user input and stores it in a `$_`. So adding a `while gets` loop around our script allows us to continually read in user input. Without the `-n` flag, if we were testing snippets of code which respond to user input, we might keep re-running them on different manual test cases. This `while` loop with the `-n` flag can be specifically useful for testing snippets of code without needing to re-run the snippets. 

The syntax to use with the `-n` flag if using a Ruby script is `ruby -n file.rb`, but for a one liner you could continue to use `-e` as we explored last week. For example: 

```
$ ruby -ne 'puts "You said #{$_}"'
Hello there!
You said Hello there!
something else
You said something else
``` 

_(Note that the `Hello there!` and `something else` are user input, while the interleaving statements are printed output. You could also pipe in other data to be processed by this loop, such as with `ls | ruby -ne 'puts "You said #{$_}"'` which would then run the code for each file returned by `ls`.)_ 

As always, we can exit this `while` loop using `control-D`. 

Taking the `-n` flag one step further, the `-p` flag will wrap a ruby file in a `while gets` loop and also print the user input itself. So using the same small example as above, we can do the following: 

```
$ ruby -pe 'puts "You said #{$_}"'
Hello there!
You said Hello there!
Hello there!
something else
You said something else
something else
``` 

We input `Hello there!` and `something else`, Ruby executes our script, and then also prints our input again. This can be more handy, perhaps, when you want to make quick transformations over incoming data and then have it output again without using something like `puts` yourself. 

For example: 

```
$ echo "hello world" | ruby -pe '$_.upcase!'
HELLO WORLD
``` 

Try this with the piped `ls` idea from above to see what happens!    

This week’s tip was written by [Jemma Issroff](https://twitter.com/jemmaissroff).          

Curated by [Peter Cooper](https://twitter.com/peterc), [Glenn Goodrich](https://twitter.com/ruprict) and [Cooperpress](https://cooperpress.com/). 

[Change your email address](https://rubyweekly.com/edit_subscription/*|UID|*) or[Stop getting this newsletter](https://rubyweekly.com/leave/*|UID|*) 

© Cooper Press Ltd · Fairfield Enterprise Centre, Louth, LN11 0LS, United Kingdom
