Skip to content

Instantly share code, notes, and snippets.

View bramswenson's full-sized avatar

Bram Swenson bramswenson

View GitHub Profile
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.
bramswenson / idyll.vim
Last active November 27, 2017 00:57
Syntax highlighting for markdown. I mean Idyll.
" Vim syntax file
" Language: Idyll
" Maintainer: Ricky Reusser <>
" Filenames: *.idl
" Last Change: 2017 May 27
if exists("b:current_syntax")
bramswenson / cors.nginxconf
Created July 25, 2017 00:51 — forked from pauloricardomg/cors.nginxconf
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
# Based on:
# *
# *
server {
Fri Mar 10 02:38:28 UTC 2017
bramswenson /
Last active September 19, 2023 17:34
Bootstrap Security - Encrypted USB + Yubikey + GPG + SSH

Bootstrap Security - Encrypted USB Storage + Yubikey + GPG + SSH

The purpose of this guide is to provide step by step instructions to bootstrap a secure identity with GPG + SSH Keys.

  1. Format USB Storage Device with LUKS Encryption
  2. Create GPG master keypair and subkey
  3. Move GPG master keypair to Encrypted USB Storage
  4. Create SSH Keys and backup to Encrypted USB Storage

Keybase proof

I hereby claim:

  • I am bramswenson on github.
  • I am bramswenson ( on keybase.
  • I have a public key ASAo8IjaDiHGj-aGHh8WHojKzlHrwVi_VBC4yGZHhba7wAo

To claim this, I am signing this object:

1) TCPSocket fails when connection is refused
Failure/Error: expect_raises(Errno, "Error connecting to 'localhost:#{port}': Connection refused") do
expected Errno with "Error connecting to 'localhost:40793': Connection refused", got #<Errno: Error connecting to 'localhost:40793': Network is unreachable> with backtrace:
# [11810935] *CallStack::unwind:Array(Pointer(Void)) +87
# [11810826] *CallStack#initialize<CallStack>:Array(Pointer(Void)) +10
# [11810778] *CallStack::new:CallStack +42
# [8993288] *raise<Exception+>:NoReturn +24
files: ./spec/**/*
run: crystal spec %file%
files: ./src/**/*.cr
run: crystal spec

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration: