Skip to content

Instantly share code, notes, and snippets.

Things that were invented in Smalltalk:
OOP
WIMP GUIs: Windows, Icons, Menus and a Pointing device
IDEs
Interactive debugger
Image-based VM
Blocks/closures
Message passing
Class browsers
(defn transfer
"Transfer a request to be handled as if it were for a different URI, but don't tell the client"
[req uri handler]
(if (= (:redirected-to req) uri)
(throw (Exception. (str "Already redirected to " uri "... no loops allowed")))
(handler (assoc req :uri uri :redirected-to uri))))
(ns rec-print)
(defn rec-pr-str
"Print record to string with type information"
[r]
(let [class-name (.getName (class r))]
(pr-str (merge {::rec-class class-name} r))))
(def lookup-class
(memoize
@jcromartie
jcromartie / git-merged.rb
Created March 29, 2011 18:47
Git command to list merged (or unmerged with -u) branches
#!/bin/ruby
show_unmerged = ARGV[0] == '-u'
branches = `git branch -r`.split("\n")
branches.each do |branch|
is_merged = `git branch --contains #{branch}` =~ /master/
puts branch if show_unmerged ^ is_merged
end
@jcromartie
jcromartie / gsd.sh
Created May 4, 2011 15:40
Elegant Bash-based Get-Shit-Done script
#!/usr/bin/env bash
# edit this list, or set GSD_SITES to add your custom sites
SITES="$GSD_SITES reddit.com forums.somethingawful.com somethingawful.com digg.com break.com news.ycombinator.com infoq.com bebo.com twitter.com facebook.com blip.com youtube.com vimeo.com delicious.com flickr.com friendster.com hi5.com linkedin.com livejournal.com meetup.com myspace.com plurk.com stickam.com stumbleupon.com yelp.com slashdot.com"
HOSTFILE="/etc/hosts"
if [ ! -w $HOSTFILE ]
then
echo "cannot write to $HOSTFILE, try running with sudo"
@jcromartie
jcromartie / pre-commit
Created May 25, 2011 14:40
Git pre-commit hook to help stay up-to-date with master
#!/usr/bin/env bash
# hook to enforce that current branch is up-to-date with latest
# changes from master before committing
# put me in .git/hooks and make me executable
# the output of rev-list in the following test will be empty if there
# are no commits in master that aren't in the current branch
(ns markov
(use clojure.test))
;; ---------- basic markov chain utils and API ----------
(defn n-grams
"Partition seq s into all sequential groups of n items"
[n s]
(partition n 1 (repeat nil) s))
(ns trie.core
(:refer-clojure :exclude (merge contains?))
(:use clojure.test))
;; some generic trie (prefix tree) functions
(def box list)
(defn trie
"Returns trie for single seq s"
(defn watch
"Returns (running) thread which observes the value of f every delay
milliseconds, and calls the callback fn if the value changes. callback
will be called with the old and new values from f"
([f callback delay]
(let [proc (fn []
(loop [x1 ::watch-init]
(let [x2 (f)]
(when (not= x1 x2)
(callback x1 x2))
(defn timestamp
"Returns object timestamped with the current system time in milliseconds"
[obj millis]
(assoc obj :timestamp (System/currentTimeMillis)))
(defn new-model-object
"Returns new, uniquely identified, timestamped object with initial
key-val pairs"
[& key-vals]
(timestamp (merge (apply hash-map kvs)