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
| /* Start by creating a reader for some fake yet conceivable type for executing SQL queries. */ | |
| val dbReader: Reader[Properties, JdbcExecutor] = | |
| for { | |
| driver <- read[String]("db.driver") | |
| uri <- read[String]("db.uri") | |
| user <- read[String]("db.username") | |
| password <- read[String]("db.password") | |
| name <- read[String]("db.pool.name") | |
| minCons <- read[Int]("db.pool.minConnections") |
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
| using System; | |
| namespace Config { | |
| sealed public class Configuration { | |
| public readonly string hostname; | |
| public readonly int port; | |
| public readonly string outfile; | |
| public Configuration(string hostname, int port, string outfile) { |
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
| By Jeff Dean (http://research.google.com/people/jeff/): | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns | |
| Compress 1K bytes with Zippy 3,000 ns | |
| Send 2K bytes over 1 Gbps network 20,000 ns | |
| Read 1 MB sequentially from memory 250,000 ns |
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
| .. | |
| @:``#, | |
| #`````+ | |
| ,@+@``````@+@ | |
| #````````````@ | |
| `````````````@ | |
| #````````````@ | |
| .@+;+++++++@@ |
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
| .. | |
| @:``#, | |
| #`````+ | |
| ,@+@``````@+@ | |
| #````````````@ | |
| `````````````@ | |
| #````````````@ | |
| .@+;+++++++@@ | |
| @,'` |
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
| lazy val yodawg = TaskKey[String]("yo-dawg", "I heard you liked settings, so I put a setting in your setting") | |
| yodawg <<= Project.app(moduleName :^: version :^: isSnapshot :^: KNil){ | |
| case a :+: b :+: c :+: HNil => task(List(a, b, c).mkString("~")) | |
| } | |
| >show yo-dawg | |
| [info] web~2.0-SNAPSHOT~true | |
| // source: https://github.com/harrah/xsbt/blob/0.11/main/Structure.scala#L443 |
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
| trait Cake { | |
| type Config | |
| def config: Config | |
| } | |
| trait FooConfig { | |
| // ... | |
| } | |
| trait FooComponent extends Cake { |
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
| // these are the data types | |
| trait Tense | |
| case object Past extends Tense | |
| case object Present extends Tense | |
| case object Future extends Tense | |
| trait Subject { | |
| protected val usage: Map[Tense, String] | |
| def apply(tense: Tense): String = usage(tense) | |
| } |
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> mongo("projects").group( | |
| | MongoDBObject(), // condition | |
| | MongoDBObject(), // key | |
| | MongoDBObject("count" -> 0, "contributors" -> 0), //initial | |
| | "function(doc, out){ out.count++; out.contributors+=doc.contributorCount;}" //, | |
| | //"function(out){ out.average = out.contributors / out.count; }" | |
| | ) | |
| res2: scala.collection.mutable.Iterable[com.mongodb.DBObject] = ArrayBuffer({ "count" : 3.0 , "contributors" : 59.0}) | |
| scala> mongo("projects").group( |
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
| class Aggregator(recipients: Iterable[ActorRef]) extends Actor{ | |
| def receive = { | |
| case msg @ Message(text) => | |
| println("Started processing message `%s`" format(text)) | |
| val result = Promise[String]() | |
| val promises = List.fill(recipients.size)(Promise[String]()) | |
| recipients.zip(promises).map{case (recipient, promise) => |