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
def jsonReader(className: TypeName, fields: List[ValDef]) = { | |
fields.length match { | |
case 0 => c.abort(c.enclosingPosition, "Cannot create json formatter for case class with no fields") | |
case _ => | |
// use the serializer for the field | |
val readers = getReaders(fields) | |
q""" | |
implicit object reader extends BSONDocumentReader[$className] { | |
import reactivemongo.bson._ | |
def read(bson: BSONDocument): $className = { |
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 someFunc(): Try[Int] = { | |
Try { | |
throw RuntimeException("Something bad happened!") | |
} | |
} | |
def callSomeFunc = { | |
val funcResult = someFunc() | |
funcResult match { |
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 Implicits { | |
implicit class PimpedString(str: String) { | |
def everyNthChar(skipNum: Int) = (for (i <- 0 until str.length if i%skipNum==0) yield str(i)).mkString | |
//Other methods I want strings to have go here | |
} | |
implicit class PimpedInt(int: Int){ | |
//Other methods I want ints to have do here | |
} | |
} |
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
trait Queryable { | |
def id: Rep[Long] | |
} | |
trait BaseDao[T <: Queryable] { | |
// Import the query language features from the driver | |
val driver: JdbcProfile | |
val table: TableQuery[T] | |
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
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
protected def createDbRecords(record: Distributor)(implicit session: JdbcBackend.SessionDef): Either[ValidationError, Distributor] = { | |
record.id.map(id => Left(ValidationError("An id must not be specified when creating a signup request."))).getOrElse { | |
record.address.id.map(id => Left(ValidationError("An address id must not be specified when creating a signup request."))).getOrElse { | |
} | |
} | |
} |
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 QuerySettings(pageSize: Option[Int] = Some(25), pageNumber: Option[Long] = Some(0), sortBy: Option[String] = None, direction: Option[String] = None, allParams: Map[String, String]) { | |
sealed trait Direction | |
sealed object Asc extends Direction | |
sealed object Desc extends Direction | |
sealed object Invalid extends Direction | |
sealed trait Operator | |
sealed object Equal extends Operator | |
sealed object LessThan extends Operator | |
sealed object LessThanOrEqual extends Operator |
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
case class Address(id:Option[Long], | |
street1: String, | |
street2: Option[String] = None, | |
city: String, | |
state: String, | |
zipCode: String) extends DBObject | |
class Addresses(tag: Tag) extends IndexedTable[Address](tag, "addresses") { | |
def street1 = column[String]("street1") | |
def street2 = column[Option[String]]("street2") |
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 Unitype { | |
implicit def objectToBool(obj: AnyRef): Boolean = obj != null | |
implicit def noneToBool(none: Option[Nothing]): Boolean = false | |
implicit def optToBool[T](opt: Option[T]): Boolean = opt.isDefined | |
trait Unityper[To, From] { | |
def convert: To | |
} |
OlderNewer