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.util.{ Enumeration => JavaEnumeration } | |
class EnumerationIterator[T](private[this] val jenum:JavaEnumeration[T]) extends Iterator[T] { | |
def hasNext = jenum.hasMoreElements() | |
def next:T = jenum.nextElement() | |
} | |
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
// Model | |
case class User(val name: String) | |
// Factory object: | |
object User extends AbstractShape[User] { | |
// one scalar field called "name" | |
object name extends Scalar[String]("name", _.name) with Functional[String] | |
// fields list | |
override lazy val * = name :: Nil |
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
(defn sig [x] | |
(:sig (meta (resolve x)))) | |
(defmulti type-of (comp type first list)) | |
(defmethod type-of :function [thing & _] (sig thing)) | |
(defmethod type-of java.util.List [expr & a] | |
(conj (map #(type-of % (first a)) (rest expr)) |
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
;variants of the code from point #2 of: | |
; http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses | |
;original | |
(apply merge-with + | |
(pmap count-lines | |
(partition-all *batch-size* | |
(line-seq (reader filename))))) |
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
tom-desktop% pwd [~] | |
/home/tom | |
tom-desktop% ghci [~] | |
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer ... linking ... done. | |
Loading package base ... linking ... done. | |
Prelude> :module Database.TokyoCabinet | |
Prelude Database.TokyoCabinet> runTCM $ do { db <- new :: TCM HDB; open db "foo.tch" [OWRITER, OCREAT]; put db "bar" "baz"; close db } | |
Loading package bytestring-0.9.1.4 ... linking ... done. |
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
(let [cursor (fetch-eager :where {... whatever ...}) | |
res (transient [])] | |
(while (.hasNext cursor) | |
(conj! res (-> cursor .next .toClojure))) | |
(persistent! res)) | |
;; |
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
(defmacro ->r | |
"The proposed Rohner arrow" | |
([x] x) | |
([x form] (if (seq? form) | |
(with-meta (replace {'_ x} form) (meta form)) | |
(list form x))) | |
([x form & more] `(->r (->r ~x ~form) ~@more))) | |
(use 'clojure.walk) |
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
(defn process-args [m] | |
(mapcat (fn [[flag value]] [(format "--%s" (name flag)) value]) m)) | |
(defn growl [m] | |
(-> (Runtime/getRuntime) | |
(.exec | |
(into-array | |
String | |
(cons "/usr/local/bin/growlnotify" (process-args m)))))) |
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
(def m (ref {})) | |
(defn str-to-int [m s] | |
(or (@m s) | |
(dosync | |
(alter m assoc s (count @m)) | |
(@m s)))) |
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
(defn assoc-autoinc [m k] | |
(if (get m k) | |
m | |
(let [v (inc (:last-value (meta m) -1))] | |
(with-meta | |
(assoc m k v) | |
(assoc (meta m) :last-value v))))) | |
(defn get-or-autoinc! [m k] | |
(if-let [v (get @m k)] |
OlderNewer