Skip to content

Instantly share code, notes, and snippets.

@msanders
msanders / README.md
Last active April 14, 2024 20:49
Userscript: YouTube usability improvements

Userscript: YouTube usability improvements

Short userscript that disables frequently mistyped shortcuts (e.g. 0-9 number keybindings) and auto-looping on shorts.

Also available on GreasyFork.

Installation

To install, open the raw link and follow the prompt on the Userscripts, Violentmonkey, or Greasemonkey extension modal. Alternatively, you can create a new JavaScript item on the extension page and copy/paste the script. On iOS, go to the same link and tap the puzzle icon in the address bar and then the “Userscripts” menu item.

@msanders
msanders / README.md
Last active March 13, 2024 01:56
Export cookies from a Firefox profile to cookies.txt format

Background

http://fileformats.archiveteam.org/wiki/Netscape_cookies.txt

Installation

mkdir -p ~/bin
curl --proto "=https" --tlsv1.2 https://gist.githubusercontent.com/msanders/0715f4a1d64190011d7813e57a2e8ffe/raw/firefox_export_cookies_txt > ~/bin/firefox_export_cookies_txt
chmod u+x ~/bin/firefox_export_cookies_txt
@msanders
msanders / README.md
Last active January 26, 2024 00:18
Verbose regular expressions and memoization in fish shell

Implementation

Converts a verbose regex back to compact form, i.e. joined and without comments or unescaped whitespace. Similar to re.VERBOSE in Python.

function verbose_regex --argument-names pattern --description "Converts a \
verbose regex back to compact form, i.e. joined and without comments or \
unescaped whitespace. Similar to re.VERBOSE in Python"
    # See https://docs.python.org/2/library/re.html#re.VERBOSE
    echo $pattern |
@msanders
msanders / README.md
Last active March 13, 2024 01:58
Backup and restore cookie and site exception list in Firefox

Installation

mkdir -p ~/bin
curl --proto "=https" --tlsv1.2 https://gist.githubusercontent.com/msanders/57837aaf6f7da30dcc1eb0bdf6b0b733/raw/firefox_export_cookie_exceptions > ~/bin/firefox_export_cookie_exceptions
curl --proto "=https" --tlsv1.2 https://gist.githubusercontent.com/msanders/57837aaf6f7da30dcc1eb0bdf6b0b733/raw/firefox_restore_cookie_exceptions > ~/bin/firefox_restore_cookie_exceptions
chmod u+x ~/bin/firefox_export_cookie_exceptions  ~/bin/firefox_restore_cookie_exceptions 
mkdir -p ~/.local/share/fxcookies

# NOTE: Firefox must be closed in order for restore to unlock the database.
@msanders
msanders / README.md
Last active January 13, 2024 18:02
Automatically backup Kobo eReader with Hammerspoon

Example config to automatically backup Kobo eReader to ~/Backups/Kobo/ whenever it is mounted using rsync. Can be copied to Hammerspoon init.lua config file.

Tested on Hammerspoon 0.9.100, macOS 14.2.

@msanders
msanders / old-reddit-redirect.user.js
Last active February 21, 2024 14:22
Userscript: Old Reddit Redirect
// ==UserScript==
// @name Old Reddit Redirect
// @description Redirects www.reddit.com to the old version of the website
// @downloadURL https://gist.githubusercontent.com/msanders/52700d5c5ed76f1114594ddb862b530e/raw/old-reddit-redirect.user.js
// @updateURL https://gist.githubusercontent.com/msanders/52700d5c5ed76f1114594ddb862b530e/raw/old-reddit-redirect.user.js
// @version 2023.10.19
// @run-at request
// ==/UserScript==
[
@msanders
msanders / read-icon.swift
Last active January 7, 2020 22:00
Rough sketch of tool to generate an icns image from a file's icon.
import AppKit
import Darwin
var stderr = FileHandle.standardError
extension FileHandle: TextOutputStream {
public func write(_ string: String) {
guard let data = string.data(using: .utf8) else { return }
write(data)
}
#!/usr/bin/env ruby
require 'optparse'
options = {}
optionparser.new do |opts|
opts.banner = 'usage: find-types.rb [options]'
opts.on('-f', '--file file', 'swift source file') { |v| options[:file] = v }
opts.on('-d',
'--directory directory',
@msanders
msanders / RandomBackoff.swift
Created October 30, 2017 22:49
Exponential Backoff And Jitter
extension CountableClosedRange {
var randomElement: Element {
let distance = self.distance(from: startIndex, to: endIndex)
let offset = arc4random_uniform(UInt32(distance))
return self[index(startIndex, offsetBy: Bound.Stride(offset))]
}
}
enum Random {
### Keybase proof
I hereby claim:
* I am msanders on github.
* I am mkskm (https://keybase.io/mkskm) on keybase.
* I have a public key whose fingerprint is 879D 9776 6369 9CBB 5225 A842 A4EC D720 95C1 EA72
To claim this, I am signing this object: