Skip to content

Instantly share code, notes, and snippets.

View Jacoby6000's full-sized avatar

Jacob Barber Jacoby6000

  • Plano, TX
View GitHub Profile
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
package TicTacToe
import TicTacToe.Player._
import spray.json._
/**
* Created by ferdy on 3/23/15.
*/
sealed trait Player
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
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
@Jacoby6000
Jacoby6000 / ListContainsExtractor.scala
Last active October 9, 2015 19:00 — forked from sam/ListContainsExtractor.scala
Trying to come up with an Extractor I can pass input to other than my match object.
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")
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._
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) => {
???
}
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
//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
}
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 =>