Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / file.md
Last active February 5, 2026 04:31
Using Jemalloc 5 with Ruby.md

For years, people have been using jemalloc with ruby. There were various benchmarks and discussions. Legend had it that Jemalloc 5 didn't work as well as Jemalloc 3.

Then, one day, hope appeared on the horizon. @wjordan offered a config for Jemalloc 5.

Ubuntu/Debian

FROM ruby:3.1.2-bullseye
RUN apt-get update ; \

This recipe is a work in progress and has never been run as-is.

  • timeouts are in ms
  • lock timeout: in postgres, when a statement that wants a restrictive lock waits on another lock, other statements that want locks can't jump the queue. so even though the statement that is waiting might only take a very short amount of time, when it starts running, while it is waiting no other statements can begin. So we set the lock timeout pretty low and retry if we don't get it.
  • statement timeout: we set a short statement timeout before statements which do lock and which we expect to take a short amount of time, just in case something about our assumptions/understanding is wrong and the statement ends up taking a long time. if this happens the statement will bail early without causing harm, and we can investigate what is wrong with
@jjb
jjb / code.rb
Last active March 25, 2025 13:36
delete old branches on github
#!/usr/bin/env ruby
require 'date'
require 'shellwords'
REMOTE = 'origin'
PROTECTED_BRANCHES = ['master']
YEARS_OLD = 2
def run_command(cmd)
@jjb
jjb / gist:996292
Created May 27, 2011 22:11
How to securely acquire the Mozilla root certificate bundle for use with curl, Net::HTTP, etc.

If you want to use curl or net-http/open-uri to access https resources, you will often (always?) get an error, because they don't have the large number of root certificates installed that web browsers have.

You can manually install the root certs, but first you have to get them from somewhere. This article gives a nice description of how to do that. The source of the cert files it points to is hosted by the curl project, who kindly provide it in the .pem format.

problem: Sadly, ironically, and comically, it's not possible to access that file via https! Luckily, the awesome curl project does provide us with the script that they use to produce the file, so we can do it securely ourselves. Here's how.

  1. git clone https://github.com/bagder/curl.git
  2. cd curl/lib
  3. edit mk-ca-bundle.pl and change:
@jjb
jjb / gist:7389552
Last active December 22, 2024 15:58
Ruby 2.1 memory configuration

This all applies to Ruby 2.1. In some cases a setting is not available in 2.0, this is noted. There is also a different with 1.9, 1.8, and REE --- these are not noted.

All the relevant code is in https://github.com/ruby/ruby/blob/master/gc.c

RUBY_HEAP_MIN_SLOTS

default: 10000

The number of heap slots to start out with. This should be set high enough so that your app has enough or almost enough memory after loading so that it doesn't have to allocate more memory on the first request (althogh this probably isn't such a big deal for most apps).

(todo: figure out how big a slot is. i think the answer can be infered from this code.)

@jjb
jjb / code.rb
Last active December 16, 2024 19:35
Script to delete old git branches
# frozen_string_literal: true
require 'time'
# Get the list of branches with their last commit date
branches = `git for-each-ref --format '%(refname:short) %(committerdate)' refs/heads/`
months_ago = 12
threshold = Time.now - (months_ago * 30 * 24 * 60 * 60)
@jjb
jjb / shipyard-shell.sh
Created June 22, 2023 17:48
Shipyard Shell
#!/usr/bin/env sh
# usage
# shipyard-shell PRNUMBER SERVICENAME
# shipyard-shell 6187 postgres
# shipyard-shell 6187 api
pr=$1
service=$2
identifier=`shipyard get environments | grep pr$pr | xargs | cut -w -f1` # xargs to remove leading and trailing whitespace

Here's something I spent a long time debugging, so I'm making this gist to help others find the solution when searching.

Summary

postgres 12 on MacOS will cause crashes when forking. The solution is to do one of these two things:

  • add gssencmode: "disable" to database.yml
  • if using homebrew: uninstall postgres, update homebrew, reinstall postgres

Here's some discussion:

@jjb
jjb / gist:7175694
Last active July 20, 2024 18:17
How to configure Textmate to use the rbenv ruby and gems
  1. Preferences -> Variables
  2. add this to the front of PATH: $HOME/.rbenv/bin:$HOME/.rbenv/shims:
  3. set TM_RUBY to this: $HOME/.rbenv/shims/ruby
  4. populate RBENV_VERSION with your version. example: 2.1.0-preview1
  5. (and make sure the checkboxes for each of those variables is selected)
@jjb
jjb / colors.md
Created June 27, 2024 19:17
Monokai Pro Colors
  • #2c292d $\textcolor{#2c292d}{\texttt{█ black}}$
  • #fdf9f3 $\textcolor{#fdf9f3}{\texttt{█ white}}$
  • #ff6188 $\textcolor{#ff6188}{\texttt{█ red}}$
  • #fc9867 $\textcolor{#fc9867}{\texttt{█ orange}}$
  • #ffd866 $\textcolor{#ffd866}{\texttt{█ yellow}}$
  • #a9dc76 $\textcolor{#a9dc76}{\texttt{█ green}}$
  • #78dce8 $\textcolor{#78dce8}{\texttt{█ blue}}$
  • #ab9df2 $\textcolor{#ab9df2}{\texttt{█ purple}}$