Skip to content

Instantly share code, notes, and snippets.

(def values
[[(/ 1.0 2.0)
(/ 1.0 2.0)]
[(/ 1.0 3.0)
(/ 1.0 3.0)
(/ 1.0 3.0)]])
(defn mean
[xs]
(/ (double (reduce + xs)) (count xs)))
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='{:deps {aysylu/loom {:mvn/version "1.0.2"}
org.apache.kafka/kafka-streams {:mvn/version "2.2.0"}}}'
#_You can put other options here
OPTS='-J-Xms256m -J-Xmx256m -J-client'
exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@"
)
(setq-default indent-tabs-mode nil)
(load "server")
(unless (server-running-p)
(server-start))
(defun mac-metas ()
"for mac keyboard"
(setq mac-option-modifier 'super)
(setq mac-command-modifier 'meta))
@tristanstraub
tristanstraub / async-apply.cljs
Created December 29, 2016 20:51
Javascript async interop between callbacks/promises and channels
(ns service.async
(:require-macros [cljs.core.async.macros :as a])
(:require [cljs.core.async :as a]))
(defn <cb [f & args]
(let [out (a/chan)]
(apply f (conj (into [] args) #(a/close! out)))
out))
(defn <promise [f & args]
(ns watermarks)
(defn partition-of
[partitions key]
(mod (.hashCode "test") partitions))
(def partitions 12)
(defn produce!
[broker topic key message]
@tristanstraub
tristanstraub / consumer.sh
Created August 30, 2018 01:38 — forked from dongjinleekr/consumer.sh
Kafka benchmark commands
## Consumer Throughput: Single consumer thread, no compression
## Consumer Throughput: 3 consumer thread, no compression
bin/kafka-consumer-perf-test.sh --topic benchmark-3-3-none \
--zookeeper kafka-zk-1:2181,kafka-zk-2:2181,kafka-zk-3:2181 \
--messages 15000000 \
--threads 1
@tristanstraub
tristanstraub / init.el
Created August 9, 2018 04:00
el-get with ensure-package
(load "server")
(unless (server-running-p)
(server-start))
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(add-to-list 'load-path (expand-file-name "el-get/el-get" "~/.emacs.d"))
@tristanstraub
tristanstraub / gist:d3afd14f7223ea3350b8c24b4d92a649
Created April 12, 2018 06:49
Start clojure socket repl and connect to it with netcal
clj -J-Dclojure.server.repl="{:port 1234 :accept clojure.core.server/repl}"
rlwrap -q ^Q nc 127.0.0.1 1234
@tristanstraub
tristanstraub / tree.clj
Last active February 7, 2018 00:06
Compress clojure data structure -- find common subtrees and move them into a lookup table.
(ns trees
(:require [clojure.walk :as walk]))
(defonce id (atom 0))
(defrecord Ref [id])
(defn new-id! []
(->Ref (swap! id inc)))
[org.apache.kafka/kafka-clients "0.11.0.0"]
[spootnik/kinsky "0.1.16"]
(ns space.kafka
(:require [kinsky.client :as client])
(:import [java.util ArrayList Properties]
org.apache.kafka.clients.consumer.KafkaConsumer
[org.apache.kafka.clients.producer KafkaProducer ProducerRecord]
[org.apache.kafka.common.serialization StringDeserializer StringSerializer]
org.apache.kafka.common.TopicPartition