Skip to content

Instantly share code, notes, and snippets.

Avatar

Christophe Grand cgrand

View GitHub Profile
View payload.json
{"user":
{"actions": {},
"properties":
{"givenName": "mike",
"faimlyName": "amundsen",
"email": "m...@example.org"}}}
View mutabots.clj
(ns mutabots
"Reimplementation of transducers, in terms of processing functions instead
of reducing functions.
tl;dr: reducing-fn based transducers are a special case, influenced by reducers,
of processing-fn based transducers.
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing
concept of reducing functions.
To sum it up, a transducer has currently the signature :
View Flattening a nested list in clojure
(defn flat?
"Returns true if seq contains no sequences"
[seq]
(not-any? (fn [x] (isa? (type x) java.util.List)) seq))
(defn flatten
"Returns an unnested sequence from the non-sequence elements of seq
for example, it turns (1 (2) 3) into (1 2 3)"
[seq]
(if (isa? (type seq) java.util.List)
View flatten-versions.clj
;;from clojure.contrib.seq-utils
;;'flatten' written by Rich Hickey,
;;see http://groups.google.com/group/clojure/msg/385098fabfcaad9b
(defn flatten [x]
(filter (complement sequential?)
(rest (tree-seq sequential? seq x))))
;aprox. translate from paul graham's on lisp to clojure
(defn flatten-ol [x]
(letfn [(rec [x acc]
View gist:126676
(set! *warn-on-reflection* true)
(ns slow
(:import [java.nio ByteBuffer Buffer]))
(defn #^ints bytes-to-ints [#^bytes bs]
(let [#^ints is (make-array Integer/TYPE (alength bs))]
(loop [i (int 0)]
(if (< i (alength bs))
(do
View gist:188441
(defn walk-out [customer]
(ref-set customer :outside))
(defn wait [customer {q :queue}]
(alter q conj customer)
(ref-set customer :waiting))
(defn sleeping? [barber]
(= :sleeping (ensure barber)))
View sweeeeeeeeeet! :).clj
(defn euclidean
"berechnet den (modifizierten) euklidischen abstand zwischen zwei usern"
[active other]
(Math/sqrt (reduce + (for [movie (common-items active other)
feat (item-map movie)]
(diff active other movie feat)))))
View unbean.clj
(defn unbean [m]
"Tries to recreate a simple JavaBean object from map m"
(let [obj (.newInstance (:class m))]
(doseq [#^java.beans.PropertyDescriptor pd (-> String java.beans.Introspector/getBeanInfo .getPropertyDescriptors)
:let [wm (.getWriteMethod pd) k (-> pd .getName keyword)] :when (and wm (contains? m k))]
(.invoke wm obj (to-array [(m k)])))
obj))
View respond.clj
;; something like that should be closer to what you want
(defmacro defplugin [& body]
(let [cmd-list (into {} (for [[docs words cmdkey] body word words] [word {:cmd cmdkey :doc docs}]))]
`(do
~@(for [[docs words cmdkey & method-stuff] body]
`(defmethod respond ~cmdkey ~@method-stuff))
(dosync
(let [m-name# (keyword (last (.split (str *ns*) "\\.")))]
(alter modules assoc m-name#
{:load #(dosync (alter commands assoc m-name# ~cmd-list))
View cs2.clj
(deftype Timeseries
[series] ; maybe dataset or backing-set or something like that
Object
(equals [this other]) ; should a TS be equal to any kind of coll holding same value or to other TS only? (the easiest answer is "any kind of coll")
(hashCode [this]) ; depends on ^^
(toString [this])
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/IPersistentCollection.java
You can’t perform that action at this time.