Skip to content

Instantly share code, notes, and snippets.

View koppen's full-sized avatar

Jakob Skjerning koppen

View GitHub Profile
@koppen
koppen / chromedriver_update.sh
Last active August 22, 2023 07:40
Update for the new Chrome for Testing setup
#!/bin/bash
# This script installs the version of Chromedriver that matches the installed
# Chrome applicaton.
#
# It installs the chromedriver binary into ~/bin/. If an existing chromedriver
# is installed it will be replaced by the updated binary.
#
# Assumptions:
#
@koppen
koppen / visibility_controller.js
Created February 20, 2023 09:55
Stimulus controller that toggles the visibility of elements based on the current value of another element. Useful for showing different input fields based on fx a selection in a dropdown.
import { Controller } from 'stimulus'
// Sets the visibility of elements based on the checked state of a source
// element.
//
// source target is expected to emit a change event when the value changes so
// the UI can be updated.
//
// Target elements must be configured with a `data-visible-when` attribute set
// to either "on" or "off" depending on when the element should be visible. The
@koppen
koppen / pre-commit
Created March 28, 2022 08:06
.git/hooks/
#!/bin/sh
#
# Check for Ruby style errors using Rubocop
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
if git rev-parse --verify HEAD >/dev/null 2>&1
@koppen
koppen / pre-commit
Created January 25, 2016 08:50
Run rubocop on pre-commit
# .git/hook/pre-commit
#!/bin/sh
#
# Check for ruby style errors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
@koppen
koppen / configure.log
Last active February 22, 2021 14:57
Ruby 2.3, OpenSSL, RVM, macOS Mojave
configure: WARNING: you should use --build, --host, --target
checking for ruby... /Users/jakob/.rvm/rubies/ruby-2.6.0/bin/ruby
*** using http instead of https ***
config.guess already exists
*** using http instead of https ***
config.sub already exists
checking build system type... x86_64-apple-darwin18.7.0
checking host system type... x86_64-apple-darwin18.7.0
checking target system type... x86_64-apple-darwin18.7.0
checking whether the C compiler works... yes
@koppen
koppen / delayed_job_helpers.rb
Last active September 28, 2020 13:41
Delayed::Job helpers
module Delayed::Job::Ext
module_function
# Returns all failed jobs
def failed_jobs
Delayed::Job.where.not(:last_error => nil).order(:failed_at)
end
def failed_with(message)
failed_jobs.
@koppen
koppen / download.sh
Created November 16, 2017 13:01
Download n URLs
#!/bin/bash
COUNTER=0
while [ $COUNTER -lt 10 ]; do
let COUNTER=COUNTER+1
wget "http://domæne.dk/navn?id=$COUNTER"
done
def do_stuff
list = [1, 2, 3, 4, 5]
list.map { |value|
return "Fizz" if value == 3
value
}
end
p do_stuff
# frozen_string_literal: true
# A generic presenter class
class Presenter < SimpleDelegator
attr_reader :view
class << self
# Returns true if object has been wrapped in a Presenter
def decorated?(object)
object.is_a?(Presenter)
end
@koppen
koppen / repro.rb
Created September 14, 2016 14:51
Reproduction steps for ActiveRecord `touch` not clearing changes in `lock_version` when used with optimistic locking
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"