Skip to content

Instantly share code, notes, and snippets.

View nriley's full-sized avatar

Nicholas Riley nriley

View GitHub Profile
@nriley
nriley / Go home.applescript
Created March 5, 2012 23:27
Multiple disk unmounting script with Time Machine to disk image/iTunes support
property _timeMachineDiskName : "Backup of Babs"
property _diskNamesToTryToEject : {"MaryMedia", "MaryBackup+", "ShirleyClone", "ShirleyLion", "bzzt"}
property _growlApplication : "Go home"
property _growlNotification : "Status"
on _notify(_title, _description)
tell application "GrowlHelperApp" to notify with name _growlNotification title _title description _description application name _growlApplication identifier _growlNotification
end _notify
@nriley
nriley / extract.py
Created June 27, 2013 06:51
Extract English subtitle text for WWDC 2013 videos.
import requests
import os, re, sys
RE_SD_VIDEO = re.compile(
r'<a href="(http://devstreaming.apple.com/videos/wwdc/2013/[^"]*-SD.mov)')
RE_WEBVTT = re.compile(r'fileSequence[0-9]+\.webvtt')
# stdin: dump of https://developer.apple.com/wwdc/videos/
for l in sys.stdin:
m = RE_SD_VIDEO.search(l)
@nriley
nriley / Save to Date.scpt
Last active August 29, 2015 13:56
Save to Date
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on dlog(foo)
@nriley
nriley / better-buff-menu.el
Created August 22, 2015 16:48
better buffer switching - a bit like electric-buffer-list, but with fit-to-buffer and window management that makes more sense to me
(global-set-key (kbd "C-x C-b")
(lambda ()
(interactive)
(let ((buffer-list-window (list-buffers)))
(fit-window-to-buffer buffer-list-window)
(select-window buffer-list-window)
(setq tabulated-list-sort-key '("File"))
(tabulated-list-init-header)
; don't try to preserve selection, because...
(tabulated-list-print nil)
local _outlinePath, _htmlPath, _htmlFolder, _outlineName, _itemsToCommit
tell application "OmniOutliner Professional"
tell front document
save
set _outlineName to name
set _outlinePath to path
end tell
set _htmlPath to ((characters 1 thru ((count characters of _outlinePath) - 4) of _outlinePath) as string) & ".html"
set _htmlFolder to (_htmlPath as POSIX file)
@nriley
nriley / ts.zsh
Created February 6, 2016 17:11
Timestamp your command output with zsh
ts() {
local tspty=tspty.$(/usr/bin/uuidgen)
zmodload zsh/zpty
zpty $tspty $@
setopt localtraps
TRAPINT() { zpty -d $tspty }
while zpty -r $tspty line; do
print -Pn '%B%D{%m/%d %H:%M:%S}%b '
print -n -- $line
done
@nriley
nriley / Move to Top.applescript
Created April 25, 2016 12:25
Move tasks to the top of their containing task or project in OmniFocus
tell application "OmniFocus"
tell default document's first document window's content
set _tasks to (selected trees where its value's class is task)'s value
set _tasks to _tasks's reverse
repeat with _task in _tasks
tell _task's parent task
move _task to beginning of tasks
end tell
end repeat
end tell
@nriley
nriley / archive-application.sh
Last active March 3, 2018 16:28
Script to archive a macOS application.
#!/bin/zsh -ef
set -x
app="$1"
# https://stackoverflow.com/a/1665662/6372
space_version=$(/usr/local/bin/launch -f "$1" |
sed -e 's/^ version: \(.*\) \[.*/ \1/; t' \
-e 's/^ version: \(.*\)/ \1/; t' \
@nriley
nriley / README.md
Last active April 1, 2017 14:55
Fake switching with homebridge-websocket

Update

The below continues to work, but homebridge-http-webhooks is much easier to set up and use as it only requires a HTTP request. With this package, you configure individual switches from config.json.

    "platforms": [
[...]
        {
            "platform": "HttpWebHooks",
 "webhook_port": 4051,
@nriley
nriley / get_lutron_cert.sh
Created October 14, 2017 15:55 — forked from mhofman/get_lutron_cert.sh
Generate a signed certificate valid to connect locally to a Lutron Caseta Smart Bridge
#!/bin/bash
# Usage: get_lutron_cert.sh [bridge_ip] | tee cert.pem
function error() {
echo "Error: $1" >&2
exit 1
}
login_server="device-login.lutron.com"