This file contains hidden or 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
(require '[fun-utils.agent :as fagent] :reload) | |
(def agnt (fagent/agent {} :mailbox-len 10)) | |
;send to the agent | |
(fagent/send agnt assoc-in [:a :b] 2) | |
;deref | |
@agnt | |
;;{:a {:b 2}} |
This file contains hidden or 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
(defrecord MyItem [a b c]) | |
(apply ->MyItem ["1" "2" "3"]) | |
;; #user.MyItem{:a "1", :b "2", :c "3"} | |
(map #(apply ->MyItem %) [ [1 2 3] [4 5 6] [7 8 9]]) | |
;;(#user.MyItem{:a 1, :b 2, :c 3} #user.MyItem{:a 4, :b 5, :c 6} #user.MyItem{:a 7, :b 8, :c 9}) |
This file contains hidden or 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 safe-inc [l ^long x] | |
(if l | |
(+ ^long l x) | |
x)) | |
// Compiled from form-init2140241509718408406.clj (version 1.5 : 49.0, super bit) | |
public final class no.disassemble$eval1752$safe_inc__1753 extends clojure.lang.AFunction implements clojure.lang.IFn$OLO { | |
// Field descriptor #9 Lclojure/lang/Var; | |
public static final clojure.lang.Var const__0; |
This file contains hidden or 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
!/usr/bin/env bash | |
NODE="$1" | |
echo "Bootstrapping node $1" | |
function install_setup(){ | |
yum update | |
yum -y install wget vim snappy-devel snappy lzo lzop elinks glibc.i686 | |
} |
This file contains hidden or 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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.provider "virtualbox" do |v| | |
v.customize ["modifyvm", :id, "--memory", "2048"] |
This file contains hidden or 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
(def msgs [ {"a" {:stat1 1 :stat2 10} "b" {:stat1 1}} {"a" {:stat1 1}}]) | |
(def merged (apply merge-with (partial merge-with +) msgs)) | |
;; {"a" {:stat1 2, :stat2 10}, "b" {:stat1 1}} | |
(prn merged) | |
;; {"a" {:stat1 2, :stat2 10}, "b" {:stat1 1}} | |
(= (-> merged first second :stat1) 2) | |
;; true |
This file contains hidden or 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
(require '[clojure.core.async :refer [go-loop chan <! close!]]) | |
(require '[fun-utils.core :refer [go-seq]]) | |
;When writing go blocks there is a repeating pattern to avoid 100% cpu spin when the channel is closed. | |
;e.g. | |
;if we run the below code, the loop will spin without pause. | |
;;running this code will cause nil to be printed without pause |
This file contains hidden or 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
(require '[clojure.core.async :refer [chan go >! <! >!! <!!]]) | |
(require '[clojure.core.async :as async]) | |
(defn chan-bridge | |
([ch-source map-f ch-target] | |
"map map-f onto ch-source and copy the result to ch-target" | |
(chan-bridge (async/map map-f [ch-source]) ch-target)) | |
([ch-source ch-target] | |
"in a loop read from ch-source and write to ch-target | |
this function returns inmediately and returns the ch-target" |
This file contains hidden or 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
(require '[clojure.core.async :refer [go alts! >! <! >!! <!! chan timeout]]) | |
(defn buffered-chan | |
"Reads from ch-source and if either timeout or the buffer-count has been | |
read the result it sent to the channel thats returned from this function" | |
([ch-source buffer-count timeout-ms] | |
(buffered-chan ch-source buffer-count timeout-ms 1)) | |
([ch-source buffer-count timeout-ms buffer-or-n] | |
(let [ch-target (chan buffer-or-n)] | |
(go |
This file contains hidden or 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
(use 'clojure.core.async) | |
(defn offer [ch msg timeout-ms] | |
"Blocks till the message can be placed on the queue and returns true otherwise returns false" | |
(not | |
(nil? | |
(first (alts!! [(go (>! ch msg) msg) (timeout timeout-ms)]))))) | |
;;lets test |