Skip to content

Instantly share code, notes, and snippets.

View yangbajing's full-sized avatar

Yang Jing yangbajing

View GitHub Profile
@notyy
notyy / gist:2022552
Created March 12, 2012 15:13
logger with value
def myFunc() = {
val rs = calcSomeResult()
logger.info("result is:" + rs)
rs
}
为避免上面的麻烦写法:
object LogUtil {
def kestrel[A](x: A)(f: A => Unit): A = { f(x); x }
def logV[A](f: String => Unit)(s: String, x: A) = kestrel(x) { y => f(s + ": " + y) }
@doitian
doitian / MongoJson.scala
Created May 10, 2013 15:12
Convert play2.0 JsValue to mongodb DBObject provided by casbah
package module.db;
import com.mongodb.casbah.Imports._
import java.text.DateFormat
import java.util.Date
import play.api.data.validation.ValidationError
import play.api.libs.json._
object MongoJson {
def fromJson(json: JsValue) : JsResult[DBObject] = readDBObject.reads(json)
@Centaur
Centaur / fromScalaConsole.scala
Last active August 29, 2015 13:59
extract pair as expected type
trait CanFromString[T] {
def fromString(s: String): T
}
implicit object intCanFromString extends CanFromString[Int] {
override def fromString(s: String): Int = s.toInt
}
implicit object SymbolCanFromString extends CanFromString[Symbol] {
override def fromString(s: String): Symbol = Symbol(s)
}