Skip to content

Instantly share code, notes, and snippets.


Jamie Gaskins jgaskins

View GitHub Profile
jgaskins /
Last active Nov 17, 2022
Running Mastodon on Kubernetes
#!/usr/bin/env bash
# Install nginx ingress controller
# NOTE: This uses DigitalOcean. If you use another Kubernetes provider,
# substitute the appropriate command from here:
kubectl apply -f
export # Make this the DNS name that will point to your LB
export LB_NAME=my-lb # Give this a useful name to identify it on the DigitalOcean control panel
jgaskins /
Created Nov 1, 2022
Give DigitalOcean load balancers provisioned for Kubernetes clusters a name and hostname so the Cert Manager HTTP solver will work
#!/usr/bin/env bash
# Fill out these two
export LB_NAME=my-lb
echo '{"metadata":{"annotations":{"":"$LB_HOSTNAME","":"$LB_NAME"}}}' |
envsubst |
awk "{ print \"'\" \$1 \"'\" }" |
xargs kubectl patch svc -n ingress-nginx ingress-nginx-controller -p
jgaskins /
Created May 11, 2022
Project-local requires in Crystal
# Experiment with macros to allow for project-local requires
{% begin %}
ROOT = "{{system("pwd")}}"
{% end %}
macro spec(file)
macro load_spec
\{% path = __DIR__.gsub(%r{\A{{}}}, "").gsub(%r{[^/]+}, "..").id %}
require "\{{path[1..]}}/spec/{{}}"
jgaskins /
Last active Jan 30, 2022
Elasticsearch Example in Crystal
require "http"
require "json"
require "uuid/json"
require "db"
require "interro" # github: jgaskins/interro
require "faker" # github: askn/faker
ES =
pg ="postgres:///")
Interro.config { |c| c.db = pg }
jgaskins /
Last active Jan 5, 2022
Array that does not let you mutate while inside an `each` block
class ImmutableEachArray(T)
include Enumerable(T)
@iterating = Atomic(Int32).new(0)
@array = Array(T).new
def <<(value : T) : self
raise"you iteratin bruh") if @iterating.get > 0
@array << value
jgaskins /
Last active May 28, 2021
Benchmarking Redis drivers: Ruby gem, Hiredis, and a custom Ruby implementation


Name Description
ruby The redis gem with the plain-Ruby driver
hiredis The redis gem with the hiredis driver (compiled as a C extension)
myredis Pure-Ruby, optimized for the specific operation


jgaskins / benchmark.rb
Last active Jun 25, 2022
Benchmarking redis gem vs hiredis vs custom Redis client
View benchmark.rb
require 'bundler/inline'
require 'socket'
class MyRedis
CRLF = "\r\n"
def initialize
@connection ='localhost', 6379)
@connection.sync = false
jgaskins /
Created Jan 18, 2021
Roda-like routing mixin for Crystal
require "http"
require "./route"
class App
include HTTP::Handler
include Route
def call(context)
route context do |r, response|
jgaskins /
Created Dec 3, 2020
Benchmarking allocation time of Crystal objects with various quantities of instance variables
require "benchmark"
value = nil
Benchmark.ips do |x| "1 ivar" { value = } "2 ivars" { value = } "4 ivars" { value = } "8 ivars" { value = } "16 ivars" { value = }
jgaskins /
Created Jun 28, 2020
Compare parsing an int as intermediate strings vs using a byte parser directly on the IO
require "benchmark"
int = 0
[1, 12, 1234, 12345678, 1234567812345678].each do |number|
puts "Parsing #{number}..."
io =
io << ":#{number}\r\n" # Redis integer format
Benchmark.ips do |x|