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
;; vector of arrays version | |
(import '(javax.swing JFrame JPanel) | |
'(java.awt Color Graphics2D)) | |
(defn neighbours-count [[above current below] i w] | |
(let [j (mod (inc i) w) | |
k (mod (dec i) w) | |
s #(if (= (aget #^objects %1 (int %2)) :on) 1 0)] | |
(+ (+ (+ (s above j) (s above i)) | |
(+ (s above k) (s current j))) |
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 timwee.remote-jobs | |
(:use [clojure.contrib map-utils]) | |
(:require [clojure.contrib.str-utils2 :as s])) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; input is | |
;name id content | |
;Hanna-McEuen /guid/9202a8c04000641f8000000000883bc4 1Club.FM: Hit Kicker | |
;Traveling Wilburys /guid/9202a8c04000641f800000000003d42c radioIO History of Rock,WXRT,Paradise Tunes | |
;;;;;;;;;;;; |
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 r-acc [look? extract x] | |
"usage (get all of :a's values) | |
- (r-acc map? :a [:a 1 2 3 {:a 1 :b [:a 2 3] :c {:b 1 :a 2}} 3 #{:a :b 1} {:b {:a 3}}]) | |
(1 2 3)" | |
(letfn [(children [coll] | |
(if (map? coll) (vals coll) coll))] | |
(filter (complement nil-or-empty?) (map extract (filter look? (tree-seq coll? children x)))))) |
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 r-acc [look? extract x] | |
"usage | |
- (r-acc map? :a [:a 1 2 3 {:a 1 :b [:a 2 3] :c {:b 1 :a 2}} 3 #{:a :b 1} {:b {:a 3}}]) | |
(1 2 3)" | |
(letfn [(children [coll] | |
(if (map? coll) (vals coll) coll))] | |
(filter (complement nil-or-empty?) (map extract (filter look? (tree-seq coll? children x)))))) |
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 apply-fnmap [fn-map & xs] | |
"end result is a bunch of (key, (f x)), where (key, f) is from fn-map" | |
(zipmap (keys fn-map) (map #(apply % xs) (vals fn-map)))) | |
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 apply-fnmap [fn-map & data] | |
"end result is a bunch of (key, (f x)), where (key, f) is from fn-map" | |
(zipmap (keys fn-map) (map #(apply % data) fn-map))) |
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
package org.parsimonygroup; | |
import java.util.Collections; | |
import java.util.List; | |
import org.apache.hadoop.fs.Path; | |
import org.junit.Test; | |
import com.google.common.collect.Lists; |
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 map-maker [f ks vs] (zipmap ks (map (fn [vals] (apply f vals)) vs))) | |
(defn map-from-keys [coll f] (map-maker f coll coll)) | |
(defn map-from-pairs [pairs f] (map-maker f (map #(first %) pairs) pairs)) | |
(defn map-from-nested-map [a f] (map-maker #(map-map f %) (map #(first %) pairs) (map #(second %) pairs))) | |
VS | |
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 org.parsimonygroup.functions | |
(:require [clojure.contrib.math :as m])) | |
(defn identityfunc [x] x) | |
(defn isPositiveNumber [num] | |
(>= num 0)) | |
(defn prevFlightRange [data] | |
(:prevFlightRange (:totals data))) | |
(defn custom [] |
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 identityfunc [x] x) | |
(defn isPositiveNumber [num] | |
(>= num 0)) | |
(defn prevFlightRange [data] | |
(:prevFlightRange (:totals data))) | |
(defn custom [] | |
{ | |
:filter {:using isPositiveNumber :groupby prevFlightRange} | |
:each {:using identityfunc} |