Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
"I'm in"

Jessica Kerr jessitron

🚀
"I'm in"
View GitHub Profile
@jessitron
jessitron / haskellyte.md
Created Aug 1, 2014
Gershom's Letter to a Young Haskell Enthusiast, condensed. I removed a lot of words, kept the themes, moved a few around a bit.
View haskellyte.md

Letter to a Young Haskell Enthusiast, by Gershom Bazerman.

Condensed from: http://comonad.com/reader/2014/letter-to-a-young-haskell-enthusiast/

The following letter is about tendencies that come with the flush of excitement of learning any new thing. It is written specifically, because if we don't talk specifics, the generalities make no sense. It is a letter full of things I want to remember.

You’ve entered the world of strongly typed functional programming, and it is great. You want to share the great things you’ve learned, and you want to slay all the false statements in the world.

@jessitron
jessitron / Condensed Letter to a Haskellyte
Last active Jan 31, 2017
Gershom's Letter to a Young Haskell Enthusiast, summarized. I removed a lot of words, kept the themes, moved a few around a bit.
View Condensed Letter to a Haskellyte
# Letter to a Young Haskell Enthusiast, by Gershom Bazerman.
Condensed from: http://comonad.com/reader/2014/letter-to-a-young-haskell-enthusiast/
The following letter is about tendencies that come with the flush of excitement of learning any new thing.
It is written specifically, because if we don't talk specifics, the generalities make no sense.
It is a letter full of things I want to remember.
You’ve entered the world of strongly typed functional programming, and it is great.
You want to share the great things you’ve learned, and you want to slay all the false statements in the world.
@jessitron
jessitron / threadingMacro
Last active Aug 29, 2015
The threading macro lets us define functions ABOUT data instead of making methods on classes, while still using a top-down ordering of code.
View threadingMacro
(defn addCustomer [sale, cust] (assoc sale :customer cust))
(defn addItems [sale, items] (assoc sale :items items))
(defn complete [sale, num] (println "Sale" num ": selling" (:items sale) "to" (:customer sale)))
(def sale { :store "Downtown" })
(-> sale
(addCustomer "Fred")
(addItems ["carrot", "eggs"])
(complete 100)
@jessitron
jessitron / methodAsFunction
Last active Aug 29, 2015
JavaScript illustrates that methods are the same as functions with an implicit parameter "this"
View methodAsFunction
var completeSale = function(num) {
console.log("Sale " + num + ": selling " + this.items + " to " + this.customer);
}
var foo = {
customer: "Fred",
items: ["carrot","eggs"],
complete: completeSale
};
View etaExpansionAndImplicits
scala> class Banana[P] {}
defined class Banana
// We will know when this gets called, when the banana is needed
scala> implicit def myBanana[P]: Banana[P] = { println("banana time"); new Banana[P] }
myBanana: [P]=> Banana[P]
// method with implicits
scala> def addWithBanana(one: Int)(two: Int)(implicit banana: Banana[Int]) = {println(banana); one + two}
@jessitron
jessitron / stayingDead.scala
Created Mar 19, 2014
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead. See: http://blog.jessitron.com/2014/03/testing-in-akka-sneaky-automatic.html
View stayingDead.scala
// In real life, it's great that stuff gets restarted when it fails.
// In testing, we'd rather know that it failed.
import akka.actor._
class DyingActor extends Actor {
def receive = { case "die" => throw new Exception("poo") }
}
// Default config, everything restarts automatically
val system = ActorSystem("ordinary")
@jessitron
jessitron / gist:9644001
Created Mar 19, 2014
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead.
View gist:9644001
// In real life, it's great that stuff gets restarted when it fails.
// In testing, we'd rather know that it failed.
import akka.actor._
class DyingActor extends Actor {
def receive = { case "die" => throw new Exception("poo") }
}
// Default config, everything restarts automatically
val system = ActorSystem("ordinary")
@jessitron
jessitron / gist:9191499
Created Feb 24, 2014
StackOverflow in scalaz-stream. My trampoline is not bouncy enough
View gist:9191499
import scalaz.stream._
import Process._
import scalaz.concurrent.Task
import scala.concurrent.duration._
// git bisect identifies the offending commit as
// https://github.com/scalaz/scalaz-stream/commit/721716ed7af0c126593e9ee227c0f36f21c5b7ed
object Test {
@jessitron
jessitron / gist:8777503
Created Feb 3, 2014
The magic of blocking { ... } in Scala's global ExecutionContext: it leads to the creation of more threads, so the CPUs don't get bored
View gist:8777503
val des = scala.concurrent.ExecutionContext.global
import scala.concurrent._
import duration._
def ct = Thread.currentThread.getName
val n = Runtime.getRuntime.availableProcessors
def hogThread(sec:Int) = future {
@jessitron
jessitron / gist:8376139
Created Jan 11, 2014
scala: print all URLs on classpath
View gist:8376139
def urlses(cl: ClassLoader): Array[java.net.URL] = cl match {
case null => Array()
case u: java.net.URLClassLoader => u.getURLs() ++ urlses(cl.getParent)
case _ => urlses(cl.getParent)
}
val urls = urlses(getClass.getClassLoader)
println(urls.filterNot(_.toString.contains("ivy")).mkString("\n")
You can’t perform that action at this time.