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:9191499
Created February 24, 2014 16:24
StackOverflow in scalaz-stream. My trampoline is not bouncy enough
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: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 / 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 / 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 / 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 = ()
@jessitron
jessitron / Failure.elm
Created August 16, 2015 00:07
An Elm Error: declaring a type equal to another doesn't make sense
module Failure where
import InnerComponent
--- ACTION
type InnerAction = InnerComponent.Action -- oops, meant type alias
type Action = Passthru InnerAction
-- MODEL
@jessitron
jessitron / EffectsTest.elm
Last active September 22, 2015 15:08 — forked from urfolomeus/EffectsTest.elm
The send Task can turn into the NoOp effect
module EffectsTest where
import Html exposing (..)
import Html.Events exposing (onClick)
import StartApp exposing (App)
import Task exposing (Task)
import Effects exposing (Effects, Never)
@jessitron
jessitron / speakerStats.scala
Created October 18, 2012 16:36
Play with the CodeMash API to analyze gender distribution of speakers
import scala.xml._
// curl http://rest.codemash.org/api/speakers > speakers.xml
val speakers = xml.XML.loadFile("codemashSpeakers.xml") \ "Speaker"
// curl http://rest.codemash.org/api/sessions > sessions.xml
val sessions = xml.XML.loadFile("sessions.xml") \ "Session"
val masculineWords = List("he","his")
val feminineWords = List("she","her","hers","lady")
def bioContainsAnyWord( strings : Seq[String], speakerNode : Node) =