Skip to content

Instantly share code, notes, and snippets.

@wagjo
wagjo / gist:d6419a289a64c503010c
Last active August 29, 2015 14:02
Linked data in EDN
JSON-LD
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
},
@wagjo
wagjo / gist:b687158ab0ff6aa8cb33
Last active August 29, 2015 14:00
Foldable multireducible
;; excerpt of foldable multireducible impl
;;
;; - introducing concept of mutable iterator, which is
;; much faster than seq
;; - this is for a (yet unreleased) custom patched clojure,
;; where clojure.lang interfaces can behave like protocols
;; - map is reducer variant, thats why I have to call seq on it
;; - seq is patched to support any reducible, not just Seqable
(defn fold-sectionable
@wagjo
wagjo / gist:10017343
Last active August 29, 2015 13:58
Upcoming library* for multireducibles
;; Multireducibles (with support for folding)
(def s1 "Hello World")
(def s2 "lllllllllll")
;; create multireducible with zip
(seq (zip s1 s2))
;; => ((\H \l) (\e \l) (\l \l) (\l \l) (\o \l) (\space \l) (\W \l) (\o \l) (\r \l) (\l \l) (\d \l))
@wagjo
wagjo / gist:9958354
Created April 3, 2014 16:54
Upcoming reducible IO library for Clojure
;; Input vector of bytes
(def vec (into (vector-of :byte)
(repeatedly 1000000 #(rand-int 128))))
;; Output file
(def out (java.io.FileOutputStream. "out.bin"))
;; Classic reduction -> 3835 ms
(let [write-fn (fn [r w] (.write out w))]
(time (reduce write-fn nil (map dec vec))))
@wagjo
wagjo / gist:9813500
Created March 27, 2014 17:42
update-in
(defn update-in*
[m [k & ks] f & args]
(let [k (if (and (instance? clojure.lang.Indexed m)
(integer? k)
(neg? k))
(+ (count m) k)
k)]
(if ks
(assoc m k (apply update-in* (get m k) ks f args))
(assoc m k (apply f (get m k) args)))))
(defprotocol IMutable
(-cas! [o oldval newval]
"Sets the value to newval if and only if the current value
is identical to oldval. Returns true if set happened,
otherwse returns false. Mutates `o`.")
(-alter! [o f] [o f x] [o f x y] [o f x y z] [o f x y z args]
"Changes referenced value with (apply f val args).
Returns new value. Mutates `o`.")
(-reset! [o val]
"Resets the referenced value to `val`.
@wagjo
wagjo / gist:8731671
Created January 31, 2014 12:57
Playing with quil
(ns foo.bar
(:use [quil.core])
(:require [clojure.string :as s]))
(defn setup []
(frame-rate 1)
(background 255))
(def *scale* 2)
@wagjo
wagjo / gist:8290237
Last active January 2, 2016 10:29
Bug in nrepl?
;; AOT before loading (e.g. with :aot :all in project.clj)
;; $ lein deps :tree
;; [clojure-complete "0.2.3" :exclusions [[org.clojure/clojure]]]
;; [org.clojure/clojure "1.5.1"]
;; [org.clojure/tools.nrepl "0.2.3" :exclusions [[org.clojure/clojure]]]
(ns ccc.core
(:gen-class))
(defprotocol P)
Type Error (user:1:5) Polymorphic function clojure.core/merge could not be applied to arguments:
Polymorphic Variables:
k36143
v36144
Domains:
nil *
(clojure.lang.IPersistentMap k v) (clojure.lang.IPersistentMap k v) *
(Option (clojure.lang.IPersistentMap k v)) *