Skip to content

Instantly share code, notes, and snippets.

View jessitron's full-sized avatar
🚀
"I'm in"

Jessica Kerr jessitron

🚀
"I'm in"
View GitHub Profile
@jessitron
jessitron / gist:9644001
Created March 19, 2014 15:22
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead.
// 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 / stayingDead.scala
Created March 19, 2014 15:23
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
// 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 / etaExpansionAndImplicits
Created April 16, 2014 22:59
scala is so weird
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 / methodAsFunction
Last active August 29, 2015 14:00
JavaScript illustrates that methods are the same as functions with an implicit parameter "this"
var completeSale = function(num) {
console.log("Sale " + num + ": selling " + this.items + " to " + this.customer);
}
var foo = {
customer: "Fred",
items: ["carrot","eggs"],
complete: completeSale
};
@jessitron
jessitron / threadingMacro
Last active August 29, 2015 14:00
The threading macro lets us define functions ABOUT data instead of making methods on classes, while still using a top-down ordering of code.
(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 / Condensed Letter to a Haskellyte
Last active January 31, 2017 06:24
Gershom's Letter to a Young Haskell Enthusiast, summarized. I removed a lot of words, kept the themes, moved a few around a bit.
# 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 / haskellyte.md
Created August 1, 2014 16:12
Gershom's Letter to a Young Haskell Enthusiast, condensed. I removed a lot of words, kept the themes, moved a few around a bit.

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 / main.log
Created October 14, 2014 05:02
random input file for demonstration
== Summum Bonum, by Robert Browning ==
All the breath and the bloom of the year
In the bag of one bee
All the wonder and wealth of the mine
In the heart of one gem
In the core of one pearl all the shade
And the shine of the sea
Breath and bloom, shade and shine, wonder, wealth,
And how far above them
Truth that's brighter than gem
@jessitron
jessitron / idea
Last active July 5, 2022 13:30
The Empty Buffer, by @fogus
You're sitting there and
all the sudden something comes to you and everything stops
You look down at no point in particular
but then the music is thrumming in your ears and
you see these colors come at the edge of your vision
red and yellow and blue, focusing in on them
If you can't stop it because you don't want to lose it
and you know that there's something there
Your vision blurs a bit and it becomes
this blackness in front of you
@jessitron
jessitron / Box.elm
Created July 11, 2015 17:51
An Elm type error that took me for a while to understand
module Box (Model, init, Action, update, view) where
import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
-- MODEL
type alias Model = ()