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
(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 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 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 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 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 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 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 '(java.io InputStreamReader FileInputStream BufferedReader)) | |
(import '(java.util.zip GZIPInputStream)) | |
(defn gz-line-counter [^String file-name] | |
(let [^BufferedReader reader (BufferedReader. (InputStreamReader. (GZIPInputStream. (FileInputStream. file-name))))] | |
(try | |
(loop [i 0] | |
(if (.readLine reader) | |
(recur (inc i)) | |
i)) |
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
package lazyseq; | |
import org.junit.Test; | |
import clojure.lang.AFn; | |
import clojure.lang.ASeq; | |
import clojure.lang.ArraySeq; | |
import clojure.lang.Cons; | |
import clojure.lang.IPersistentMap; | |
import clojure.lang.ISeq; |
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
int ret = new ProcessBuilder("gzip", "-t", "t.txt.gz").inheritIO().start().waitFor() | |
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
Caution: Partitioning lazy sequence code freeze | |
(def l [1 2 3 4 5]) | |
;create a simple lazy sequence function testing only | |
;(rdr l) returns a lazy sequence from l | |
(def rdr (fn reader[x] (cons (first x) (lazy-seq (reader (rest x)))))) | |
;the line below will freeze | |
(doall (partition-all 2 (rdr l)) ) |
OlderNewer