Skip to content

Instantly share code, notes, and snippets.

@jamie-allen
jamie-allen / gist:1068213
Created July 6, 2011 20:15
Duncan Example
import scala.actor._
import scala.actor.Actor._
sealed trait DoSomething
case class SaySomething(text: String) extends DoSomething
case class YellSomething(text: String) extends DoSomething
object DuncanExample {
def main(args: Array[String]) {
val nActors = 5
@jamie-allen
jamie-allen / gist:1270249
Created October 7, 2011 13:15
for comprehensions
scala> Map("0110529461001" -> Set("0010ddecf7", "0010da6be5"), "0110519163601" -> Set("0010edc96f"), "0110513382403" -> Set("0010edcaee"), "0110519771404" -> Set("0010ddee12"))
res0: scala.collection.immutable.Map[java.lang.String,scala.collection.immutable.Set[java.lang.String]] = Map(0110529461001 -> Set(0010ddecf7, 0010da6be5), 0110519163601 -> Set(0010edc96f), 0110513382403 -> Set(0010edcaee), 0110519771404 -> Set(0010ddee12))
scala> Map("0010da6be5" -> Set("!|", "!("), "0010ddecf7" -> Set( "!_"), "0010ddee12" -> Set( "!&"), "0010edcaee" -> Set( "|&"), "0010edc96f" -> Set( "!|", "!&", "|_"))
res1: scala.collection.immutable.Map[java.lang.String,scala.collection.immutable.Set[java.lang.String]] = Map(0010ddee12 -> Set(!&), 0010edcaee -> Set(|&), 0010da6be5 -> Set(!|, !(), 0010edc96f -> Set(!|, !&, |_), 0010ddecf7 -> Set(!_))
scala> Map("!&" -> Set("91", "32859"), "!I" -> Set("60", "32838", "61", "88", "63", "32856", "62", "58", "32807", "32802", "145149", "40", "32803", "1", "32808", "59", "39", "34"
@jamie-allen
jamie-allen / gist:1270960
Created October 7, 2011 18:06
final code
package com.comcast.ues.vcwloader
import scala.io.Source
import scala.collection.mutable.{MultiMap, HashMap => MHash, Set => MSet}
object VcwLoader extends App {
override def main(args: Array[String]) {
new VcwLoader().loadData
}
}
/**
* I'm trying to create a basic supervisor hierarchy with four actors. If any fail for
* any reason, tear them all down and restart them to re-process any unhandled
* data. When I run, I see the "Blowing up!" log output. I expect the ensuing throw
* to blow up my actors, and then I should see all of my actors restarted per my
* supervision strategy, but I just get a message timeout (None response to the
* producer).
*
* The online Akka docs say this about sending a message with a ?: "The receiving
* actor should reply to this message, which will complete the future with the
@jamie-allen
jamie-allen / gist:2341725
Created April 9, 2012 05:44
Simple test of the pattern matching by Types in Scala
import scala.annotation.switch
/**
* Simple test of how quickly Scala can perform typed pattern
* matches, both of primitive types and complex object types.
*/
object PatternMatchTest extends App {
val numberOfOperations = 10000000
println("Performing baseline test...")
@jamie-allen
jamie-allen / gist:2565539
Created May 1, 2012 06:13
Large table/lookupswitch pattern match by hashed type
import scala.annotation.switch
/**
* Simple test of how quickly Scala can perform typed pattern matches, both of primitive types and complex object types.
*/
object PatternMatchRunner extends App {
val numberOfOperations = 10000000
name := "Akka ActorSystem Test"
version := "1.0"
scalaVersion := "2.9.1-1"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.1"
@jamie-allen
jamie-allen / gist:2631366
Created May 7, 2012 23:18
PatternMatchTest.scala
import scala.annotation.switch
/**
* Simple test of how quickly Scala can perform typed pattern matches, both of primitive types and complex object types.
*/
object PatternMatchRunner extends App {
@jamie-allen
jamie-allen / IoManagerBootstrap.scala
Created August 10, 2012 20:37
Simple example of how to use Akka IOManager Iteratee and exporting work to another actor
import akka.actor._
import akka.pattern.ask
import akka.util._
import akka.util.duration._
import scala.util.control.Exception._
/**
* To test, execute this code and use this command in a shell: "telnet localhost 8080"
* At the prompt, type in numbers and press enter, and they will be accumulated, returning
* the total value each time.
@jamie-allen
jamie-allen / gist:4067714
Created November 13, 2012 19:06
Console build.sbt
scalaVersion := "2.9.2"
name := "Console Playground"
scalacOptions ++= Seq("-unchecked", "-deprecation", "-optimize")
resolvers ++= Seq("akka-snapshots" at "http://repo.akka.io/snapshots",
"akka-releases" at "http://repo.akka.io/releases",
"Atmos Repo" at "http://repo.typesafe.com/typesafe/atmos-releases",
"Cloudera Repo" at "https://repository.cloudera.com/content/groups/public",