Skip to content

Instantly share code, notes, and snippets.

@brokaw
brokaw / gist:1136775
Created August 10, 2011 13:19 — forked from gruber/gist:1063605
Simple Inbox Archiving Script for Apple Mail
-- See article here: http://daringfireball.net/2007/07/simple_inbox_sweeper
-- The following should be one long line:
set _description to "All unflagged, read messages in each IMAP account
inbox will be moved to the “Archive” mailbox corresponding to that
account. This action is not undoable."
tell application "Mail"
display alert "Archive read messages from IMAP inboxes?" buttons ¬
{"Cancel", "Archive"} cancel button 1 message _description
@brokaw
brokaw / post-commit
Created September 12, 2011 16:52
Jekyll Deployment on NFSN
TMP_CLONE_DIR=$(mktemp -d -t sitename)
git clone ${HOME}/site.git ${TMP_CLONE_DIR}
jekyll ${TMP_CLONE_DIR} ${DOCUMENT_ROOT}
rm -rf ${TMP_CLONE_DIR}
@brokaw
brokaw / count-change
Created September 20, 2011 15:48
count-change from SICP Chapter 1
(define (count-change amount)
(cc amount 5))
(define (cc amount kinds-of-coins)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(else (+ (cc amount
(- kinds-of-coins 1))
(cc (- amount
(first-denomination kinds-of-coins))
@brokaw
brokaw / acl-monitor.sh
Created September 21, 2011 21:55
Monitor the Last-Modified HTTP header on www.aclfestival.com. Designed for Mac OS X.
#!/bin/bash
# $1 = recipient
# $2 = The Subject
# $3 = The message content
sendapplemail() {
/usr/bin/osascript >/dev/null 2>&1 <<EOF
tell application "Mail"
set myContent to quoted form of "$3"
set theMessage to make new outgoing message with properties {subject:"$2", content:myContent, sender:"Steve Brokaw <steve@jetseven.org>"}
@brokaw
brokaw / PrettyJSON.py
Last active February 2, 2024 04:29
A BBEdit text filter to prettify JSON.
#!/usr/bin/env python3
# A text filter for BBEdit. If it encounters a JSON error, it writes an error message
# to stderr (appears in a new BBEdit window) and leaves the original text unaltered.
# c.f. http://crisp.tumblr.com/post/2574967567/json-pretty-print-formatting-in-bbedit
# c.f. http://blog.scottlowe.org/2013/11/11/making-json-output-more-readable-with-bbedit/
import json
import sys
def main():
#!/usr/bin/env python
# Requires third-party markdown library. pip install --user Markdown
import sys
import markdown
def main():
input = sys.stdin.read()
extensions = ['markdown.extensions.extra',
@brokaw
brokaw / CBUUID to UUID
Last active April 15, 2019 17:16
Extension on CBUUID to return a UUID
extension CBUUID {
var UUIDValue: UUID? {
get {
return self.data.withUnsafeBytes { buffer in
guard buffer.count == MemoryLayout<uuid_t>.size else { return nil }
let uuid = buffer.bindMemory(to: uuid_t.self)
return UUID(uuid: uuid.baseAddress!.pointee)
}
}
}
@brokaw
brokaw / Vagrantfile
Created March 18, 2017 15:18
A Vagrant file for Stanford Compilers course
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@brokaw
brokaw / fibonacci.swift
Last active April 2, 2017 19:04
Learning Swift sequence protocols
struct FibIterator: IteratorProtocol {
var currentCount = 0
var maxCount: Int?
var maxValue: Int?
var currentFib: Int
var previousFib: Int
mutating func next() -> Int? {
if let maxCount = maxCount, currentCount >= maxCount {
return nil
}
@brokaw
brokaw / vex
Last active November 11, 2017 16:06
Replacement for $VIRTUAL_ENV/bin/activate
#!/bin/sh
# vex: Virutalenv EXecute
# Inspired by https://gist.github.com/datagrok/2199506
VEXPATH="$(dirname $0)"
export PS1='\[\e[1;31m\](python3)\[\e[0m\] \h:\W \u\$ '
export VIRTUAL_ENV="$HOME/Library/Python/virtualenvs/py3"
export PATH="$VEXPATH:$VIRTUAL_ENV/bin:$PATH"
unset PYTHON_HOME
exec "${@:-$SHELL}"