Skip to content

Instantly share code, notes, and snippets.

(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
;; 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))
@ato
ato / twitjure.clj
Created November 30, 2009 05:16 — forked from devn/twitjure.clj
(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]
@ato
ato / scratch.clj
Created November 20, 2009 09:15 — forked from duncanmak/scratch.clj
(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)))
@ato
ato / scroller.c
Created October 25, 2009 12:53 — forked from farcaller/scroller.c
// 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)]);