Sage Griffin

Former co-lead of the crates.io team. Creator of Diesel. Former Rails committer. they/them

Read this first

Un poema para “hace”

“Hace” es el mejor palabra del mundo, porque puede significar todo.

¿Quieres crear algo nuevo?
¡Hace ese algo!

¿Quieres realizar algo?
¡Lo hace!

¿Quieres cocinar una comida?
¡Hace esa cena!

¿Quieres hablar del tiempo?
¡Hace frío!

¿Cuántas horas en el pasado?
¡Hace horas!

¿"ser" y “estar” no son suficientes?
¡Hace!

En las palabras de Kevin, ¿por qué usa muchas palabras cuando pocas palabras están bien?

Why use many word when few word do trick?

View →


Things I Wish I Knew About Assembly

My talk for RustConf this year includes an technical deep dive of the MissingNo glitch from Pokemon Red and Blue. It was important to me to really understand not just what happened in this glitch, but why it happened. This meant I had to spend a lot of time over the last year reading through a disassembly of the game.

While I had a very rudimentary understanding of x86 assembly going into this, I had never seen this assembly syntax before. I also didn’t know much about some of the intricacies of assembly programming. As a result I went down a few rabbit holes of misinformation, and had to learn a lot about the GameBoy’s assembly. Here are some things I learned that would have saved me time had I known them up front.

The disassembly I used was built with the RGBDS assembler. Some of this may be specific to that tool chain, some of it may be specific to the GameBoy hardware, and some of...

Continue reading →


Neat Rust Tricks: Passing Rust Closures to C

One of Rust’s biggest selling points is how well it can interoperate with C. It’s able to call into C libraries and produce APIs that C can call into with very little fuss. However, when dealing with sufficiently complex APIs, mismatches between language concepts can become a problem. In this post we’re going to look at how to handle callback functions when working with C from Rust.

Our hypothetical library has a Widget struct, which periodically generates events. We want to take a callback function from users that is called whenever one of these events occurs. More concretely, we want to provide this signature:

impl Widget {
    fn register_callback(&mut self, callback: impl FnMut(Event)) {
        // ...
    }
}

Unlike Rust, C has no concept of closures. Instead it has function pointers. To put this in Rust terms, you can take fn(Event), but not impl FnMut(Event). Function pointers...

Continue reading →


Thoughts on Arbitrary Pagination

Pagination is the act of breaking a data set into multiple pages to limit the amount of data that has to be processed and sent by a server at once. We’re going to be changing how pagination works on crates.io, and I wanted to share some musings about the issues with supporting this as a generic abstraction. While I’m going to be talking about some PostgreSQL internals in this article, the general ideas presented apply to any SQL database.

“Simple” Pagination

The most common form of pagination uses page numbers. This is done by having numbered page links shown towards the bottom of the UI, and including ?page=5 in the URL. Often there are also links for next page, previous page, first page, and last page. The UI might look like this.

Screen Shot 2019-08-20 at 10.02.27 AM.png

This form of pagination is implemented on the server by adding an offset to the query. The total is also needed to know how many pages there actually...

Continue reading →


Moving on from Rails and what’s next

It’s been more than 6 years since my first commit to Ruby on Rails. I had just gotten my first full time Ruby position, was excited to move away from PHP, and wanted to give back. Since then I made 1452 commits to the project. Today, I am finally ready to move on from Rails.

In 2014 I started working on the Active Record Attributes API. We got to a working implementation fairly quickly, but it took many more months and thousands of lines of code to get to an implementation that I was comfortable shipping. By the time Rails 4.2 came out, I had ended up rewriting a significant portion of the library, which meant I was spending more and more of my time maintaining that code and fixing other issues.

Around the time that 4.2 was entering beta, I decided it was time to try and take this commitment full time. I spent the next 4 years devoting as much of my professional time as possible to the...

Continue reading →