Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Example pre-commit hook: triggers rubocop & eslint on staged files.
#
# To use it, create a symlink in your .git/hooks directory:
#
# $ ln -s $(pwd)/bin/pre-commit .git/hooks
set -e
# Ruby
function initComponent(root, goDeep = true) {
const component = root.dataset.component;
const targets = {};
const state = {};
root.querySelectorAll(`[data-${component}-target]`).forEach((attr) => {
targets[attr.getAttribute(`data-${component}-target`)] = attr;
});
Array.from(root.attributes).forEach((attr) => {
@pch
pch / base32.rb
Last active December 18, 2023 08:21
Base32 encoding in Ruby (RFC 4648)
# Base32 (RFC 4648) implemented in Ruby
#
# Source: https://ptrchm.com/posts/base32-explained/
class Base32
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".split("")
PADDING_CHAR = "="
BITS_PER_BYTE = 8 # 1 byte = 8 bits
BITS_PER_CHAR = Math.log2(ALPHABET.length).round # 5 = 32 chars = 2^5 number of bits encoded into a single character in the ALPHABET
BITS_PER_CHUNK = BITS_PER_CHAR.lcm(BITS_PER_BYTE) # 40 (least common mutliple of 5 and 8)
@pch
pch / settings.json
Created January 27, 2024 13:59
vscode settings for eslint, prettier, ruby-lsp
{
"editor.overviewRulerBorder": false,
"[typescript, javascript]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[ruby]": {
@pch
pch / typeerror.md
Created February 2, 2024 07:51
Rails, Turbo, esbuild: TypeError: map.get is not a function

(This applies to Rails 7.1, Turbo 8.0 with esbuild and propshaft)

If you're getting a "TypeError: map.get is not a function" when navigating between pages:

Uncaught (in promise) TypeError: map.get is not a function
    at fetch (application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:6485:20)
    at fetchWithTurboHeaders (application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1153:10)
    at FetchRequest.perform (application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1263:25)
fetch @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:6485