Skip to content

Instantly share code, notes, and snippets.

@joecwu
joecwu / Blog-Docker-Push-Error.md
Created November 21, 2015 16:50
[Docker] Push Error
published tags
true
Docker

[Docker] Push Error

這篇同步發佈在我的BlogGist

背景

@joecwu
joecwu / Blog-ScaVaToScala-Scalaz-Task.md
Last active August 29, 2015 14:27
[ScaVa->Scala] Scalaz Task 取代Scala Future來進行非同步處理的另一個選擇
published tags
true
ScaVaToScala
Scala
Scalaz
Programming

[ScaVa->Scala] Scalaz Task 取代Scala Future來進行非同步處理的另一個選擇

這篇同步發佈在我的BlogGist

Scala的Future用起來有什麼問題?

在Scala中,我們要處理asynchronous computations的時候應該都知道有Future這個好用的東西,但Future monad常讓我在進行error handling的時候有點困擾,我本來的回傳值若是有"成功"或"失敗"兩種case的時候,我們可以用Scalaz的disjuction或是Scalactic的Or來處理,但是加上Future後的結果會變成:

@joecwu
joecwu / Blog-ScaVaToScala-Scalaz-Writer-Monad.md
Last active August 29, 2015 14:27
[ScaVa->Scala] Scalaz Writer Monad

Shortener Design Concept

Shortener

Shortener trait is an interface that defines core functions of shortener which is shorter & taller.

trait Shortener {
  def shorter(url:String)(implicit dbClient : DBClient, tracerInfo: TracerInfo) : String Or BaseException
  def taller(short:String)(implicit dbClient : DBClient, tracerInfo: TracerInfo) : String Or BaseException

}

@joecwu
joecwu / 0_reuse_code.js
Last active August 29, 2015 14:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
import java.io.{FileOutputStream, ByteArrayOutputStream, ByteArrayInputStream}
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import java.io._
object GzipHelper {
implicit def StringGzipConvertor(str:String) = new {
def toGzipBytes(charset:String="UTF-8") = compress(str,charset)
def toGzipBytesString(charset:String="UTF-8") = new String(compress(str,charset).map(_.toChar))
val a : Option[String] = Some("abc")
if(a.isEmpty)
println("do something if a has value "+a.get)
else
println("do something if a is empty")
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{

Publish Artifacts to Sonatype Nexus Repository by using SBT

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")

PGP Gen Key Reference

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.")}
}