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
Mandy.job "Word Count" do | |
map do |line| | |
line.split(' ').each do |word| | |
emit(word, 1) | |
end | |
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
describe "reducer" do | |
it "counts occurrences" do | |
occurrences = [1,1,1,1] | |
@runner.reduce('andy' => occurrences) do |reducer| | |
reducer.should_receive(:emit).with('andy', 4) | |
end | |
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
Mandy.job "Word Count" do | |
# ... snipped for brevity | |
reduce do |word, occurrences| | |
emit(word, occurrences.size) | |
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
(ns mahout-test.recommend | |
(:import [java.io File] | |
[org.apache.mahout.cf.taste.model DataModel] | |
[org.apache.mahout.cf.taste.impl.model.file FileDataModel] | |
[org.apache.mahout.cf.taste.impl.similarity PearsonCorrelationSimilarity TanimotoCoefficientSimilarity LogLikelihoodSimilarity] | |
[org.apache.mahout.cf.taste.impl.neighborhood NearestNUserNeighborhood ThresholdUserNeighborhood] | |
[org.apache.mahout.cf.taste.impl.recommender GenericUserBasedRecommender GenericItemBasedRecommender])) | |
(defn create-user-recommender | |
[file] |
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 divisible-by-3-or-5 | |
[n] | |
(or (= 0 | |
(mod n 3)) | |
(= 0 | |
(mod n 5)))) | |
(defn sum | |
[xs] | |
(reduce + xs)) |
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 multiple-of? | |
[divisors n] | |
(some #(= 0 %) | |
(map #(mod n %) divisors))) | |
(reduce + | |
(filter #(multiple-of? '(3 5) %) | |
(range 1 1000))) |
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
#!/bin/sh | |
cd ~/deploy-keys | |
git pull origin master | |
cat *.pub > ~/.ssh/authorized_keys |
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
;;Example 1.10 | |
;;Ackermann's function: | |
;;http://en.wikipedia.org/wiki/Ackermann_function | |
;; | |
(defn ackermann | |
[x y] | |
(cond (= y 0) 0 | |
(= x 0) (* 2 y) | |
(= y 1) 2 |
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
;; tree-recursive fibonacci | |
(defn fib-recur | |
[n] | |
(cond (= n 0) 0 | |
(= n 1) 1 | |
:else (+ (fib-recur (- n 1)) | |
(fib-recur (- n 2))))) | |
;;linear iteration fibonacci | |
(defn fib-iter |
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 primes | |
[n] | |
(letfn [(multiple-of? | |
[p] | |
(= 0 | |
(mod n p))) | |
(sieve | |
[ps] | |
(let [p (first (rest ps))] |