Skip to content

Instantly share code, notes, and snippets.

View mcav's full-sized avatar

Marcus Cavanaugh mcav

View GitHub Profile
@mcav
mcav / gist:1398162
Created November 27, 2011 21:13 — forked from CarlQLange/gist:1398137
Open all mp3s in all subfolders of ./muzak
import os
for subdir, dirs, files in os.walk('./muzak'):
for file in files:
if file.endswith('.mp3'):
os.system('open ".%s/%s"' % (subdir[1:], file))
@mcav
mcav / gist:4969790
Last active December 13, 2015 20:28
(defn export-twitter-archive []
(->> (for [f (.listFiles (io/file "tweets/data/js/tweets"))
:when (.endsWith (.getName f) ".js")]
(for [tweet (json/read-str (second (str/split (slurp f) #"=" 2)) :key-fn keyword)]
(assoc tweet
:date (java.util.Date. (:created_at tweet)))))
(apply concat)
(sort-by :date)
reverse))
~/projects/mcav $ cat /etc/hosts | 9:51PM Sat 16
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
(defn page-template [config post]
(list
"<!doctype html>"
[:html
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport" :content "width=680"}]
[:title (h (str (:title config) (when (:title post)
(str ": " (:title post)))))]
@mcav
mcav / gist:5323781
Created April 6, 2013 00:54
Type-checking an API method in 20 lines of Clojure.
(defmacro defapi [method metadata args & forms]
`(defn ~method [& {:as named-params#}]
;; preprocess arguments
(doseq [arg# '~args]
(let [param# (get named-params# (keyword arg#))
optional# (:optional (meta arg#))]
;; ensure all required arguments were provided
(when (and (not optional#) (nil? param#))
(throw (IllegalArgumentException.
(format "Argument \"%s\" is required and was not provided." (name arg#)))))
@mcav
mcav / gist:5468358
Created April 26, 2013 15:59
Recursively, losslessly convert all JPEGs into Progressive JPEGs
brew install jpeg
find . -type f -name '*.jpg' -exec jpegtran -progressive -outfile {} {} \;
@mcav
mcav / gist:6382880
Created August 29, 2013 20:15
dmesg output of hamachi with broken wifi
root@android:/ # dmesg
<6>[ 0.000000] Booting Linux on physical CPU 0
<6>[ 0.000000] Initializing cgroup subsys cpu
<5>[ 0.000000] Linux version 3.0.21-perf-g5d8e666-00002-gf46e44c (android-bld@aclgcl-ubnt) (gcc version 4.4.3 (GCC) ) #1 SMP PREEMPT Fri May 17 17:37:08 CST 2013
<4>[ 0.000000] CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c5387d
<4>[ 0.000000] CPU: VIPT nonaliasing data cache, VIPT aliasing instruction cache
<4>[ 0.000000] Machine: QCT MSM7x27a FFA
<6>[ 0.000000] Partition (from atag) boot -- Offset:28f Size:30
<6>[ 0.000000] Partition (from atag) system -- Offset:2bf Size:5a0
<6>[ 0.000000] Partition (from atag) cache -- Offset:85f Size:140
@mcav
mcav / gist:6720785
Created September 26, 2013 21:24
Converts vim-style TAGS files to emacs TAGS files.
(ns easytags.core
(:require [clojure.string :as str]))
(def fs (js/require "fs"))
(def format (.-format (js/require "util")))
(set! *print-fn* #(.log js/console))
(defn strip-regex [re]
(when re
@mcav
mcav / exec-last-iterm-command.el
Created October 10, 2013 18:05
Executes the most recent iTerm command from right within Emacs. Useful for unit testing, etc.
(defun exec-last-iterm-command ()
(interactive)
(do-applescript
(concat
"set currentApp to (path to frontmost application as text)\r"
"tell application \"iTerm\" to activate\r"
"tell application \"System Events\"\r"
" delay 0.1\r"
" keystroke \"p\" using control down\r"
" keystroke return\r"
@mcav
mcav / com.mcav.arbpl.plist
Last active December 30, 2015 20:09
Launch ArbPL at startup, and keep it running forever.
<!--
Install with:
mkdir -p ~/Library/LaunchAgents
curl -o ~/Library/LaunchAgents/com.mcav.arbpl.plist https://gist.github.com/mcav/7879144/raw
launchctl load -w ~/Library/LaunchAgents/com.mcav.arbpl.plist
To stop:
launchctl unload ~/Library/LaunchAgents/com.mcav.arbpl.plist