Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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() + "/"
@joakimk
joakimk / pipeline.md
Last active March 18, 2018 08:37
How we made our commit to production time twice as fast using heroku pipelines

Background

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
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 / elm-and-atom.md
Last active November 20, 2017 17:03
Elm and Atom setup

Some notes on my Elm development environment.

The most important thing is elm-format. It auto-formats the code when you save. You will likely miss this in other languages.

  1. brew install elm elm-format
  2. Install Atom
  3. Elm plugins: elm-format language-elm
  4. Vim plugins: ex-mode vim-mode-plus

Currently evaluating the elmjutsu plugin.

@joakimk
joakimk / code.js
Last active June 12, 2017 17:38
#live_coding Simple example
/* jshint asi:true */
// PixiJS v4 example (WebGL rendering)
model = loadStateOrDefaultTo({
move: 1
})
tick = (delta) => {
if(codeHasChanged()) { return }
@joakimk
joakimk / research.md
Last active May 12, 2017 07:26
Research: Why is single Elixir unit tests slow to run?

Instant-feeling unit tests improves productivity and developer happiness :)

Elixir tooling isn't quite there the way Ruby can be when optimized.

Ruby benchmarks:

  • instant 46ms base time (time ruby -e "")
  • instant 190ms running a ruby unit test doing nothing
  • in 50k line rails app:
  • okay 640ms bundler (time bundle exec ruby -e "")
@joakimk
joakimk / talks_and_articles.md
Last active October 6, 2016 08:09
A collection of good talks and articles by topic. Elixir, Elm, Ruby, ...

Building a little list so I can more easily recommend the best talks and be able re-watch them myself.

Elm

@joakimk
joakimk / Update.elm
Last active September 22, 2016 19:19
One attempt at simple adding or updating a record in a list in Elm
import UpdateList exposing (addOrUpdateById)
update msg model =
case msg of
NewOrUpdatedItem item ->
({model | items = model.items |> addOrUpdateById item}, Cmd.none)