Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Deep Work

Trevor Hartman devth

Deep Work
View GitHub Profile
def getOrCreate[A](m: JMap[Any, Any], key: Any, create: A): A = {
if (m.containsKey(key)) m.get(key).asInstanceOf[A]
else {
m.put(key, create)
create
}
}
def storeAtPath(m: JMap[Any, Any], path: Seq[String], values: Seq[Any]) {
path.toList match {
sealed trait NestedProjection
case class Field(name: String) extends NestedProjection
case class NestedField(field: Field, child: NestedProjection) extends NestedProjection

Keybase proof

I hereby claim:

  • I am devth on github.
  • I am devth (https://keybase.io/devth) on keybase.
  • I have a public key whose fingerprint is 2E06 04DD 164E F921 8B97 EF06 EE84 56ED C976 4E34

To claim this, I am signing this object:

(def ^{:dynamic true} foo "ok")
(binding [foo "y u no"]
(def aa (go (Thread/sleep 10000) foo)))
(<!! aa) ;=> y u no
# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
set-window-option -g mode-mouse on
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf
import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
val load = (x: Int) => future { Thread.sleep(200); x }
val f = Future.traverse(1 to 100)(load)
Await.result(f, Duration.Inf)
// scala.collection.immutable.IndexedSeq[Int] = Vector(1, 2, 3, 4, 5, 6, 7, 8,
// 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
// 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
function insertEvery(str, xChars, strToInsert) {
var newStr = "", times = Math.ceil(str.length / xChars);
for (var i = 0; i < times; i++) {
newStr += str.substr(i * xChars, xChars) + strToInsert;
}
return newStr;
}
;;; Pallet project configuration file
(require '[pallet.crate.java :as java]
'[pallet.crate.runit :as runit]
'[pallet.crate.lein :as lein]
'[pallet.crate.app-deploy :as app-deploy]
'pallet.compute)
(defplan setup-machine []
(package-manager :update)
(packages :apt ["git"]))
@devth
devth / stacksize.clj
Last active June 20, 2017 19:02
explore the size of the clojure stack
(defn stacksize [] (try (throw (Exception. "")) (catch Exception e (count (.getStackTrace e)))))
(defn prss [] (print (stacksize) " "))
; stack size doesn't increase with proper loop/recur
(loop [x 0] (prss) (when (> 10 x) (recur (inc x))))
; 24 24 24 24 24 24 24 24 24 24 24 nil
; stack size increases with recursion
(defn rec [x continuation]
(prss)