Skip to content

Instantly share code, notes, and snippets.

John Cromartie jcromartie

Block or report user

Report or block jcromartie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jcromartie
jcromartie / pre-commit
Created Jun 6, 2017
pre-commit hook which fails when untracked files are present in working tree
View pre-commit
#!/bin/sh
untrackedFiles=$(git ls-files --others --exclude-standard)
if [ ! -z "$untrackedFiles" ]
then
echo "There are untracked files in the working tree:"
echo "$untrackedFiles"
echo ""
echo "Are you sure you aren't forgetting something?"
View mayhem.clj
(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)
View fix-my-speedbar.el
(defun definitely-speedbar ()
(interactive)
(speedbar t))
(global-set-key [f11] 'definitely-speedbar)
View uniq-live.rb
#!/usr/bin/ruby
# 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
jcromartie / git-cleanup
Created Apr 3, 2015
git cleanup - delete branches that are fully merged relative to the current branch
View git-cleanup
#!/bin/bash
for branch in $(git branch --merged | grep -v '*')
do
read -n 1 -p "Delete ${branch} [y/N]? " answer
echo ""
if [[ "$answer" = "y" ]]
then
git branch -d "$branch"
fi
View arrayAssocIn.js
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
jcromartie / events.clj
Last active Aug 29, 2015
Totally naive event based system in Clojure
View events.clj
(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
View missing_bits.rb
class Integer
def to_a
(0..Math.log2(self).ceil).map {|idx| self[idx] }.reverse
end
end
@jcromartie
jcromartie / vignere.clj
Last active Aug 29, 2015
Vigenere cipher in a completely pointless (I mean, um, point-free) style
View vignere.clj
;; an appropriate prelude...
(def parpar (partial partial partial))
(def parapply (parpar apply))
(def parconj (parpar conj))
;; one convenient constant
(def char-offset (int \A))
View stackity.stack.clj
(ns stackity.stack)
(defn compile-mode?
[stack]
(-> stack meta :mode (= :compile)))
(def interpret-mode? (complement compile-mode?))
(defn ->compile-mode
[stack]
You can’t perform that action at this time.