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 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 | |
*/ | |
shared | |
class chan(T) { | |
Mutex lock; | |
private bool closed_; bool closed() {synchronized (lock) {return closed_;}} void Close() { synchronized(lock) { closed_ = true; } } |
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 [] | |
(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"))))) |
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 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)) |
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
@GrabResolver(name='gstorm', root='http://dl.bintray.com/kdabir/maven') | |
@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 groovyx.net.http.ContentType.TEXT | |
@Grab(group='commons-io', module='commons-io', version='2.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
(ns github-api.core | |
(:gen-class) | |
(:require [tentacles.repos :as repos]) | |
(:use [clojure.pprint]) | |
(:import (java.time Period LocalDateTime))) | |
(let [starred (repos/starring "clojj" | |
{:per-page 4 | |
:accept "application/vnd.github.v3.star+json"}) |
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 github-api.core | |
(:gen-class) | |
(: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/vnd.github.v3.star+json" :auth token |
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
find . -name "pom.xml" | xargs git diff master..some-release-or-feature/foo-bar -- |
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 transpeek.core | |
(:gen-class) | |
(:import (java.util ArrayList))) | |
(defn map- | |
([f] | |
(fn [rf] | |
(fn | |
([] (rf)) | |
([result] (rf result)) |
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 solutions-4clojure.solution-53 | |
(:import (java.util ArrayDeque))) | |
(defn subseq-by [f] | |
(fn [rf] | |
(let [deq (ArrayDeque.)] | |
(fn | |
([] (rf)) | |
([result] |
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 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")) |
OlderNewer