Abe Voelker's blog Programming stuff, mainly

Generating YouTube-like IDs in Postgres using PL/V8 and Hashids

8 minute read

Hashid

Update: There is a brand-new Postgres Hashids extension that you should use if possible instead of this PL/V8 solution! However, this solution may still be valuable if you are using AWS RDS, which doesn’t currently support the Hashids extension.

Recently on a Rails project, I ran into an issue where I wanted to expose a resource (lets say it was a product) in a RESTful route, but I also didn’t want the URLs to be easily guessable. In other words, following Rails conventions my standard “show” actions would be URLs like https://example.com/products/1, https://example.com/products/2, https://example.com/products/3, which are trivially guessable since we’re exposing the database’s auto-incrementing integer primary key as the resource ID. To prevent people from writing a super simple script that could scrape my whole product catalog, it would be nice if we could make the URLs not trivially guessable while still remaining publicly-accessable for people who know them.

Adding Elm to a Rails application

7 minute read

Elm logo

Recently I added Elm to a Rails application using webpack, and it took me a while to figure out as I’m new to both so I figured I’d share what I did.

A complete example app is available on GitHub (abevoelker/rails-elm-example); this post will walk through each step used to create it.

Simple transactional email links using JSON Web Tokens (JWT)

15 minute read

JWT logo

Recently I ran into an issue with a Rails web application where I wanted to add one-click unsubscribe links to transactional emails I send out. This website tracks the inventory of retail product websites; users subscribe to individual products and get notified via email when the price or stock status changes so that they can quickly make purchasing decisions based on the information.

You got Haskell in my Ruby! Cleaner Ruby validations using the Either monad and Kleisli gem

17 minute read

You got Haskell in my Ruby!

Alternate title: “You could have invented Either!”

Update: It came to my attention from some Reddit comments that the simple example I use in this article is probably not the best for showing off a good use case of the kleisli gem as the “naive” code can be simplified. Therefore, I will be updating this post in the future with a more thorough example. In the meantime, I’d encourage you to read the article “Cleaner, safer Ruby API clients with Kleisli” by the kleisli gem author which has a more comprehensive use case!

I’m still a rank beginner at Haskell, but I guess it’s already leaving some tracks in my brain as I find myself wanting algebraic data types and pattern matching when I’m writing Ruby.