Using Serial Ports with Ruby
Tender Lovemaking
by Aaron Patterson
2M ago
Lets mess around with serial ports today! I love doing hardware hacking, and dealing with serial ports is a common thing you have to do when working with embedded systems. Of course I want to do everything with Ruby, and I had found Ruby serial port libraries to be either lacking, or too complex, so I decided to write my own. I feel like I’ve not done a good enough job promoting the library, so today we’re going to mess with serial ports using the UART gem. Don’t let the last commit date on the repo fool you, despite being over 6 years ago, this library is actively maintained (and I use it eve ..read more
Visit website
Fast Tokenizers with StringScanner
Tender Lovemaking
by Aaron Patterson
8M ago
Lately I’ve been messing around with writing a GraphQL parser called TinyGQL. I wanted to see how fast I could make a GraphQL parser without writing any C extensions. I think I did pretty well, but I’ve learned some tricks for speeding up parsers and I want to share them. Today we’re going to specifically look at the lexing part of parsing. Lexing is just breaking down an input string in to a series of tokens. It’s the parser’s job to interpret those tokens. My favorite tool for tokenizing documents in Ruby is StringScanner. Today we’re going to look at a few tricks for speeding up StringScann ..read more
Visit website
Bitmap Matrix and Undirected Graphs in Ruby
Tender Lovemaking
by Aaron Patterson
1y ago
I’ve been working my way through Engineering a Compiler. I really enjoy the book, but one part has you build an interference graph for doing register allocation via graph coloring. An interference graph is an undirected graph, and one way you can represent an undirected graph is with a bitmap matrix. A bitmap matrix is just a matrix but the values in the matrix can only be 1 or 0. If every node in your graph maps to an index, you can use the bitmap matrix to represent edges in the graph. I made a bitmap matrix implementation that I like, but I think the code is too trivial to put in a Gem. Her ..read more
Visit website
Vim, tmux, and Fish
Tender Lovemaking
by Aaron Patterson
1y ago
I do most of my text editing with MacVim, but when I pair with people I like to use tmate. tmate is just an easy way to connect tmux sessions with a remote person. But this means that I go from coding in a GUI to coding in a terminal. Normally this wouldn’t be a problem, but I had made a Fish alias that would open the MacVim GUI every time I typed vim in the terminal. Of course when I’m pairing via tmate, the other people cannot see the GUI, so I would have to remember a different command to open Vim. Today I did about 10min of research to fix this problem and came up with the following Fish c ..read more
Visit website
In Memory of a Giant
Tender Lovemaking
by Aaron Patterson
1y ago
The Ruby community has lost a giant. As a programmer, I always feel as if I’m standing on the shoulders of giants. Chris Seaton was one of those giants. I’ve been working at the same company as Chris for the past 2 years. However, I first met him through the open source world many years ago. He was working on a Ruby implementation called TruffleRuby, and got his PhD in Ruby. Can you believe that? A PhD in Ruby? I’d never heard of such a thing. My impression was that nobody in academia cared about Ruby, but here was Chris, the Ruby Doctor. I was impressed. Patience As a college dropout, I’ve al ..read more
Visit website
Cross Platform Machine Code
Tender Lovemaking
by Aaron Patterson
1y ago
I hate writing if statements. I’ve been working on a couple different assemblers for Ruby. Fisk is a pure Ruby x86 assembler. You can use it to generate bytes that can be executed on x86 machines. AArch64 is a pure Ruby ARM64 assembler. You can use it to generate bytes that can be executed on ARM64 machines. Both of these libraries just generate bytes that can be interpreted by their respective processors. Unfortunately you can’t just generate bytes and expect the CPU to execute them. You first need to put the bytes in executable memory before you can hand them off to the CPU for execution. Ex ..read more
Visit website
Homebrew, Rosetta, and Ruby
Tender Lovemaking
by Aaron Patterson
1y ago
Hi everyone! I finally upgraded to an M1. It’s really really great, but the main problem is that some projects I work on like TenderJIT and YJIT only really work on x86_64 and these new M1 machines use ARM chips. Fortunately we can run x86_64 software via Rosetta, so we can still do development work on x86 specific software. I’ve seen some solutions for setting up a dev environment that uses Rosetta, but I’d like to share what I did. Installing Homebrew I think most people recommend that you install two different versions of Homebrew, one that targets ARM, and the other that targets x86. So fa ..read more
Visit website
Publishing Gems With Your YubiKey
Tender Lovemaking
by Aaron Patterson
1y ago
The recent compromise of ua-parser-js has put the security and trust of published packages at the top of my mind lately. In order to mitigate the risk of any Ruby Gems I manage from being hijacked, I enabled 2FA on my RubyGems.org account. This means that whenever I publish a Ruby Gem, I have to enter a one time passcode. I have to admit, I find this to be a pain. Whenever I do a release of Rails, I have to enter a passcode over and over again because you can only push one Gem at a time. Finally I’ve found a way to deal with this. I can maintain account security and also not be hassled with OT ..read more
Visit website
Debugging an Assertion Error in Ruby
Tender Lovemaking
by Aaron Patterson
1y ago
I hope nobody runs in to a problem where they need the information in this post, but in case you do, I hope this post is helpful. (I’m talking to you, future Aaron! lol) I committed a patch to Ruby that caused the tests to start failing. This was the patch: commit 1be84e53d76cff30ae371f0b397336dee934499d Author: Aaron Patterson <tenderlove@ruby-lang.org> Date: Mon Feb 1 10:42:13 2021 -0800 Don't pin `val` passed in to `rb_define_const`. The caller should be responsible for holding a pinned reference (if they need that) diff --git a/variable.c b/variable.c index 92d7 ..read more
Visit website
Counting Write Barrier Unprotected Objects
Tender Lovemaking
by Aaron Patterson
1y ago
This is just a quick post mostly as a note to myself (because I forget the jq commands). Ruby objects that are not protected with a write barrier must be examined on every minor GC. That means that any objects in your system that live for a long time and don’t have write barrier protection will cause unnecessary overhead on every minor collection. Heap dumps will tell you which objects have a write barrier. In Rails apps I use a small script to get a dump of the heap after boot: require 'objspace' require 'config/environment' GC.start File.open("heap.dump", "wb") do |f| ObjectSpace.dump_ ..read more
Visit website

Follow Tender Lovemaking on FeedSpot

Continue with Google
Continue with Apple
OR