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
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 = {
def someFunc(): Try[Int] = {
Try {
throw RuntimeException("Something bad happened!")
}
}
def callSomeFunc = {
val funcResult = someFunc()
funcResult match {
@Jacoby6000
Jacoby6000 / gist:3b24d8397491c0f92cb4
Last active August 29, 2015 14:16
Scala extension methods
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
}
}
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._
package TicTacToe
import TicTacToe.Player._
import spray.json._
/**
* Created by ferdy on 3/23/15.
*/
sealed trait Player
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 {
}
}
}
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
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")
@Jacoby6000
Jacoby6000 / scala.scala
Last active August 29, 2015 14:18
Unitype scala! woo!
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
}