Skip to content

Instantly share code, notes, and snippets.

View edw's full-sized avatar

Edwin Watkeys edw

View GitHub Profile
(def n 1000)
(def ds (dataset [:x :y] (partition
2
(interleave (sample-normal n)
(sample-exp n)))))
(def plot (scatter-plot ($ :x ds) ($ :y ds)))
(view plot)
edw@li246-89:~/dev/cascalog$ lein compile
Warning: problem requiring hooks: java.lang.IllegalAccessError: extract-javac-tasks is not public (javac.clj:1)
...continuing without hooks completely loaded.
Compiling 31 source files to /home/edw/dev/cascalog/classes
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
WARNING: :namespaces in project.clj is deprecated; use :aot.
WARNING: :namespaces in project.clj is deprecated; use :aot.
edw@li246-89:~/dev/cascalog$ lein repl
Warning: problem requiring hooks: java.lang.IllegalAccessError: extract-javac-tasks is not public (javac.clj:1)
...continuing without hooks completely loaded.
REPL started; server listening on localhost:18550.
user=> (use 'cascalog.playground) (bootstrap)
nil
nil
user=> (?<- (stdout) [?person] (age ?person 25))
java.lang.NoClassDefFoundError: cascalog/graph/proxy$java/lang/Object$EdgeFactory$4210cf45 (NO_SOURCE_FILE:0)
user=>
@edw
edw / gist:732226
Created December 7, 2010 18:59
ls -lR of my (2nd) cascalog directory
Edwins-MacBook-Pro:cascalog edw$ cat ls-lR
total 80
-rw-r--r-- 1 edw staff 32472 Dec 7 12:46 LICENSE
-rw-r--r-- 1 edw staff 3735 Dec 7 12:46 README.markdown
drwxr-xr-x 4 edw staff 136 Dec 7 12:47 classes
drwxr-xr-x 9 edw staff 306 Dec 7 12:46 lib
-rw-r--r-- 1 edw staff 0 Dec 7 13:58 ls-lR
-rw-r--r-- 1 edw staff 695 Dec 7 12:46 project.clj
drwxr-xr-x 4 edw staff 136 Dec 7 12:46 src
drwxr-xr-x 3 edw staff 102 Dec 7 12:46 test
@edw
edw / wildcard.clj
Created December 13, 2010 19:49
Wildcarded variable subsets in Cascalog
(defn wildcard? [var]
(= "*" (subs (name var) 0 1)))
(defn make-output-values [vars]
(let [wildcards (filter wildcard? vars)
subsets (map set (clojure.contrib.combinatorics/subsets wildcards))]
(map #(vec (filter identity
(map (fn [var]
(if (wildcard? var)
(and (contains? % var)
;; THIS WORKS
(?- (lfs-textline "unified-traffic") (apply union (vals (traffic-plan "2010-12-12"))))
;; THIS DOESN'T
(let [all-queries (apply union (vals (traffic-plan "2010-12-12")))]
(?- (lfs-textline "unified-traffic-sorted")
(<- [?key ?visits ?transactions ?visit-revenue]
(all-queries ?key ?visits ?transactions ?visit-revenue)
(:sort ?visit-revenue :desc) (reverse :true))))
@edw
edw / set-bucket.clj
Created January 24, 2011 19:38
Demonstration of multiple-arity support in DEFMAPCATOP
(defmapcatop set-bucket
([s v inv]
(if (contains? s v) (list inv) '()))
([s v inv outv]
(if (contains? s v) (list inv) (list outv)))
([s v inv outv bothv]
(list bothv (if (contains? s v) (list inv) (list outv)))))
(def x (memory-source-tap [["a" 1]
["b" 1]
@edw
edw / sequences-star.clj
Created January 31, 2011 15:18
Sequence operations that operate on a subset of values of each sequence element.
(defn- make-getter [indices]
(let [indices (if (sequential? indices) indices [indices])]
(fn [coll] (map #(nth coll %) indices))))
(defn map* [indices proc coll]
(let [getter (make-getter indices)]
(map #(apply proc (getter %)) coll)))
(defn filter* [indices pred? coll]
(let [getter (make-getter indices)]
var handler = function(req, res) {
var channel = req.params.channel;
client.lrange(channel, 0, -1, function(err, myRange) {
res.end(JSON.stringify(myRange));
});
}
@edw
edw / magic3.scm
Created April 21, 2011 20:21
A Mini Framework in Scheme for Passing the Arc Challenge
;;;; Magic 3 -- a Web application server in Scheme (Scheme 48)
;;;; By Edwin Watkeys
;;;;
,open srfi-13 srfi-14 fluids sockets i/o primitives threads byte-vectors encodings text-codecs extended-ports queues srfi-1 posix-time ascii define-record-types silly cells handle srfi-27 srfi-8 posix-i/o interrupts posix-processes posix-files posix-regexps tables time queues simple-signals os-strings
;;;; Sample code is at the bottom of the file. To start the server,
;;;; eval: (start "password")