Skip to content

Instantly share code, notes, and snippets.

joakimk /
Last active May 5, 2021
Single core cpu performance test

Single core cpu performance.

echo 'int main() { double i = 0; for(i = 0; i < 5000000000; i++) { 20%7 * i; } }' > /tmp/test.c && gcc /tmp/test.c -o /tmp/test && time /tmp/test && rm /tmp/test.c && rm /tmp/test

NOTE: It's not 100% reliable since it differs depending on compiler version.

Platform                   CPU                   Time
MacBookPro15,1 (Mid 2018)  i9 2.4 ghz            11.1 
iMac15,1 (Late 2014)       i7 4.0 ghz            11.7
PC (Early 2016, i5 4690k)  i5 3.5 ghz            12.0
joakimk /
Last active Feb 25, 2021
Building custom ruby images to use the latest versions (e.g. to get security fixes earlier)

Building custom ruby-alpine

Check the alpine version of the previous image.

alpine3.9 master$ docker run -it ruby:2.5.4-alpine sh
/ # cat /etc/alpine-release 
/ # ruby -v
ruby 2.5.4p155 (2019-03-13 revision 67245) [x86_64-linux-musl]
joakimk / controller.rb
Created Feb 17, 2012
A way to lazy load partials in Rails 3
View controller.rb
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
joakimk /
Last active Dec 4, 2020
CircleCI elixir build example

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible.

We've been using this for months in multiple projects without any issues. Please ping be if there is any issues with this script and I'll update it.

It should be generic enough to work on any elixir app using mix.

If you have a elixir_buildpack.config, then enable that section in the build script to keep versions in sync!

2016-08-09: Updated to newer Erlang and Elixir and fixed curl command.

joakimk /
Created Oct 12, 2010
Script to install a PXE boot server for diskless clients
# This installs a PXE boot server.
# It's based on
# It's been used with ubuntu-10.10-server-amd64.iso and ubuntu-10.10-server-i386.iso.
# It requires two network cards. One for access to the outside world and one
# for a private network of PXE clients. I've choosen this setup to not cause problems
# with DHCP on the normal network.
# It also requires that you have a second partition mounted on /nfsroot.
joakimk / webpacker-environment.js
Last active Oct 11, 2018
non-digested assets in webpack (e.g. non-stupid-digest-assets for webpacker)
View webpacker-environment.js
// Didn't find anything on google for this so I wrote my own. Use as a starting point if you have a similar problem.
// Please write comments if there is a better way to do this (or solve the same problem in another way) in webpack.
// Contents of config/webpack/environment.js:
const { environment } = require('@rails/webpacker')
// Generate undigested assets for use in embedded javascript, emails, etc.
// We previously used non-stupid-digest-assets for this.
joakimk /
Last active Apr 5, 2018
Running tests in tmux from Atom
# Atom -> Init Script...
child = require "child_process"
runTestInTmux = (focus) ->
editor = atom.workspace.getActiveTextEditor()
fullPath = editor.getPath()
projectPath = atom.project.getDirectories()[0].getPath() + "/"
joakimk /
Last active Mar 18, 2018
How we made our commit to production time twice as fast using heroku pipelines


We started out with two apps.

  • foo-staging
  • foo-production

Our CI would run tests, then deploy to staging, run smoke tests and then run to production and run smoke tests.

This took about 22-25 min.

joakimk /
Created Sep 11, 2016
heroku: Could not connect to database to initialize transfer

If you're seeing this error, try heroku ps:scale web=0 then import the database again and run heroku ps:scale web=1 afterwards. Found nothing on google for this error, so posting this gist with the solution that worked for me. Could have been a temporary error too.