Skip to content

Instantly share code, notes, and snippets.

View chan.d
import core.sync.mutex : Mutex;
import core.thread : Thread, Fiber;
* chan allows messaging between threads without having to deal with locks, similar to how chan works in golang
class chan(T) {
Mutex lock;
private bool closed_; bool closed() {synchronized (lock) {return closed_;}} void Close() { synchronized(lock) { closed_ = true; } }
clojj / gist:646e6b3e002e49d0996f
Last active Aug 29, 2015
combinating ppm images
View gist:646e6b3e002e49d0996f
(defn process []
(let [file-data (IOUtils/toByteArray (io/input-stream "resources/img1.ppm"))
ppm-head (subvec (vec file-data) 0 32)
img-data (partition 3 (subvec (vec file-data) 32))
file-data2 (IOUtils/toByteArray (io/input-stream "resources/img2.ppm"))
img-data2 (partition 3 (subvec (vec file-data2) 32))]
(let [result (map #(map (fn [n] (/ n 2)) (map + %1 %2)) img-data img-data2) ;(r/fold (r/monoid into vector) conj (r/map #(/ (+ % %) 2) img-data img-data2))
result-data (flatten result)
ba (byte-array (concat ppm-head result-data))]
(IOUtils/write ba (io/output-stream "resources/out.ppm")))))
View suspendable_test.clj
(ns clojure.core.suspendable-test
(:require [clojure.core.async :as async]))
(def c (async/chan))
(defn fn1 [ctrl-chan]
(async/go-loop [cmd-old :run cmd-new :run]
(condp = cmd-new
:run (do
(when (not (= cmd-old cmd-new))
clojj / persist-starred.groovy
Created Jan 14, 2015
retrieves my starred repos from Github v3 API and stores them in HSQL
View persist-starred.groovy
@GrabResolver(name='gstorm', root='')
@GrabConfig(systemClassLoader = true) @Grab('gstorm:gstorm:0.6')
import gstorm.*
import groovy.json.*
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
@GrabExclude(group='xerces', module='xercesImpl')
import static
@Grab(group='commons-io', module='commons-io', version='2.3')
clojj / core.clj
Created Jan 23, 2015
github v3 api with tentacles
View core.clj
(ns github-api.core
(:require [tentacles.repos :as repos])
(:use [clojure.pprint])
(:import (java.time Period LocalDateTime)))
(let [starred (repos/starring "clojj"
{:per-page 4
:accept "application/"})
clojj / core.clj
Created Jan 25, 2015
sort starred repos by commit-count in last n days
View core.clj
(ns github-api.core
(:require [tentacles.repos :as repos]
[clojure.core.reducers :as r])
(:use [clojure.pprint])
(:import (java.time Period LocalDateTime)))
(defn latest [days token]
(let [starred (repos/starring "clojj"
{:accept "application/" :auth token
clojj / gist:2366602e794633a059db
Created Feb 13, 2015
Review changes in **/pom.xml before merging release- or feature-branch
View gist:2366602e794633a059db
find . -name "pom.xml" | xargs git diff master..some-release-or-feature/foo-bar --
clojj / core.clj
Created Feb 23, 2015
peek into transducing
View core.clj
(ns transpeek.core
(:import (java.util ArrayList)))
(defn map-
(fn [rf]
([] (rf))
([result] (rf result))
clojj / solution_53.clj
Created Mar 1, 2015
using transducers.. needs clojure 1.7.0
View solution_53.clj
(ns solutions-4clojure.solution-53
(:import (java.util ArrayDeque)))
(defn subseq-by [f]
(fn [rf]
(let [deq (ArrayDeque.)]
([] (rf))
clojj / progressor.clj
Last active Aug 29, 2015
in response to .... so (start) will give you a channel to put initial states on.. or you can comment-in line 70
View progressor.clj
(ns async-state-progressor.progressor
(:require [clojure.core.async :refer [go-loop >! <! thread chan timeout onto-chan]]))
(defn log-state [msg current-state]
(locking *out* (println msg (:state current-state))))
(defn download-report [{:keys [client date] :as state}]
;; snip
(assoc state :file "dummy-file"))