This file contains hidden or 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
// The variable data could easily be an Iterator from scala.io.Source instance, it will work just the same. | |
val data = List("Food,Count","Cake,9","Biscuits,2","Cookie,10") | |
val Parser = """([^,]+),(\d+)""".r | |
val entries = data.collect{case Parser(food,count) => (food, count.toInt)} |
This file contains hidden or 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
case class Button() | |
case class AlertDialog( | |
title: String = "", | |
message: String = "", | |
positiveButton: Option[Button] = None | |
) | |
def builder = new AlertDialog(title = "Epic Builder") |
This file contains hidden or 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
sealed abstract class CommandLineItem(name: String, description: String) | |
case class CommandLineArgument(name: String, description: String) extends CommandLineItem(name, description) | |
case class CommandLineOption(name: String, description: String, optionName: String) extends CommandLineItem(name, description) | |
case class PassedInItems(options: Map[String, String] = Map(), arguments: List[String] = List(), hangingOptionName: Option[String] = None) | |
case class CommandLineOptions(commandLineOptions: Seq[CommandLineOption], commandLineArguments: Seq[CommandLineArgument]) { | |
def parse(args: Array[String]): Either[PassedInItems, String] = { | |
args.foldLeft(Left(PassedInItems()).asInstanceOf[Either[PassedInItems, String]]){(workingResult, arg) => workingResult match { | |
case Left(PassedInItems(options, arguments, hangingOptionName)) => { |
This file contains hidden or 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 Server { | |
def main(args: Array[String]): Unit = { | |
val serviceName = "appserver" | |
val managerPortOption = new CommandLineOption("Manager Port", "Manager Port", "managerPort") | |
val serverPortOption = new CommandLineOption("Server Port", "Server Port", "serverPort") | |
val options = List(managerPortOption, serverPortOption) | |
val arguments = List(new CommandLineArgument("Command", "Command")) | |
def success(options: Map[String, String], arguments: Seq[String]): Unit = { | |
val serverPort = options(serverPortOption.optionName).toInt | |
val managerPort = options(managerPortOption.optionName).toInt |
This file contains hidden or 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
05/10 17:01:35 INFO [main] a.s.AkkaLoader - ================================================== | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t t t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t t tt t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - tt t t tt t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t ttttttt t ttt t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t tt ttt t ttt t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t t ttt t ttt t t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - tt t ttt ttt ttt t | |
05/10 17:01:35 INFO [main] a.s.AkkaLoader - t t ttt ttt t tt t |
This file contains hidden or 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.builder.RouteBuilder | |
import org.apache.camel.impl.DefaultCamelContext | |
@Grab(group="org.apache.camel",module="camel-jetty",version="2.7.0") | |
@Grab(group="org.slf4j",module="slf4j-nop",version="1.6.1") | |
class WebRouteBuilder extends RouteBuilder { | |
void configure() { | |
from("jetty:http://0.0.0.0/cake") | |
.inOut() | |
.setBody(constant("<html><title>Cake</title><body>Chocolate Cake Is The Best</body></html>")) |
This file contains hidden or 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
Server Software: Gigantor! | |
Server Hostname: 127.0.0.1 | |
Server Port: 8080 | |
Document Path: /dave | |
Document Length: 44 bytes | |
Concurrency Level: 200 | |
Time taken for tests: 5318.533 seconds | |
Complete requests: 10000000 |
This file contains hidden or 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> import scala.util.control._ | |
import scala.util.control._ | |
scala> Exception.catching(classOf[Throwable]).either{"1".toInt} | |
res2: Either[Throwable,Int] = Right(1) | |
scala> Exception.catching(classOf[Throwable]).either{"dave".toInt} | |
res3: Either[Throwable,Int] = Left(java.lang.NumberFormatException: For input string: "dave") |
This file contains hidden or 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.scalacheck.Prop | |
import org.scalacheck.Prop.Params | |
import java.util.concurrent.atomic.AtomicBoolean | |
class TimedProp(maximumMs: Int, wrappedProp: => Prop) extends Prop { | |
def apply(prms: Params) = { | |
val atLeastOnce = new AtomicBoolean(true) | |
val startTime = System.currentTimeMillis() | |
val resultStream = Stream.continually{ | |
Thread.sleep(20) |
This file contains hidden or 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 akka.actor._ | |
import akka.actor.Actor._ | |
case class StartPayment(provider: String) | |
case class CompletePayment(provider: String) | |
case class PaymentProcess(userId: Int) extends Actor { | |
var currentProvider: String = _ | |
def receive = { | |
case StartPayment(provider) => { |