Skip to content

Instantly share code, notes, and snippets.

@clojj
clojj / gist:216a7d274878420ac053
Created April 20, 2015 15:09
parallel grep recursively for STRING-content (requires GNU parallel package)... replace STRING with what you are looking for !
find . -type f | parallel -k -j150% -n 1000 -m grep -i -H -n 'STRING' {}
@clojj
clojj / progressor.clj
Last active September 3, 2023 09:25
in response to http://oobaloo.co.uk/multiplexing-work-reliably-and-efficiently-with-state-machines-and-core-dot-async .... so (start) will give you a channel to put initial states on.. or you can comment-in line 70
(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"))
@clojj
clojj / solution_53.clj
Created March 1, 2015 22:41
using transducers.. needs clojure 1.7.0
(ns solutions-4clojure.solution-53
(:import (java.util ArrayDeque)))
(defn subseq-by [f]
(fn [rf]
(let [deq (ArrayDeque.)]
(fn
([] (rf))
([result]
@clojj
clojj / core.clj
Created February 23, 2015 12:50
peek into transducing
(ns transpeek.core
(:gen-class)
(:import (java.util ArrayList)))
(defn map-
([f]
(fn [rf]
(fn
([] (rf))
([result] (rf result))
@clojj
clojj / gist:2366602e794633a059db
Created February 13, 2015 10:05
Review changes in **/pom.xml before merging release- or feature-branch
find . -name "pom.xml" | xargs git diff master..some-release-or-feature/foo-bar --
@clojj
clojj / core.clj
Created January 25, 2015 00:03
sort starred repos by commit-count in last n days
(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
@clojj
clojj / core.clj
Created January 23, 2015 23:45
github v3 api with tentacles
(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"})
@clojj
clojj / persist-starred.groovy
Created January 14, 2015 21:27
retrieves my starred repos from Github v3 API and stores them in HSQL
@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')
(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
clojj / gist:646e6b3e002e49d0996f
Last active August 29, 2015 14:07
combinating ppm images
(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")))))