Skip to content

Instantly share code, notes, and snippets.

View j5ik2o's full-sized avatar

Junichi Kato j5ik2o

View GitHub Profile
@kuzuha
kuzuha / gist:8106846
Created December 23, 2013 23:59
fact20 bench in scala/node/java
% scala/bench 100000000 factorial20 factorial20 factorial20
# factorial20
## 3.9219999999999997
# factorial20
## 3.295
# factorial20
## 3.3129999999999997
% node/bench 100000000 factorial20 factorial20 factorial20
# factorial20
@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経由で提供するところまでやる。

@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"
// カリー化された定義の利点その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 }
@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
@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) );
@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 {
@ogatatsu
ogatatsu / gist:1518754
Created December 25, 2011 05:10 — forked from j5ik2o/gist:1518723
こんな構文で階層型のログ出力をしたい
def connect = {
log("connect") { // connect start
// ... 何かの処理 ...
log("login") { // connect : login start
// ... 何かの処理 ...
} // connect : login end
// ... 何かの処理 ...
} // connect end
}
@makotan
makotan / gist:1476310
Created December 14, 2011 11:59
Either[L,Either[L,R]]のように多段になる場合にRだけを取得する
def eith[R](arg: Either[Throwable, Any] ) : R = {
arg match {
case Left(e) => throw e
case Right(o:Either[Throwable, Any]) => eith(o)
case Right(o:R) => o
}
}
@tyano
tyano / gist:1429205
Created December 4, 2011 04:48
List(1, 2, 3, 1) を Map(1 -> 2, 2 -> 1, 3 -> 1)
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 }}