Skip to content

Instantly share code, notes, and snippets.

View jcromartie's full-sized avatar

John Cromartie jcromartie

View GitHub Profile
jcromartie / pre-commit
Created June 6, 2017 16:40
pre-commit hook which fails when untracked files are present in working tree
untrackedFiles=$(git ls-files --others --exclude-standard)
if [ ! -z "$untrackedFiles" ]
echo "There are untracked files in the working tree:"
echo "$untrackedFiles"
echo ""
echo "Are you sure you aren't forgetting something?"
(defn add-component
[system entity component data]
(-> system
(update-in [:identity entity] (comp set conj) component)
(assoc-in [component entity] data)))
(defn delete-component
[system entity component]
(-> system
(update-in [:identity entity] disj component)
(defun definitely-speedbar ()
(speedbar t))
(global-set-key [f11] 'definitely-speedbar)
jcromartie / uniq-live.rb
Created July 27, 2015 15:30
uniq live!
# uniq-live
# Reads from stdin or a given file and counts the number of times a
# given line repeats as it is read.
last = nil
count = 1
while !ARGF.eof? && line = ARGF.readline.strip do
jcromartie / git-cleanup
Created April 3, 2015 19:24
git cleanup - delete branches that are fully merged relative to the current branch
for branch in $(git branch --merged | grep -v '*')
read -n 1 -p "Delete ${branch} [y/N]? " answer
echo ""
if [[ "$answer" = "y" ]]
git branch -d "$branch"
function arrayAssocIn(obj, keys, val) {
var m = obj;
for (var ii = 0; ii < keys.length - 1; ii++) {
var k = keys[ii];
m = m[k] = m[k] || [];
m[keys[keys.length - 1]] = val;
return obj;
jcromartie / events.clj
Last active August 29, 2015 14:04
Totally naive event based system in Clojure
(defonce handlers (atom {}))
(defn- install-handler!
[topic-key f]
(swap! handlers assoc topic-key f))
(defmacro on
"Registers a global message handler for the given topic keyword. A
single handler can be registered at a time for a given topic
keyword. Handlers are dispatched based on the name portion of the
class Integer
def to_a
(0..Math.log2(self).ceil).map {|idx| self[idx] }.reverse
jcromartie / vignere.clj
Last active August 29, 2015 14:00
Vigenere cipher in a completely pointless (I mean, um, point-free) style
;; an appropriate prelude...
(def parpar (partial partial partial))
(def parapply (parpar apply))
(def parconj (parpar conj))
;; one convenient constant
(def char-offset (int \A))
(ns stackity.stack)
(defn compile-mode?
(-> stack meta :mode (= :compile)))
(def interpret-mode? (complement compile-mode?))
(defn ->compile-mode