Skip to content

Instantly share code, notes, and snippets.

(defn breed [parent-a parent-b]
(let [breed-index (rand (count parent-a))
transmission-a (take breed-index parent-a)
transmission-b (drop breed-index parent-b)
pure-child (concat transmission-a transmission-b)]
mutate-agent pure-child))
{"mobileview":{"sections":[{"id":0,"text":""},{"toclevel":1,"line":"English","id":1,"text":"<h2><span class=\"mw-headline\" id=\"English\">English<\/span><\/h2>\n<div class=\"sister-wikipedia sister-project noprint floatright\" style=\"border: 1px solid #aaa; font-size: 90%; background: #f9f9f9; width: 250px; padding: 4px; text-align: left;\">\n<div style=\"float: left;\">\n<div class=\"floatnone\"><span class=\"mw-mf-image-replacement\">[Image]<\/span><\/div>\n<\/div>\n<div style=\"margin-left: 60px;\"><a href=\"\/wiki\/Wikipedia\" title=\"Wikipedia\">Wikipedia<\/a> has an article on:\n<div style=\"margin-left: 10px;\"><b class=\"Latn\" lang=\"en\" xml:lang=\"en\"><a href=\"\/\/en.wikipedia.org\/wiki\/This\" class=\"extiw\" title=\"w:This\">This<\/a><\/b><\/div>\n<\/div>\n<\/div>\n<p><span class=\"interProject\"><a href=\"\/\/en.wikipedia.org\/wiki\/This\" class=\"extiw\" title=\"w:This\">Wikipedia<\/a><\/span><\/p>"},{"toclevel":2,"line":"Etymology","id":2,"text":"<h3><span class=\"mw-headline\" id=\"Etymol
@jbrechtel
jbrechtel / foo.txt
Created October 27, 2012 10:59
nth vs last/take
clojoomba.core.runner=> (time (count (nth (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200}) 2)))
"Elapsed time: 133.896 msecs"
20
clojoomba.core.runner=> (time (count (nth (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200}) 2)))
"Elapsed time: 121.748 msecs"
20
clojoomba.core.runner=> (time (count (nth (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200}) 2)))
"Elapsed time: 113.795 msecs"
20
clojoomba.core.runner=> (time (count (last (take 2 (clojoomba.core.evolution/evolutions {:agents (gen-agents 20) :room-size 10 :num-rooms 10 :steps 200})))))
@jbrechtel
jbrechtel / cake.scala
Created September 17, 2012 00:17
really bad cake pattern example
class Foo {
val emailer: EmailService
}
trait Fakes {
val emailer = new FakeEmailService()
}
trait RealThings {
val emailer = new SmtpEmailService()
@jbrechtel
jbrechtel / memoize.clj
Created September 15, 2012 14:54
Confused with memoize
;not sure why this doesn't really memoize the anonymous function call
(defn add [a b] ((memoize (fn [x y] (Thread/sleep 1000) (+ x y))) a b))
;this does correctly memoize the (non anonymous) function call
(defn adds [a b] (Thread/sleep 1000) (+ a b))
(def addf (memoize adds))
(defn basic-item-total [price quantity]
(* price quantity))
(defn with-line-item-conditions [f price quantity]
(apply f price quantity))
@jbrechtel
jbrechtel / super.rb
Created July 1, 2012 16:24
overriding new
class Parent
class << self
alias_method :orig_new, :new
def new(arg)
puts "newing parent with #{arg}"
orig_new
end
end
object Hulu {
def playVideo(video: Content) {
try {
video.streamToTV()
} catch {
case t:Throwable => playNextAd()
}
}
}
@jbrechtel
jbrechtel / if.rb
Created June 10, 2012 05:18
if blocks return values
something = if x > 10
'hello'
else
'bye'
end
numb = 10
while numb != 0
bottle = "bottle"
if numb > 1
bottle = "bottles"
end
puts numb.to_s + ' ' + bottle + ' of beer on the wall ' + numb.to_s + ' ' + bottle +' of beer'