Skip to content

Instantly share code, notes, and snippets.

View schaueho's full-sized avatar

Holger schaueho

View GitHub Profile
@schaueho
schaueho / crypto.cljs
Created August 18, 2020 08:20
ClojureScript interop calls of SodiumPlus code triggers type inference warnings
(defn encrypt-test [plaintext]
(go
(let [sodium (.-sodium js/window) ;; <-- this
nonce (<p! (.randombytes_buf sodium 24))
key (<p! (.crypto_secretbox_keygen sodium))
ciphertext (<p! (.crypto_secretbox sodium plaintext nonce key))]
(println "key: " (.toString key "hex"))
(println "cipher:" (.toString ciphertext "hex"))
(println "decrypted:" (.toString (<p! (.crypto_secretbox_open sodium ciphertext nonce key)))))))
@schaueho
schaueho / threadripper-debian.md
Last active January 24, 2019 18:57
Threadripping under Debian

Getting a Threadripper machine working under Debian

After a long long time of more than eight years my old machine started showing hardware problems: first the power supply failed and had to be replaced. Next the CMOS battery died. It became clear that finally a replacement would be in order. When the first reports about AMDs Ryzen family came out and in particular with the Threadripper tests, I became interested. In the end, I waited until the Threadripper 2950X was available before ordering a custom-built machine from a local vendor. Here is the basic hardware setup:

  • CPU: Threadripper 2950X (32 cores)
  • Mainboard: MSI 399X Carbon
  • Memory: 32 GB
  • GPU: Nvidia 1060
  • SSD: Samsung 970 Evo NVM 1TB
@schaueho
schaueho / aggregation.core.clj
Created June 26, 2018 08:24
Onyx emit aggregation example, not working
(ns aggregation.core
(:require [clojure.core.async :refer [chan >!! <!! close!]]
[onyx.extensions :as extensions]
[onyx.plugin.core-async :refer [take-segments!]]
[onyx.api])
(:gen-class))
;;; Word count!
;;; Split a sentence into words, emit a seq of segments
@schaueho
schaueho / gist:79c8d19a7304a2994599
Last active August 29, 2015 14:25
Generate a random text collection
(defn file2wordlist [wordlistfile]
(-> (slurp wordlistfile)
(str/triml)
(str/split #"\s+")
((partial concat ["." ","]))))
(defn generate-random-text-coll
"Generate a random text collection with nrtexts texts that are up to maxlength long.
Wordlist should be a file with one word per line."
[wordlist nrtexts maxlength]
@schaueho
schaueho / gist:5726a96641693dce3e47
Last active August 29, 2015 14:23
Some notes on core.async channels

Notes on core.async usage:

go and thread will return a channel with buffer-size of zero containing the result of the body. That's exploited in the following snippet from the core.async walkthrough, which more or less "tests" (asserts) that the value "hello" is successfully communicated over the channel c.

(let [c (chan)]
	 (go (>! c "hello"))
	 (assert (= "hello" (<!! (go (<! c)))))
	 (async/close! c))

Note that the assert is neither within the go block nor directly outside go, because as outlined above, the result will be another channel. So the assertion checks the result of the blocking take !&lt;&lt; on the result channel. This is a useful pattern for testing core.async code: return the result channel from your taking code and run the test with a blocking take on it, like this: