Skip to content

Instantly share code, notes, and snippets.

@mkremins
mkremins / pbcopy.js
Created April 17, 2014 21:41
node.js: put text into OS X clipboard
function pbcopy(data) {
var proc = require('child_process').spawn('pbcopy');
proc.stdin.write(data);
proc.stdin.end();
}
@mkremins
mkremins / zip.clj
Last active August 29, 2015 13:55
Clojure utility fns for working with zippers
(require '[clojure.zip :as z])
(defn forms-zip
"Returns a clojure.zip zipper over a tree of Clojure forms."
[form]
(z/zipper coll?
#(if (map? %) (interleave (keys %) (vals %)) (seq %))
#(cond
(map? %1) (apply hash-map %2)
(seq? %1) %2
@mkremins
mkremins / partial.clj
Created January 27, 2014 23:07
clojure.core/partial with explicit argument ordering
(defn partial* [f & static-args]
(fn [& dynamic-args]
(loop [args []
static-args static-args
dynamic-args dynamic-args]
(if-let [static (first static-args)]
(if (= static :%)
(if-let [dynamic (first dynamic-args)]
(recur (conj args dynamic) (rest static-args) (rest dynamic-args))
(throw (Exception. "too few arguments")))
@mkremins
mkremins / gist:5818692
Created June 19, 2013 22:27
Bash: pretty-print currently available color codes
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
# Shamelessly stolen from:
@mkremins
mkremins / gist:4459835
Created January 5, 2013 04:54
Bukkit: detect whether an inventory click falls within the top or bottom inventory
@EventHandler
public void onInvClick(InventoryClickEvent event) {
Player p = (Player) event.getWhoClicked();
if(event.getRawSlot() == event.getSlot()) {
p.sendMessage("TOP");
}
else {
p.sendMessage("BOTTOM");
}
}