Skip to content

Instantly share code, notes, and snippets.

View marckohlbrugge's full-sized avatar
🏠
Working from home

Marc Köhlbrugge marckohlbrugge

🏠
Working from home
View GitHub Profile
<!-- Do Not Track -->
<script type="text/javascript">
// Global
window.trackingEnabled = function() {
var dnt = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
return !(dnt === "1" || dnt === "yes");
}();
</script>
<!-- Google Tag Manager, Segment, etc. -->
@mikker
mikker / 00 README.md
Created May 13, 2020 20:59
Open Reading List in Tabs.app

Open Reading List in tabs

  1. Make a new Automator document of type "App"
  2. Add these three steps in order
  3. Remember to replace mikker with your own username in the AppleScript scripts
require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
config = Rails.application.config
cookie = CGI::unescape(cookie)
salt = config.action_dispatch.authenticated_encrypted_cookie_salt
encrypted_cookie_cipher = config.action_dispatch.encrypted_cookie_cipher || 'aes-256-gcm'
# serializer = ActiveSupport::MessageEncryptor::NullSerializer # use this line if you don't know your serializer
serializer = ActionDispatch::Cookies::JsonSerializer
@hopsoft
hopsoft / prefetch.js
Last active December 27, 2023 02:45
Turbolinks Prefetching
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {
@waffleau
waffleau / extract_dominant_colors.rb
Last active March 27, 2024 10:22
Extract dominant colours from an image in Ruby using MiniMagick
def self.extract_dominant_colors(image_path, quantity=5, threshold=0.01)
image = MiniMagick::Image.open(image_path)
# Get image histogram
result = image.run_command('convert', image_path, '-format', '%c', '-colors', quantity, '-depth', 8, 'histogram:info:')
# Extract colors and frequencies from result
frequencies = result.scan(/([0-9]+)\:/).flatten.map { |m| m.to_f }
hex_values = result.scan(/(\#[0-9ABCDEF]{6,8})/).flatten
total_frequencies = frequencies.reduce(:+).to_f
# ENVs
# HEROKU_API_KEY
# HEROKU_APP_NAME
# Gemfile
# gem 'heroku-api'
# config/initializers/heroku.rb
unless (app_name = ENV["HEROKU_APP_NAME"]).nil?
require 'heroku-api'
@gmaclennan
gmaclennan / README.md
Last active June 21, 2019 14:57
Marker Dispersion

Uses d3-force to disperse overlapping markers on a mapbox-gl map.

Markers are tethered to their actual location, but have a collision force based on the radius of the icon. An additional force pulls icons towards their previous location (locations are calculated each time you move the map) to avoid markers jumping around excessively as they settle into different local minima on each re-draw.

@dylanjha
dylanjha / history.sh
Last active April 28, 2017 20:48
See what commands you run in your terminal most often. Run this to see which commands you should create new aliases for. Stolen from here: https://superuser.com/questions/250227/how-do-i-see-what-my-most-used-linux-command-are
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
@lawso017
lawso017 / mentionable_trix.js.coffee
Last active July 6, 2022 10:13
@mentions with trix-editor and selectize.js
window.addEventListener "trix-initialize", (e) =>
Utility.TrixMentions.prepare($(e.target))
@floscr
floscr / highscoreMoney.js
Last active May 30, 2016 21:53
Calculate the total amount on highscore.money
[].slice.call(document.querySelectorAll('table tr td:nth-child(2)')).reduce((total, num) => {
let numValue = parseInt(num.innerHTML.replace('$', ''));
return total + numValue;
}, 0) + '$';