Skip to content

Instantly share code, notes, and snippets.

scala> import cats._, cats.instances.all._
import cats._
import cats.instances.all._
scala> :paste
// Entering paste mode (ctrl-D to finish)
sealed trait TrafficLight
object TrafficLight {
def red: TrafficLight = Red
@jamie-allen
jamie-allen / gist:8571694
Created January 23, 2014 02:21
A complaint to US Airways
I'm Chairman's Preferred, but I'm switching to another airline to stay on the Star Alliance the second the changeover occurs in March. I'm tired of US Airways' cattle cars with no services except wifi. You don't even give power outlets to first class travelers. That's absurd.
I'm tired of being told ludicrous explanations that my flight from SFO to Zurich is "direct," despite stopping in PHL, changing planes and likely having to switch terminals. I'm tired of flying in outdated 767s that leak water on me. I'm tired of your flight attendants' attitudes, that when I point out the water leaking on me from the water-damaged internal fuselage, tells me there's nothing they can do about it instead of WRITING IT DOWN SO A MAINTENANCE PERSON CAN FIX IT. I'm tired of complaining about poor service and having another flight attendant complain back at me that they lost their personal closets in the latest plane overhauls, as if I should care about that. I'm tired of not having a personal movie system in economy
@jamie-allen
jamie-allen / gist:7833551
Created December 6, 2013 22:54
How to bypass Scala trait linearization
scala> trait A { def p: Unit }
defined trait A
scala> trait B extends A { def p = println("b") }
defined trait B
scala> trait C extends A { def p = println("c") }
defined trait C
scala> class D extends B with C { override def p = { super[B].p } }
80 pages in pre-production length
Preface
Part I. Actor Application Types
1. Domain-Driven
Domain-driven messages are “facts”
2. Work Distribution
Routers and routees
Random
➜ ~ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_10-ea).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :cp /Users/jamie/.ivy2/local/com.typesafe/config/0.4.2-SNAPSHOT/bundles/config.jar
Added '/Users/jamie/.ivy2/local/com.typesafe/config/0.4.2-SNAPSHOT/bundles/config.jar'. Your new classpath is:
".:/Users/jamie/.ivy2/local/com.typesafe/config/0.4.2-SNAPSHOT/bundles/config.jar"
Nothing to replay.
import akka.actor.OneForOneStrategy
import akka.actor.SupervisorStrategy._
import akka.actor.ActorSystem
import akka.actor.Actor
import akka.util.duration._
import akka.actor.Props
case object Start
case object MakeCrash
class AccountBalanceRetrieverFinal(savingsAccounts: ActorRef, checkingAccounts: ActorRef, moneyMarketAccounts: ActorRef) extends Actor {
def receive = {
case GetCustomerAccountBalances(id) => {
val originalSender = sender
implicit val ec: ExecutionContext = context.dispatcher
context.actorOf(Props(new Actor() {
val promisedResult = Promise[AccountBalances]()
var checkingBalances, savingsBalances, mmBalances: Option[List[(Long, BigDecimal)]] = None
def receive = {
Async {
Logger.debug(s"Start $duration second wait")
Akka.system.scheduler.scheduleOnce(duration seconds){
val blocker = Future { duration }
blocker map { duration =>
Logger.debug(s"Finished $duration second wait")
Ok(duration.toString)
}
}
}
@jamie-allen
jamie-allen / gist:4121396
Created November 20, 2012 21:45
Console stack trace
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/jamie/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/jamie/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
13:31:11.616 [consoletest-akka.actor.default-dispatcher-1] INFO a.a.t.Slf4jTraceContextEventHandler - Slf4jEventHandler started
13:31:11.620 [consoletest-akka.actor.default-dispatcher-2] DEBUG akka.event.EventStream - logger log1-Slf4jTraceContextEventHandler started
13:31:11.620 [consoletest-akka.actor.default-dispatcher-2] DEBUG akka.event.EventStream - Default Loggers started
13:31:11.639 [consoletest-akka.actor.default-dispatcher-4] INFO o.j.c.Bootstrap$$anonfun$5$$anon$1 - **** Starting balance retrieval ****
13:31:11.672 [consoletest-akka.actor.default-dispatc
@jamie-allen
jamie-allen / gist:4069114
Created November 13, 2012 23:24
NPE in DefaultPromise.future.map
package org.jamieallen.consoletest
import akka.util.duration._
import akka.actor._
import akka.dispatch.ExecutionContext
import akka.dispatch.Promise
import java.util.concurrent.TimeoutException
import akka.dispatch.Await
import akka.pattern.pipe