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
implicit val userWrites: Writes[User] = ( | |
(__ \ "lastVisit").write[Timestamp] and | |
(__ \ "handle").write[String] and | |
(__ \ "firstName").write[String] and | |
(__ \ "lastName").write[String] and | |
(__ \ "email").write[String] and | |
(__ \ "rating").write[Int] and | |
(__ \ "location").write[String] and | |
(__ \ "shirtSize").write[String] and | |
(__ \ "id").writeNullable[Long] and |
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
package TicTacToe | |
import TicTacToe.Player._ | |
import spray.json._ | |
/** | |
* Created by ferdy on 3/23/15. | |
*/ | |
sealed trait Player |
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
package models.dao | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
import play.api.Play.current | |
import play.modules.reactivemongo.ReactiveMongoPlugin | |
import reactivemongo.api.collections.default.BSONCollection | |
import reactivemongo.bson.BSONDocument | |
import reactivemongo.bson.BSONDocumentIdentity |
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
def collectSubAar(ps: Seq[ProjectRef]): Seq[AarLibrary] = ps flatMap { p => | |
val locals = Project.runTask(libraryProjects in(p, Android), st).collect { | |
case (_, Value(value)) => value | |
} | |
val aarlibs = locals.fold(Seq.empty[AarLibrary])(_ collect { | |
case a: AarLibrary => a | |
}) | |
val sub = Project.getProject(p, struct) | |
if(sub.isEmpty) aarlibs |
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.util.Try | |
case class Contains(test: String) | |
object ContainsA { | |
def unapply(obj: Contains): Option[String] = Some(obj.test) | |
} | |
object ContainsB { | |
def unapply(obj: Contains): Option[Int] = Try(obj.test.toInt).toOption | |
} | |
val container = Contains("foo") |
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 play.api.db.slick.HasDatabaseConfig | |
import slick.driver.JdbcProfile | |
import slick.lifted.AbstractTable | |
case class Coffee (name: String, id: Option[Int]) | |
abstract class CoffeeDao extends Dao { | |
import driver.api._ |
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
sealed trait Response | |
case class Question(...) extends Response | |
case class Respond(...) extends Response | |
case class Batch(...) extends Response | |
def apply(input: String): JsonElement = { | |
input.decodeOption[Response] match { | |
case Some(q: Question) => { | |
??? | |
} |
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
def parallelPaper(lines: List[String]): Future[Int] = { | |
val computingCounts: List[Future[Int]] = lines.map(line => parallelCompute(line)) | |
val futureComputedCounts: Future[List[Int]] = Future.sequence(computingLines) | |
val resultFuture: Future[Int] = | |
futureComputedCounts.map { counts => | |
val accumulatorInitialValue = 0 | |
counts.foldLeft(accumulatorInitialValue)((accumulator, nextCount) => accumulator + nextCount) | |
} | |
resultFuture |
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
//reads input string, checks if its json, and if it is returns an encoded object of the first type that parses correctly. | |
def read[A](input: String)(implicit decoder: DecodeJson[A]): Option[A] = { // require that the decodeJson for type A be in scope | |
JsonParser.parse(input).toOption match { | |
case None => { | |
throw new AlgorithmException(s"input failed to parse.") | |
} | |
case Some(json: Json) => { | |
val decoded = decoder.decodeJson(json).toOption | |
decoded | |
} |
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
def apply(input: String): String = { | |
val output = | |
Utils.read[SealedTraitParent](input) match { | |
case Some(predict: Predict) => | |
println(predict) | |
predict.process(client) | |
case Some(train: Training) => | |
println(train) | |
train.process(client) | |
case None => |
OlderNewer