This file contains 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
//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) | |
} |
This file contains 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
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)) | |
} |
This file contains 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
(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")) |
This file contains 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
(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] |
This file contains 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
(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}$" "")) |
This file contains 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
(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))) |
This file contains 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
(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}$" "")) |
This file contains 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
(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"))))) |
This file contains 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
(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"))))) |
This file contains 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
(ns probe) | |
(use 'clojure.contrib.seq-utils) | |
(defmacro property | |
([doc] | |
`(println "Pending - " ~doc)) | |
([doc test] | |
`(if ~test | |
(println "passed! " '~test) |
OlderNewer