Skip to content

Instantly share code, notes, and snippets.

@timwee
timwee / abrian.clj
Created November 17, 2009 22:11 — forked from cgrand/abrian.clj
;; 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)))
(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
;;;;;;;;;;;;
(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))))))
(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))))))
(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))))
(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)))
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;
(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
(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 []
(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}