Skip to content

Instantly share code, notes, and snippets.

@LukeDefeo
LukeDefeo / tail.sc
Last active June 18, 2020 11:37
Tail recursion in scala explainer
def sumNonTail(ints: List[Int]): Int = {
ints match {
case Nil => 0
case x :: xs => x + sumNonTail(xs)
}
// bytecode
// temp = sumNonTail(i) <-- recursive call not in tail position, the result of the recursive call is being 'post-processed' and has to be stored on the stack as it cant return out
// return x + temp
val testSource = Source(1 until 50)
val processingFlow: Flow[Int, Int, NotUsed] = Flow[Int].mapAsyncUnordered(10)(x => Future {
println(s"Kicking off $x")
Thread.sleep(Random.nextInt(500))
x * 10
})
testSource.via(processingFlow).runWith(Sink.seq[Int])```
@LukeDefeo
LukeDefeo / macos-certificates-to-java-keystore.sh
Created November 22, 2017 14:28
Extracts all certificates from the mac os certificate store / key chain and imports them into the key chain of your Java installation
#!/bin/bash
#this script should pull all root CAs from the mac os keychain and add them to the jre's keystore
#Comes with absolutely no warranty and all the usual disclaimers
mkdir temp-extract
cd temp-extract
keystore=$JAVA_HOME/jre/lib/security/cacerts
echo "making backup of keystore $keystore to ~/keystore.backup"
set -e -o pipefail
@LukeDefeo
LukeDefeo / struct_and_inheritance.swift
Last active September 28, 2015 20:34 — forked from AliSoftware/struct_vs_inheritance.swift
Swift-Struct-Inheritance
// #!Swift-.
import Foundation
// MARK: - () classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/