Skip to content

Instantly share code, notes, and snippets.

@kch
kch / 1-safari-cursor-parking.md
Last active August 6, 2026 04:08
Change the URL with pushState/replaceState in Safari and the cursor under the user's stationary pointer is swapped for an arrow, staying wrong until they move the mouse. The WebKit cause, the dead ends, and a fix that works, with a demo.

Safari swaps the cursor out from under a stationary pointer when the URL changes

If your page updates the address bar without navigating, history.pushState or history.replaceState, Safari replaces the mouse cursor with the default arrow and will not reconsider until it sees a real mouse event.

The damage is in the timing. A cursor is supposed to describe whatever is under the pointer, and it changes when the pointer moves. This changes it while the pointer is perfectly still, which is exactly when the user has no reason to expect it and no way to trigger a correction: they clicked something and are looking at the result. Whatever they

@kch
kch / structure_dump_cleanup.rb
Last active July 6, 2025 21:05
Clean trailing newlines and spaces from structure.sql after dumping
# config/initializers/structure_dump_cleanup.rb
# Clean trailing newlines and spaces from SQL schema dump file after dumping
module StructureDumpWhitespaceCleanup
def structure_dump(cfg, fn, *) = super.tap{ @dump_file = fn }
def dump_schema(...)
super.tap do
next unless fn = @dump_file
File.write fn, File.read(fn).gsub(/[ \t]+\n/, "\n").sub(/\s+\n\z/, "\n")
end
@kch
kch / iterm2-edit
Last active June 30, 2025 17:59
iTerm2 file opener for semantic history
#!/opt/homebrew/opt/ruby/bin/ruby
# iTerm2 file opener for semantic history
#
# Setup: iTerm2 » Settings » Profiles » Advanced » Semantic History » Always run command…
# Command: /path/to/iterm2-edit \5 \1
#
# Parses text selections and opens appropriate handler:
# - Text files: $EDITOR with line:col positioning
# - Binary files: system default app
@kch
kch / etc--supervisor.d--fswatch-chmod.ini
Last active June 30, 2025 21:18
auto make shebang files executable
[program:fswatch-chmod]
# For each changed file:
# - skips if not regular file
# - skips if no shebang
# - finds enclosing git repo (if any)
# - skips if file tracked and unchanged in that repo (prevent mangling checkouts / rebases)
# - otherwise makes file executable
# - ignore files inside .git but allow in .git/hooks/
command=bash -c '
/opt/homebrew/bin/fswatch -v -r ~/bin ~/src --exclude /\.git/ --include /\.git/hooks/ |
@kch
kch / git-reword
Last active July 9, 2025 21:12
reword commits inline in interactive rebase file
#!/usr/bin/env ruby
# git-reword: Interactive tool for bulk editing commit messages' first line
#
# Opens the rebase todo sequence for editing, amends any commit messages with
# the inline-reworded message. Other rebase operations are performed normally.
#
# If you reword inline but also use a reword action on the same line, the
# inline edit wins.
#
@kch
kch / scanl.rb
Last active December 31, 2023 10:22
ruby scanl
# Operating with plain arrays:
class Array
def scanl(init, &f)
return [init] if empty?
reduce([init]){ |xs, x| xs << f.(xs.last, x) }
end
def scanl1(&f)
return if empty? # might consider returning []
// ==UserScript==
// @name ⌘⌫ Element
// @description ⌘⌫ deletes element under cursor, ⌘Z puts back
// @match *://*.*
// ==/UserScript==
let undoWindow = 3000 // can undo for this long
let undoCooldown = 1500 // will prevent default undo for this long after last undo
let scheduledDeletion = null // timeout id for deleteElements
let lastHide = 0 // timestamp for last element was hidden
// ==UserScript==
// @name Youtube ensure HD
// @description Sets youtube player to highest resolution if drops from an HD res
// @match *://www.youtube.com/watch*
// @match *://youtu.be/watch*
// ==/UserScript==
let intervalID = setInterval(()=> {
let qs = (q) => document.querySelector(q)
let qsa = (q) => [...document.querySelectorAll(q)]
@kch
kch / wgt.rb
Created May 12, 2016 12:29
sort wgt bands by time, append location
#!/usr/bin/env ruby
s = ARGF.read =~ /Freitag, 13. Mai 2016.*?(?=\n\n)/m && $&
s.gsub! /^(\d\d)\.(\d\d)\u00A0Uhr\n/, "\\1:\\2h -- "
days = []
s.lines.each do |l|
case l
when /^\d\d:\d\dh -- Einlaß/ then :pass
when /Mai 2016$/ then days << [l, []]
when /^\d\d:\d\dh -- / then days.last[1] << l.sub(/\Z/, " -- @ #{$x}")
@kch
kch / infix-functions.swift
Last active July 17, 2016 20:30
Use any binary function as infix operator in Swift
infix operator « { precedence 131 associativity left }
func «<A,B,C>(a:A, f:(A,B) -> C) -> B -> C { return { f(a,$0) } }
infix operator » { precedence 131 associativity left }
func »<B,C>(f:(B) -> C, b:B) -> C { return f(b) }
infix operator < { precedence 131 associativity left }
func <<A,B,C>(a:A, f:(A,B) -> C) -> B -> C { return { f(a,$0) } }
infix operator > { precedence 131 associativity left }