Skip to content

Instantly share code, notes, and snippets.


Dominic Muller domgetter

  • Bakersfield, CA
View GitHub Profile
View socket_client.clj
;; Client
(import '
(def output (.getOutputStream (Socket. "localhost" 3000)))
(.write output 3)
View resource_ala_rails.clj
;; Use defroutes to create a defresource macro that generates restful routes like
;; Rails:
(def restful-routes
[['GET "" "/index" ]
['GET "/new" "/new" ]
['POST "" "/create" ]
['GET "/:id" "/show" 'id]
['GET "/:id/edit" "/edit" 'id]
['PATCH "/:id" "/update" 'id]
View repeatedly.rb
class Object
def repeatedly do |y|
loop { y << yield(self) }
#=> [4, 3, 4, 4, 4, 4, 3, 5, 5, 5]
View before.rb
def state
when !collected? then 'booked'
when !ironed? then 'collected'
when !delivered? then 'ironed'
else 'delivered'
View find_with_key.clj
(defn find-with-key
([ds key] (find-with-key (:root ds) key [:root]))
([ds key path]
(if (= key (:key (:data ds)))
(if (empty? (:children ds)) nil
(first (filter identity (for [[index child] (map-indexed list (:children ds))]
(find-with-key ((:children ds) index) key (conj path :children index)))))))))
(def my-map {:key nil
View partition_while.clj
(defn partition-while
"partitions elements in order while the predicate function holds
the predicate function is given the current element
and the current partition. "
[f coll]
(loop [truck [] box [] [book & books] coll]
(if (empty? books) ; if there are no more books to pack
(conj truck box) ; tape up the last box, put it in the truck, and return the truck
(if (f book box) ; otherwise, if we can put the current book in the pending box
(recur truck (conj box book) books) ; put the book in the box and work on the next book
View each_cons.rb
[*"a".."h"].each_cons(2) {|(last, current)| puts "last: #{last}, current: #{current}" }
# last: a, current: b
# last: b, current: c
# last: c, current: d
# last: d, current: e
# last: e, current: f
# last: f, current: g
# last: g, current: h
View rolling_variance.clj
(defn rolling-variance
([] [0.0 0.0 0])
([[m v c] val]
(let [mean (+ m (/ (- val m) (inc c)))
var (+ v (* (- val m) (- val mean)))]
[mean var (inc c)])))
(defn standard-deviation [coll]
(let [[_ variance count] (reduce rolling-variance (rolling-variance) coll)]
(Math/sqrt (/ variance count))))
View excpetions.rb
begin # start catching exceptions here
ldap =
:host => host,
:port => port,
:auth => {
:method => :simple,
:username => CONFIG['repldn'],
:password => CONFIG['replpw']
View bottomfeeder.rb
module Auspice
class BottomFeeder
attr_accessor :x, :y, :z, :in, :out
def initialize(size,w,h)
@font =,:name => DAT+'ttfs/ATComputer.ttf')
@rows = ((h / size)+size)
@cols = (w / @font.text_width('_',1))
@size = size
@dtext = ['']