Skip to content

Instantly share code, notes, and snippets.

View j5ik2o's full-sized avatar

Junichi Kato j5ik2o

View GitHub Profile
@j5ik2o
j5ik2o / rest.scala
Created February 24, 2012 15:54 — forked from stonegao/rest.scala
Basic RESTful service with Finagle
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 {
def index(id:String) = Action {
getFirstData(id)
}
private def getFirstData(id:String) = {
Cache.get(id) match {
case Some(id2) => getSecondData(id2)
case None => NotFound
}
}
private def getSecondData(id2:String) = {
@yamashiro
yamashiro / gist:2724450
Created May 18, 2012 10:13
これなんでコンパイルエラーになるの?
class Hoge() {}; var hoge = List(new Hoge()); hoge foldLeft(Map[String, Hoge]()) ( (map:Map[String,Hoge], hoge:Hoge) => map + ("hoge" -> hoge) );
@stonegao
stonegao / HttpServer.scala
Created June 14, 2012 02:53 — forked from soheilhy/HttpServer.scala
Routing based on HTTP method in Finagle
import com.twitter.finagle.http.path._
import com.twitter.finagle.http.service.RoutingService
import com.twitter.finagle.http.{Request, Response, RichHttp, Http}
import com.twitter.finagle.{Service, SimpleFilter}
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer
import org.jboss.netty.util.CharsetUtil.UTF_8
import com.twitter.util.Future
@xuwei-k
xuwei-k / not_tailrec.scala
Created June 26, 2012 16:32 — forked from j5ik2o/gist:2996293
リトライハンドラーの殴り書き
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 {
// カリー化された定義の利点その1
// 擬似的な制御構文を作るのに使える
//
// 以下の関数maybeは、maybe(条件){ 式 } のような使い方ができる。
// 条件が真なら、式の実行結果をSomeに包んでSome[A]を返し、
// 偽ならばNoneを返す
scala> def maybe[A](cond: => Boolean)(f: => A):Option[A] = if(cond) Some(f) else None
maybe: [A](cond: => Boolean)(f: => A)Option[A]
scala> maybe(true){ util.Random.nextPrintableChar }
@hayajo
hayajo / changelog_en.md
Last active May 3, 2024 08:29
ChangeLog を支える英語

ChangeLog を支える英語

ChangeLog を書く際によく使われる英語をまとめました。

ほとんど引用です。

基本形

@seizans
seizans / persistent.md
Created December 10, 2012 15:21
Haskellで便利にデータ設計

Haskellで便利にデータ設計

概要

これは [Haskell Advent Calendar 2012][] の11日目の記事です。
Haskell でデータ設計を便利に行う発想・方法について書きました。
[persistent][] というライブラリを活用します。
Haskell を知らなくても読めます。
主な対象読者は [プログラミングHaskell][] か [すごいHaskellたのしく学ぼう!][] を読み、Haskell をより使いたい人です。

@jacksoncage
jacksoncage / post-recive hook in Atlassian Stash
Created May 10, 2013 20:30
Create post-recive hook in Atlassian Stash that notifys Jenkins on push
#!/bin/bash
# Create git hook on stash server
# Exit script on error
set -e
# Define the function that renders super awesome header
renderHeader () {
HEADER=$1
printf "\n\n"
@mumoshu
mumoshu / play2-ganglia-howto.md
Last active December 19, 2015 07:19
Play framework 2.1.0で開発したアプリのメトリクスをGangliaでモニタリングする

Idea

            メトリクス                           Web API(JSON)                                    メトリクス
Play2アプリ ----------> guardian-management-play ------------> Rubyスクリプト --> gmetricコマンド ----------> Webサーバ内のgmond --------> 集約先のgmond/gmetad
  • guardian-management-playはPlay2のフィルタを使ってメトリクスを計測し、管理Web経由で計測データをJSONファイルとして公開する

Play2アプリ側の作業

Play2アプリでMetricsを計測して、それをJSONファイルとしてWeb API経由で提供するところまでやる。