Skip to content

Instantly share code, notes, and snippets.

(ns flat-workflow.functions.sample-functions)
(defn ^{:batch-size 10 :onyx? true} increment-age [segment]
(update-in segment [:age] inc))
(defn ^{:batch-size 10 :onyx? true} legal?
"hello world"
[age segment]
age)
@gardnervickers
gardnervickers / gist:9e915efc3ec875c68bcd
Last active August 29, 2015 14:21
flow-combine in onyx
Executing before task -=___ Peer 1 starts task/job and batch
Executing before batch -=__/ Segments are loaded through the :core.async/read-from-chan :in
Executing after batch -=__/
Executing before batch -=___ Segments are loaded into the :inc function and processed
Executing after batch -=__/
Executing before batch -=___ Segments are loaded through the :core.async/write-to-chan :out
Executing after task -=___ Why does this happen *before* "Executing after batch"
Executing after batch -=__/
@gardnervickers
gardnervickers / gist:178f4c4ac0607f6275c5
Last active August 29, 2015 14:23
Read json file and parse to edn with core.async
(defn try-parse [x]
(try
(json/parse-string x true)
(catch Exception e
x)))
(defn lazy-test-data []
"Returns a channel that reads json maps line by line from mock_data.json "
(let [channel (chan 5 (map try-parse))]
(future (with-open [rdr (clojure.java.io/reader "resources/mock_data.json")]
;; Code
[[:in :concat-names]
[:concat-names :parse-dates]
[:parse-dates :time-left]
[:time-left :notify-near-expiration]
[:notify-near-expiration :out]
[:time-left :out]]
;; What the code means
:in ; Read data line-by-line from a file
(defn gen-contact-table
[size]
(mapv (fn [i]
{:name (str (rand-nth ["Gardner" "Mike" "Matt" "Jordan" "Vinny" "Jacob"])
" "
(rand-nth ["Vickers" "Heskie" "Dawson" "Carol" "Stark"]))
:email (rand-nth ["gardner@vickers.me" "test@test.com" "fakemail@inva.lid"])
:position (rand-nth ["floor-sweeper" "cart-pusher" "president"])
:company (rand-nth ["mcdonalds" "carousel" "medlyfe" "YoloCorp"])
:expertise [(rand-nth ["avaya" "nortel" "cisco" "alarmtraq"])
export GOVC_RESOURCE_POOL='*/Resources'
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
mv lib lib2 // Moved the symlink
cp lib2 ~/jars // copied the jars from lib2 to ~/jars
cp -r lib2 ~/jars // recursive copy ^^
cp -r lib2 ~/jars // recursive copy ^^
sudo cp -r lib2 ~/jars // recursive copy ^^ sudo
find lib2 -user root -exec cp {} ~/lib/{} \; // copy jars owned by root to ~/lib in my local
find lib2/ -user root -exec cp {} ~/lib/{} \; // sudo copy jars owned by root to ~/lib in my local
ls lib2
mv lib2 lib // reset lib2 to lib
[:pdf-table
[10 20 15]
["foo" [:chunk {:style :bold} "bar"] [:phrase "baz"]]
[[:pdf-cell "foo"] [:pdf-cell "foo"] [:pdf-cell "foo"]]
[[:pdf-cell "foo"] [:pdf-cell "foo"] [:pdf-cell "foo"]]]
(defn start-go-peer
"Applies XF"
([in-chan xf] (start-go-peer in-chan xf (chan)))
([in-chan xf out-chan] (start-go-peer in-chan xf out-chan 1))
([in-chan xf out-chan parallelism]
(let [running? (atom true)]
(do (async/pipeline parallelism out-chan xf in-chan)
{:fauonyx/out out-chan
:fauonyx/in in-chan