RSSAmplifier

Blog

ABuisman.com

Blog about solving problems with code, mostly Ruby, and other things I have learned working as an engineer and a technical leader

abuisman.comRSS feed ↗10 posts

Latest posts

Building a Vector Database in Ruby Using Hash and PStore

Today, I’m sharing a very cool piece of code I’ve written. It is a vector database in pure Ruby that you could use for tiny datasets or to test some things in your console quickly. First, why would we need a vector database? A quick aside : what are vector databases, you ask? Why would I want to use one? Vector databases have recently become very popular in AI because they allow us to store…

Language matters: Building blocks

I have been working on a big platform with countless pages. Since its beginning, it was built using Bootstrap for the front end, but maintenance has become burdensome over time. This is due to multiple layers of custom CSS and the reuse of CSS, which has caused changes in one place to have unpredictable effects on others. Our way out of this situation is Tailwind. Since you write HTML and style in…

Super fast downloading of big files

Using curl or wget for downloading big dumps to your virtual machines is slow! Use aria2 instead. Today I had to download a 49GB Heroku Postgres backup to an EC2 server to import it into an RDS instance. The defacto way to download files is using curl and wget . The problem with these tools is that you download the file using one connection, and connections are often throttled. You can see that by…

Zero downtime credential updates on Heroku.

When you use Rails credentials on Heroku, you probably have your key in your environment variables. Probably RAILS_MASTER_KEY . Let’s say you want to rotate this key. You re-encrypt your credentials, push the code (reboot 1) and then add the env-var (reboot 2). You could also flip these two steps around. In between these two reboots, your app won’t work since you either have a new credentials file…

Cron monitoring with Blazer

Many apps have recurring jobs and we should track them. There are third-party services to do this, but I like to keep things simple and own my data. I’ll show you how to keep track of cron jobs within your Rails application and report on them through Slack. We collect logs in your database, so you can use them for other things as well. When done we can write this SQL: SELECT * FROM job_logs WHERE…

Quick page benchmarks

I love optimising performance, be it in databases, scripts or webpages. It can be pretty evident in database queries when you’ve improved the performance, with total runtimes of scripts, etc. Webpages, however, are a bit more tricky when the differences are relatively small. I’ll show you a quick way to run benchmarks that won’t require you to set up a lot of stuff in your framework but instead…

Simple query optimisation

Query optimisation is one of my favourite things to do because you can get extra performance in response times and because we will use fewer resources in your database. To optimise queries properly, you have to look at the queries but also know something about your application’s domain. I will take you along in a straightforward one I did today. So starting from the following query: EXPLAIN…

Fixing Ruby openssl errors

The other day I wanted to try out Rails 7’s import maps on my new M1 MacBook, but I was blocked by an error telling me that Ruby couldn’t make any SSL requests. I’ll go through how I fixed this. The command I tried that gave me an error was: bin/importmap pin @picocss/pico I got the following error about SSL: /Users/abuisman/.asdf/installs/ruby/3.1.0/lib/ruby/3.1.0/net/protocol.rb:46:in…

Crazyton - Better than module_function

I created a new gem that gives you the nice syntax of module_function s but with the advantages of classes. An example: class ApiStub include Crazyton def sign_up ( email , password , status = 200 , response = default_sign_up_request ) stub_request ( :post , "https://some-service.com" ) . with ( body: { email: email , password: password }) . to_return ( status: status , body: response . to_json )…

Heroku differ: see which commits would be deployed

Before pushing to Heroku, I’d like to know what will be in the release. Let’s use the power of git to answer this question. The script I created is the following, I’ll go over it, argument, by argument below. #!/bin/bash git log —first-parent heroku/master..master —abbrev-commit —date = relative —format = format: '%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim…