Mike Coutermarsh
  • Home
  • About
  • Twitter
  • GitHub
Sign in Subscribe

AstroVim slow on large files

If you're finding AstroVim is lagging on very large files, it is possible the source of the problem is vim-illuminate. To determine if it is, run :TSDisable illuminate. Does it solve your problem? Large file cutoff If that solved your problem, you can disable illuminate for large files
Apr 19, 2024

How to use GitHub Copilot with AstroVim 4

This took me a while to figure out. In this file: ~/.config/nvim/lua/community.lua You need to add the following line. { import = "astrocommunity.completion.copilot-lua-cmp" }, Then, when you start nvim again. Run :Copilot auth. This will trigger the setup and you'll be good to
Apr 16, 2024

How high scale Rails apps make schema changes

I recently wrote a post over on the PlanetScale blog sharing how we make schema changes for our own Rails app. In the post I share a couple concepts that might be new to you. 1. "Online" schema change tools 2. Separating rails db:migrate from deploys If
Apr 7, 2024

Using replicas to scale out your database

High traffic websites often use database replicas to scale out their reads. Most web traffic is a GET request anyway and never modifies data. But how do you know when you should READ from the primary? The answer is more complex than you might think. And it's important
Apr 5, 2024 2 min read

How to stop GitHub Slack app from @ mentioning you

This took me too long to figure out. I hope this helps you if you are googling around. To force the GitHub Slack app to stop @ mentioning you. The only way I found is to do the following. 1. In a separate slack workspace (that you don't care
Jan 22, 2024

Building a webhooks service

I recently had the chance to work on building webhooks for PlanetScale. As part of this, I learned quite a lot about the possible security vulnerabilities that running a webhooks service can expose you too. You might be surprised with all the risks there are! Everything I learned is over
Nov 21, 2023 3 min read

Easy Rails controller rate limiting with Rails.cache

Here's an easy trick I reach for when wanting to add simple rate limiting to an endpoint. def special_endpoint model = Model.find(params[:id]) cache_key = "rate_limit:mymodel:#{model.id}" # If the key exists, we rate limit if Rails.cache.fetch(cache_key) return
Oct 19, 2023 1 min read

How dare you test a private method

I feel inspired to talk more about “testing a private method” (gasp!). Since people seem to get upset about it. Where did this idea of it being bad even come from? I remember when learning to code it was all over the place. Blog posts, books, podcasts. I remember being
Sep 27, 2023 1 min read

How to use Flash messages from a Rails API only controller

If you are debugging this Flash message error. undefined local variable or method `flash' for And you are currently using an API only Rails controller, but still want to use flash messages in your app because you are redirecting to a normal controller. Then you can fix this by
Aug 16, 2023

How to stop Rails from setting a session cookie

Recently I was working on a Rails API and I wanted to stop Rails from setting it's _session cookie for API requests. Since these requests are authenticated via an API token, there's no reason for the cookie to be returned to the user. # application_controller.rb
Aug 11, 2023

How to make a Fly API call from Ruby

Fly has a graphql API available. You can find ways to use it by looking through their CLI's source code. I recently wanted to automate a Fly API call from a ruby script. And I was not in an environment where I wanted to install the fly CLI.
Jul 31, 2023 1 min read

Setting an Actions secret with Octokit.rb - Ruby Example

Here's a Ruby example of how to set a GitHub Actions secret using Octokit in Ruby. The secret needs to be encrypted before it is sent to the API. You need the octokit and rbnacl gems installed. require "octokit" require "rbnacl" client = Octokit::Client.
Jul 27, 2023 1 min read

Performant database tree traversal with Rails

New post over on the PlanetScale blog. This was the toughest N+1 performance problem I've faced. It shows a trick you can use to preload records, in a situation where includes doesn't cut it. Go check it out.
Jul 12, 2023

How to tech lead and survive

If you're in a tech lead role and struggling. Try this. Make a mindset shift. Ask yourself: "How can I not be the person who builds that?" This will feel hard because for years you have been good at building. You're used to taking
Jul 10, 2023 1 min read

Fly + PlanetScale + Rails example dockerfile

If you are debugging this error: LoadError: libmariadb.so.3: cannot open shared object file: No such file or directory - /rails/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/lib/mysql2/mysql2.so The fix is having these packages installed for production: default-mysql-client default-libmysqlclient-dev Here's
Jun 10, 2023 2 min read

Sidekiq: retry once before erroring

Here's how you can silence/mute the initial Sidekiq error, but still report any errors after the first try. This reduces noise in the error tracker and makes any errors more actionable. def perform # Do work rescue SomeError => e retry_once_before_raising_error(e) end Read
Jun 9, 2023 2 min read

Rails tests: Content-Length header before sending it

Here is a quick and easy way to estimate the content-length of a request from the params being sent. I needed to do this recently in a Rails test. require 'rack' params = { mike: true } params_string = Rack::Utils.build_nested_query(params) content_length = params_string.length puts
May 30, 2023

Using Multi-Node Elasticache with Rails

When using multi-node Elasticache memcached with Rails, it's critically important to get your setup correct. If you don't, your application will connect to memcached nodes at random (!!!). Resulting in low cache hit rates. How to setup Conveniently, there is a gem for this, dalli-elasticache. gem "
May 4, 2023 1 min read

Sidekiq connecting logs in test

Sidekiq 7.0.6 connecting to Redis with options If you have these all over your Rails test logs, here is how you can disable them for test. In test/test_helper.rb, add the following: Sidekiq.logger.level = Logger::WARN Now your test logs will be clean. This took
Apr 21, 2023

New index name generation in Rails 7.1

For as long as I can remember Rails has had this little quirk where it will auto generate index names that are too long. A couple weeks ago Andrew Culver tweeted out his wish for this to be improved. I'll contribute $500 to the bounty for anyone who
Apr 8, 2023 1 min read

Top 5 Ruby gems for Rails apps

I recently shared a couple of my favorite gems on Twitter. And people asked for more! These are my top 5 must have gems for any Rails app + my reasoning and some tips on how to best use them. 1. Pry 2. Flipper 3. Sidekiq 4. Rack::Attack 5. Prometheus
Apr 2, 2023 4 min read

No fear Rails schema changes

Over on the PlanetScale blog I just wrote up how we handle schema changes in our own Rails app. It's the best workflow I've ever used for Rails migrations. It's both inspired by and better than the custom tooling I had access to when
Apr 2, 2023 1 min read

There was an error parsing Gemfile: windows is not a valid platform

I hit this error recently. To fix this, you need to update to a newer version of bundler. gem update bundler Good luck, hope this saved you some time. Error There was an error parsing `Gemfile`: `windows` is not a valid platform.
Mar 23, 2023

Trick for fixing Rails `find_by` N+1's

Recently I had some code that was doing 100's of find_by queries. Due to the way it was setup, a simple fix using includes wasn't possible. I was able to know which records would be called via find_by though, meaning I should be able
Feb 26, 2023 2 min read

New Rails health check endpoint

Rails just recently added a default /up route that will return a 200 when the application is running. I've had to implement this in pretty much every Rails app I've ever worked on. This is a nice addition! If you're not familiar. This is
Jan 13, 2023 1 min read
Page 1 of 5 Older Posts →
Mike Coutermarsh © 2025
  • HTML/CSS to Image API
  • Twitter
  • GitHub
  • LinkedIn