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.
import Foundation | |
final class GCDLock<Value> { | |
var value: Value | |
let queue = DispatchQueue(label: "") | |
init(value: Value) { | |
self.value = value | |
} | |
func read() -> Value { |
import UIKit | |
extension UIImage { | |
convenience init?(uncachedName name: String) { | |
let deviceScale: Double = Double(UIScreen.mainScreen().scale) | |
let scaleFactors = [1.0, 2.0, 3.0].sort { x, y -> Bool in | |
let distanceA = abs(x - deviceScale) | |
let distanceB = abs(y - deviceScale) | |
return distanceA == distanceB ? x > y : distanceA < distanceB | |
} |
### 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: |
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 { |
#!/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', |
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) | |
} |
// ==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== | |
[ |
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.
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.
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 |