Skip to content

Instantly share code, notes, and snippets.

//Gives us the :: syntax for streams. From http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient.
class RichStream[A](str: =>Stream[A]) {
def ::(hd: A) = Stream.cons(hd, str)
}
implicit def streamToRichStream[A](str: =>Stream[A]) = new RichStream(str)
object M { //Gives us a shorthand for declaring BigDecimals that Scala lacks
def apply(i:Int) = BigDecimal(i)
}
val mc = new java.math.MathContext(300,java.math.RoundingMode.HALF_UP)
//Hack to work around poor bigdecimal support in Scala
def divide(a:BigDecimal, b:BigDecimal) = {
new BigDecimal(a.bigDecimal.divide(b.bigDecimal, mc))
}
def piSummands(n: BigDecimal): Stream[BigDecimal] = {
Stream.cons(divide(BigDecimal(1), n), piSummands(n + BigDecimal(2)).map(_ * -1))
}
(require ['clojure.contrib.shell-out :as 'shell])
(defn user-prop
[key]
(System/getProperty (str "user." key)))
(defn find-files
[]
(shell/sh "find" (user-prop "home") "-name" "*.clj"))
(import '(java.io File))
(defn file-list
"returns a lists of files in a directory"
([dir] (.listFiles (File. dir) )))
(defn file-names [dir]
(map #(.getName %) (file-list dir)))
(defn ruby-files [dir]
(require ['clojure.contrib.shell-out :as 'shell])
(def dir (second *command-line-args*))
(defn as-seq [str]
(seq (.split str "\n")))
(defn find-by-name [d n] (as-seq (shell/sh "find" "." "-name" n :dir d)))
(defn oggs [] (as-seq (shell/sh "find" "." "-name" "*.ogg" :dir dir)))
(require ['clojure.contrib.shell-out :as 'shell])
(def dir (second *command-line-args*))
(defn as-seq [string] (seq (.split string "\n")))
(defn find-by-name [d n] (as-seq (shell/sh "find" "." "-name" n :dir d)))
(defn oggs [] (find-by-name dir "*.ogg"))
(defn base-name [fname] (.replaceFirst fname "\\..{3}$" ""))
(require ['clojure.contrib.shell-out :as 'shell])
(def dir (second *command-line-args*))
(defn as-seq [string] (seq (.split string "\n")))
(defn find-by-name [d n] (as-seq (shell/sh "find" "." "-name" n :dir d)))
(defn oggs [] (find-by-name dir "*.ogg"))
(defn base-name [fname] (.replaceFirst fname "\\..{3}$" ""))
(require ['clojure.contrib.shell-out :as 'shell])
(require ['clojure.contrib.str-utils2 :as 'stru])
(use 'clojure.contrib.seq-utils)
; Vorbis comment to mp3 tags functions
(defn- vorbis-comments
"Retuns a seq of seq containing key/value pairs (('ARTIST' 'foo') ('ALBUM' 'bar')) for a given file name"
[file]
(let [comments (shell/sh "vorbiscomment" file)]
(seq (map #(stru/split % #"=") (stru/split comments #"\n")))))
(require ['clojure.contrib.shell-out :as 'shell])
(require ['clojure.contrib.str-utils2 :as 'stru])
(use 'clojure.contrib.seq-utils)
; Vorbis comment to mp3 tags functions
(defn- vorbis-comments
"Retuns a seq of seq containing key/value pairs (('ARTIST' 'foo') ('ALBUM' 'bar')) for a given file name"
[file]
(let [comments (shell/sh "vorbiscomment" file)]
(seq (map #(stru/split % #"=") (stru/split comments #"\n")))))
(ns probe)
(use 'clojure.contrib.seq-utils)
(defmacro property
([doc]
`(println "Pending - " ~doc))
([doc test]
`(if ~test
(println "passed! " '~test)