Install PGP plugin Reference
For sbt 0.13.5+: Add the following to your ~/.sbt/0.13/plugins/gpg.sbt file:
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
case class HttpRequest(path:String, queryStrings:Map[String,List[String]]) { | |
def getPath() : String Or String = if(path.length>0) Good(path) else Bad("path cannot be empty.") | |
def getQueryStrings() : ((List[String], Int), String) Or Every[String] = { | |
validateKeyword(queryString.get("keyword")) zip validateNumber(queryString.get("number")) zip validateGender(queryString.get("gender")) | |
} | |
def validateKeyword(value:Option[List[String]]) : List[String] Or One[String] = { | |
if(value.isDefined && value.get.length>0) Good(value.get) else Bad(One("No keyword.")) | |
} | |
def validateNumber(value:Option[List[String]]) : Int Or One[String] = { | |
try{ |
case class InvalidArgumentException(msg:String) extends Exception(msg) | |
case class SearchUsersRequest(keyword: Option[String], userType: Option[Int], maxNum: Option[Int], returnFields: List[String]) { | |
def getKeywork() = keyword | {throw InvalidArgumentException("keyword cannot be empyt.")} | |
def getUserType() = { | |
userType.map{ tp => (1 until 10 contains tp) ? tp | {throw InvalidArgumentException("userType must between 1 to 10.")}} |{ throw InvalidArgumentException("userType cannot be empyt.")} | |
} | |
def getMaxNum() = maxNum.getOrElse(10) | |
def getReturnFields() = (returnFields.length > 0) ? returnFields | {throw InvalidArgumentException("must provide returnFields.")} | |
} |
case class Error(code:Int, msg:String) | |
case class User(id:String,name:String) | |
object UserRepo{ | |
def find(id:String) : Option[User] = {None} | |
def getUser(id:String) : Either[Error,User] = { | |
find(id).map(Right(_)).getOrElse(Left(Error(404,s"User not found. id:[$id]"))) | |
} | |
} |
import com.joecwu.jcwutil.ObjFormatter._ | |
object TestApp { | |
def run = { | |
implicit def timeZone = TIMEZONE_UTC | |
println(System.currentTimeMillis().toStringRFC3339) | |
println(System.currentTimeMillis().toStringISO8601) | |
} | |
} |
case class GetArticleRequest(id:String,country:String,language:String) | |
def parseRequest(queryStr:String) = { | |
// parse arguments | |
val args = queryStr.split('&') map { str => | |
val pair = str.split('=') | |
(pair(0) -> pair(1)) | |
} toMap | |
// get 'id','country','language' and gen GetArticleRequest object | |
val resp = for{ |
case class TracerId(tid:String) | |
object TestApp { | |
implicit val tracerId = TracerId(java.util.UUID.randomUUID().toString) // tracerId can be defined and retrieved from HTTP request header. | |
def run(){ | |
methodA(1) | |
methodB | |
} | |
def methodA(i:Int)(implicit tracerId:TracerId) = { |
val list=List(1,2,3,4,5) | |
//list: List[Int] = List(1, 2, 3, 4, 5) |
import java.io._ | |
import java.util.zip._ | |
val pi = new PipedInputStream | |
val po = new PipedOutputStream(pi) | |
val zo = new GZIPOutputStream(po) | |
val zi = new GZIPInputStream(pi) | |
val w = new PrintWriter(zo) | |
val r = new BufferedReader(new InputStreamReader(zi)) |