Skip to content

Instantly share code, notes, and snippets.

View Jacoby6000's full-sized avatar

Jacob Barber Jacoby6000

  • Plano, TX
View GitHub Profile
case class Foo(value: Int)
def somethingThatDependsOnFoo(someInt: Int): Foo => Int = (foo: Foo) => someInt*foo.value
val myFooFunction: Foo => Int = somethingThatDependsOnFoo(5)
val myFooFunctionResult: Int = myFooFunction(Foo(5))
implicit class SqlIdeFixer(val sc: StringContext) {
def sqlIde[A: Composite](args: A): SqlInterpolator#Builder[A] = {
val interpolator = doobie.syntax.string.SqlInterpolator(sc)
new interpolator.Builder(args)
}
}
object string {
object SqlInterpolator {
class Builder[A: Composite](a: A, stackFrame: Option[StackTraceElement], rawSql: String) {
def query[O: Composite]: Query0[O] = Query[A, O](rawSql, stackFrame).toQuery0(a)
def update: Update0 = Update[A](rawSql, stackFrame).toUpdate0(a)
}
}
class UserDao(implicit comp: Composite[User]) extends BaseDao[User]{
val tableName = "users"
val columnNames: List[String] = "id" :: "email_address" :: "created_on" :: "modified_on" :: "deleted_on" :: Nil
def insert(document: User): Task[User] =
sql"""
insert into $tableName (
id,
email_address,
[info] Compiling 17 Scala sources to /media/sf_windows/Users/Jacob/Projects/virtual-receptionist-server/target/scala-2.11/classes...
[error] /media/sf_windows/Users/Jacob/Projects/virtual-receptionist-server/src/main/scala/com/jbarber/receptionist/web/RootWebService.scala:20: type mismatch;
[error] found : Object
[error] required: scalaz.concurrent.Task[org.http4s.Response]
[error] .flatMap(_.getOrElse(BadRequest("Failure for some reason. i dunno.") : Task[Response]))
val visitorWebService = VisitorWebService()
val userWebService = UserWebService()
val service =
"visitors" / visitorWebService ~
"users" / userWebService
implicit class stringExtensions(str: String) {
def /(service: HttpService): HttpService = {
val root = if(str.startsWith("/")) str else "/" + str
URITranslation.translateRoot(root)(service)
}
}
implicit class SymbolExtensions(sym: Symbol) {
def /(service: HttpService): HttpService = {
sym.name / service
case class MessageArray(list: List[MessageFields])
case class MessageFields(fields: Message)
case class MessageObject(message: Message)
case class Message(value: String);
import spray.json._
import DefaultJsonProtocol._
implicit val messageFormats = jsonFormat1(Message.apply)
implicit val messageObjectFormats = jsonFormat1(MessageObject.apply)
class FooClass[T <: Entity](...) {
...
// Should these 3 methods be on a typeclass? They only exist because we can't call the .copy method on a generic type.
def addCreatedDateToDocument(document: T, date: DateTime): T
def addModifiedDateToDocument(document: T, date: DateTime): T
def addIdToDocument(document: T, id: String): T
}
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