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 lazy-combine [xs ys] | |
(lazy-seq | |
(if-let [[x & xs*] xs] | |
(if-let [[y & ys*] ys] | |
(cond (= x y) (cons x (lazy-combine xs* ys*)) | |
(< x y) (cons x (lazy-combine xs* ys)) | |
(> x y) (cons y (lazy-combine xs ys*))) | |
xs) ; no more ys | |
ys))) ; no more 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
;; LibSVM Model parser. | |
(use 'clojure.contrib.duck-streams) | |
(use 'clojure.contrib.seq-utils) | |
(require '[clojure.contrib.str-utils2 :as s]) | |
(def *root* "/data/") | |
;; (set! *print-length* 5) eval in repl | |
(defn model-file [name] (str *root* name)) |
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 take-tweets [n] | |
(take n (map read-json | |
(line-seq (reader | |
(get-stream)))))) | |
(defn tweet-text [n] | |
(map #(get % "text") | |
(take-tweets n))) | |
(defn search-text [s coll] |
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 write [name data] | |
(let [buf (make-array Byte/TYPE 1024) | |
dest (FileOutputStream. name)] | |
(with-open [r (BufferedInputStream. data) | |
w (BufferedOutputStream. dest)] | |
(loop [bytes (.read r buf 0 1024)] | |
(when-not (= bytes -1) | |
(.write w buf 0 bytes) | |
(recur (.read r buf 0 1024))))) | |
(println "Wrote" name))) |
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
// simplified and fixed bug where too many \b characters were printed | |
#include <stdio.h> | |
#include <unistd.h> | |
int main (int argc, const char *argv[]) | |
{ | |
int i; | |
const char scroller[] = "|/-\\"; | |
for(i=0; i<20; ++i) { | |
printf("%c", scroller[i % (sizeof(scroller) - 1)]); |