Skip to content

Instantly share code, notes, and snippets.

@joakimk
joakimk / cpu_test.md
Last active March 26, 2024 20:25
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
joakimk / solution.md
Last active October 13, 2023 17:00
Seeing "Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT" after upgrading from Rails 3 to Rails 4?

For us this turned out to be that we had cached html generated by the rails 3 app that had the ASCII-8BIT encoding, clearing all html caches fixed this.

To arrive at this, we first added this debug code:

# if you reuse this: ensure it matches the method in your version of rails
# as the method is overwritten by this monkeypatch

# config/initializers/debug_encoding_errors.rb
ActiveSupport::SafeBuffer
@joakimk
joakimk / code.rb
Last active November 7, 2022 02:34
Save and restore cookies and session with capybara and apparition
# I have not deeply researched the best way of doing this. This is just one way.
# Made this gist because there was no google result for this exact question so I had to dive into the code instead.
# Saving
cookies = browser.driver.cookies.instance_variable_get(:@browser).get_raw_cookies.map { |c| c.instance_variable_get(:@attributes) }
cookies_json = cookies.to_json
# Restoring
cookies = JSON.parse(cookies_json)
cookies.each do |c|
@joakimk
joakimk / pxe_server_install.sh
Created October 12, 2010 16:41
Script to install a PXE boot server for diskless clients
# This installs a PXE boot server.
#
# It's based on https://help.ubuntu.com/community/DisklessUbuntuHowto.
# 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
joakimk / README.md
Last active January 1, 2022 23:21
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
joakimk / notes.md
Last active February 25, 2021 14:25
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 
3.9.2
/ # ruby -v
ruby 2.5.4p155 (2019-03-13 revision 67245) [x86_64-linux-musl]
@joakimk
joakimk / controller.rb
Created February 17, 2012 10:40
A way to lazy load partials in Rails 3
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
end
@joakimk
joakimk / webpacker-environment.js
Last active October 11, 2018 18:31
non-digested assets in webpack (e.g. non-stupid-digest-assets for webpacker)
// 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
joakimk / init.coffee
Last active April 5, 2018 13:10
Running tests in tmux from Atom
# Atom -> Init Script...
child = require "child_process"
runTestInTmux = (focus) ->
editor = atom.workspace.getActiveTextEditor()
editor.save()
fullPath = editor.getPath()
projectPath = atom.project.getDirectories()[0].getPath() + "/"