This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Client | |
(import 'java.net.Socket) | |
(def output (.getOutputStream (Socket. "localhost" 3000))) | |
(.write output 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Use defroutes to create a defresource macro that generates restful routes like | |
;; Rails: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions | |
(def restful-routes | |
[['GET "" "/index" ] | |
['GET "/new" "/new" ] | |
['POST "" "/create" ] | |
['GET "/:id" "/show" 'id] | |
['GET "/:id/edit" "/edit" 'id] | |
['PATCH "/:id" "/update" 'id] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def repeatedly | |
Enumerator.new do |y| | |
loop { y << yield(self) } | |
end | |
end | |
end | |
[3,4,5].repeatedly(&:sample).take(10) | |
#=> [4, 3, 4, 4, 4, 4, 3, 5, 5, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def state | |
case | |
when !collected? then 'booked' | |
when !ironed? then 'collected' | |
when !delivered? then 'ironed' | |
else 'delivered' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn find-with-key | |
([ds key] (find-with-key (:root ds) key [:root])) | |
([ds key path] | |
(if (= key (:key (:data ds))) | |
path | |
(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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[*"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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin # start catching exceptions here | |
ldap = Net::LDAP.open( | |
:host => host, | |
:port => port, | |
:auth => { | |
:method => :simple, | |
:username => CONFIG['repldn'], | |
:password => CONFIG['replpw'] | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Auspice | |
class BottomFeeder | |
attr_accessor :x, :y, :z, :in, :out | |
def initialize(size,w,h) | |
@font = Gosu::Font.new(size,:name => DAT+'ttfs/ATComputer.ttf') | |
@rows = ((h / size)+size) | |
@cols = (w / @font.text_width('_',1)) | |
@size = size | |
@dtext = [''] |