Skip to content

Instantly share code, notes, and snippets.

import net.liftweb.mongodb.record.field.ObjectIdField
import net.liftweb.mongodb.record.{MongoMetaRecord, MongoRecord}
import net.liftweb.record.field.IntField
// ==== BASE
trait BaseDoc[T <: BaseDoc[T]] extends MongoRecord[T] {
self: T =>
import com.foursquare.rogue.LiftRogue._
import net.liftweb.mongodb.record.{MongoRecord, MongoMetaRecord}
// ==== BASE
trait BaseDoc[T <: MongoRecord[T]]
extends MongoRecord[T] {
self: T =>
import sbt._
import Keys._
object HelloBuild extends Build {
lazy val root = Project(id = "hello",
base = file("."),
settings = Project.defaultSettings ++ Seq(compileInputs in doc in Compile ~= (x => x.copy(config = x.config.copy(sources = List())))))
}
import play.api.libs.json.Json
case class MyClass(id: Int, text: String)
object MyClass {
implicit val mailRead = Json.reads[MyClass]
def apply(id: Int) =
apply(id, "")
// Library
// =================================================
trait ConfigComp {
trait Config {
def get(k: String): String
}
def config: Config
}
// counts number of vars in Tree
def countVars(implicit codeTree: List[Tree]): (String, Int) =
("noOfVars", codeTree.collect {
case e: ValDef if (e.mods.hasFlag(MUTABLE)) => true
}.size)
// overwrites field of Task trait
def metaField(name: String, value: Int) =
ValDef(Modifiers(OVERRIDE), newTermName("_" + name), TypeTree(), Literal(Constant(value)))
trait Testable {
var _tasks = mutable.Map[Int, Task]()
def registerTask(num: Int, t: Task) {
_tasks(num) = t
}
def task(num: Int)(code: Any): Any =
macro TaskMacro.task
class Task {
val _raw = ""
val _source = ""
val _noOfIfs = 0
val _noOfVars = 0
val _noOfVals = 0
val _noOfDefs = 0
val _noOfTrys = 0
task(2) {
def isWorkingDay(day: String) = {
var res: Boolean = false
day match {
case "Monday" =>
res = true
case "Tuesday" =>
res = true
case "Wednesday" =>
project.categories.query(c => c.ancestors.where(_.id === rootId))