This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main { | |
def main(args: Array[String]): Unit = { | |
new SixtyEightK() { | |
moveq(10, d0) | |
addl(200, d0) | |
println(d0) | |
// Outputs: DataRegister(210) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IntMatchActor extends Actor { | |
def receive = { | |
case 1 => self.reply("This is number 1.") | |
case 2 => self.reply("This is number 2, it comes after 1.") | |
case _ => self.reply("This value is neither 1 nor 2.") | |
} | |
} | |
val intMatchActor = actorOf[IntMatchActor].start | |
println(intMatchActor !! 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val firstLongProcessActor = actorOf[FirstLongProcessActor].start | |
val secondLongProcessActor = actorOf[SecondLongProcessActor].start | |
val startTime = currentTimeMillis | |
val firstFuture = firstLongProcessActor !!! 1000 | |
val secondFuture = secondLongProcessActor !!! 1000 | |
Futures.awaitAll(List(firstFuture, secondFuture)) | |
val timeTaken = currentTimeMillis - startTime | |
println("Process took " + timeTaken + "ms.") | |
// Output is: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val supervisor = Supervisor(SupervisorConfig( | |
AllForOneStrategy(List(classOf[IllegalStateException]), Some(3), Some(1000)), | |
Supervise(actorOf[BrokenActor], Permanent) :: Nil | |
)) | |
supervisor.start | |
val brokenActor = supervisor.children.head | |
printlnRequestResult(brokenActor, 1) | |
printlnRequestResult(brokenActor, 5) | |
try { | |
printlnRequestResult(brokenActor, 20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.atomic.AtomicInteger | |
import akka.actor._ | |
import akka.actor.Actor._ | |
import akka.dispatch.Future | |
case class Reduce(val size: Int) | |
case class MappingDetail[T](val item: T, val reducer: ActorRef) | |
class MapperActor[T, U](val mapping: (T) => U) extends Actor { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Vector" should { | |
"return a distance of 2 in a 1-dimensional difference" in { | |
val distance = new PositionVector(0, 0, 0).distance(new PositionVector(2, 0, 0)) | |
distance must equalTo(2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
import scala.xml._ | |
import scala.collection.mutable._ | |
val source = Source.fromURL("""http://query.yahooapis.com/v1/public/yql?q=select%20commit.author.name,%20commit.id%20from%20github.repo.commits%20where%20id='jboner'%20and%20repo='akka'&diagnostics=true&env=store://datatables.org/alltableswithkeys""") | |
val sourceXML = XML.loadString(source.mkString) | |
val commits = sourceXML \ "results" \ "commits" \ "commit" | |
val authorsToCommits: MultiMap[String, String] = commits.foldLeft(new HashMap[String, Set[String]] with MultiMap[String, String]){(multiMap,commit) => | |
multiMap.addBinding((commit \ "author" \ "name").text, (commit \ "id").text) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> (connection.get("TEST").liftFailNel |@| connection.get("TEST2").liftFailNel){(test, test2) => List(test,test2)} | |
res5: scalaz.Validation[scalaz.NonEmptyList[String],List[Option[String]]] = Success(List(Some(5), Some(6))) | |
scala> connection.close() | |
scala> (connection.get("TEST").liftFailNel |@| connection.get("TEST2").liftFailNel){(test, test2) => List(test,test2)} | |
res7: scalaz.Validation[scalaz.NonEmptyList[String],List[Option[String]]] = Failure(NonEmptyList(Socket closed, Socket closed)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.camel.Processor | |
import org.apache.camel.Exchange | |
import org.apache.camel.builder.RouteBuilder | |
import org.apache.camel.impl.DefaultCamelContext | |
import org.apache.commons.io.FileUtils | |
import java.net.URL | |
@Grab(group="org.apache.camel",module="camel-jetty",version="2.5.0") | |
@Grab(group="commons-io", module="commons-io",version="2.0") | |
class WebRouteBuilder extends RouteBuilder { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val counter = new java.util.concurrent.atomic.AtomicInteger(0) | |
def printTwiceExpression(expression: => Int) = { | |
println(expression) | |
println(expression) | |
} | |
def printTwiceValue(value: Int) = { | |
println(value) | |
println(value) | |
} |