Skip to content

Instantly share code, notes, and snippets.

Created November 13, 2011 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1362348 to your computer and use it in GitHub Desktop.
Save anonymous/1362348 to your computer and use it in GitHub Desktop.
(ns mytest3)
(def file-path "/Users/me/Desktop/temp/bob.txt")
;(def file-path "/Users/me/Downloads/3MB-file.m4a")
(def group-by-twos
(fn [a-list]
(let [first-two (fn [a-list] (list (take 2 a-list)))
the-rest-after-two (fn [a-list] (rest (rest a-list)))
only-two-left? (fn [a-list] (if (= (count a-list) 2) true false))]
(loop [result '() rest-of-list a-list]
(if (empty? rest-of-list)
result
(recur (doall (concat result (first-two rest-of-list)))
(doall (the-rest-after-two rest-of-list))))))))
(def get-the-file
(fn [file-name-and-path]
(let [the-file-pointer
(new java.io.RandomAccessFile (new java.io.File file-name-and-path) "r")
intermediate-array (byte-array (.length the-file-pointer))] ;reserve space for final length
(.readFully the-file-pointer intermediate-array)
(partition 2 (seq intermediate-array)))))
;(group-by-twos (seq intermediate-array)))))
(spit "bob2.txt" (some-pretty-print-here (get-the-file file-path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment