Skip to content

Instantly share code, notes, and snippets.

@msanders
msanders / README.md
Last active August 30, 2024 17:12
Script to update Kiwix catalog automatically using aria2c

Minimal script to update a Kiwix catalog. Supports automatically resuming partial downloads, can safely set and forget.

Installation

curl --proto "=https" --tlsv1.2 "https://gist.githubusercontent.com/msanders/903923ce83040054a09907b376b89c7d/raw/kiwix_catalog_update" -o /usr/local/bin/kiwix_catalog_update
chmod u+x /usr/local/bin/kiwix_catalog_update

Requirements

@msanders
msanders / README.md
Last active August 30, 2024 17:16
Script to remove all cookies from Safari except for a list of domains

Installation

First, install CookiesTool to a location of your choice (by default the script looks for ~/bin/CookiesTool).

Then download the script below.

curl --proto "=https" --tlsv1.2 "https://gist.githubusercontent.com/msanders/365b06cbc2f9c63981f4ab88234cd330/raw/safari_clear_cookies" -o /path/to/safari_clear_cookies
chmod u+x /path/to/safari_clear_cookies
@msanders
msanders / README.md
Last active May 18, 2024 05:16
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 August 29, 2024 20:45
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 September 2, 2024 23:06
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',