Skip to content

Instantly share code, notes, and snippets.

Junichi Kato j5ik2o

Block or report user

Report or block j5ik2o

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 20140907_scaling-scala.md
View functor.scala
import scalaz._, Scalaz._
sealed trait MyOption[+A]
case class MySome[A](value: A) extends MyOption[A]
case object MyNone extends MyOption[Nothing]
object MyOption {
implicit object MyOptionFunctor extends Functor[MyOption] {
@j5ik2o
j5ik2o / not_tailrec.scala
Created Jun 26, 2012 — forked from xuwei-k/not_tailrec.scala
リトライハンドラーの殴り書き
View not_tailrec.scala
object RetryUtil {
case class RetryException(throwables: List[Throwable]) extends Exception
def retry[T](retryLimit: Int, retryInterval: Int, shouldCatch: Throwable => Boolean)(f: => T): T = {
// @annotation.tailrec
def _retry( errors: List[Throwable], f: => T):T = {
try {
f
} catch {
@j5ik2o
j5ik2o / rest.scala
Created Feb 24, 2012 — forked from stonegao/rest.scala
Basic RESTful service with Finagle
View rest.scala
class Respond extends Service[Request, Response] with Logger {
def apply(request: Request) = {
try {
request.method -> Path(request.path) match {
case GET -> Root / "todos" => Future.value {
val data = Todos.allAsJson
debug("data: %s" format data)
Responses.json(data, acceptsGzip(request))
}
case GET -> Root / "todos" / id => Future.value {
@j5ik2o
j5ik2o / gist:1476354
Created Dec 14, 2011 — forked from makotan/gist:1476310
Either[L,Either[L,R]]のように多段になる場合にRだけを取得する
View gist:1476354
object Loan {
def using[A <: { def close() }, B](resource: A)(func: A => B): Either[Exception, B] =
try {
Right(func(resource))
} catch {
case e: Exception => Left(e)
} finally {
if (resource != null) resource.close()
}
@j5ik2o
j5ik2o / gist:1429210
Created Dec 4, 2011 — forked from tyano/gist:1429205
List(1, 2, 3, 1) を Map(1 -> 2, 2 -> 1, 3 -> 1)
View gist:1429210
List(1,2,3,1).zip(List(1,1,1,1)).foldLeft(Map[Int,Int]()) { (x, y) => x.get(y._1) match { case Some(v) => x + Pair(y._1, (v + y._2)) case None => x + y }}
You can’t perform that action at this time.