Skip to content

Instantly share code, notes, and snippets.

View masahitojp's full-sized avatar
🎯
Focusing

Masato Nakamura masahitojp

🎯
Focusing
View GitHub Profile
package controllers
import play.api._
import play.api.mvc._
import play.api.http._
import play.api.libs.iteratee._
import play.api.libs.iteratee.Input._
import net.liftweb.json.{ JValue => LiftJValue, _ }
@tototoshi
tototoshi / finagle_http_hello.scala
Created May 19, 2012 04:11
finagle-http で Hello, world.
package com.github.tototoshi.finagle_hack
import java.net.InetSocketAddress
import com.twitter.finagle.{Service, SimpleFilter}
import com.twitter.util.Future
import com.twitter.finagle.builder.{Server, ServerBuilder}
import com.twitter.finagle.http._
import com.twitter.finagle.http.path._
object HTTPServer {
@rirakkumya
rirakkumya / gist:2724922
Created May 18, 2012 12:06
List[Either[Throwable,_]]のリスト中にLeftが1個以上あったら最初のLeftを返し、Leftが1個もなければ、Rightを1個のリストにまとめて返すコード
def f[a] = (d:List[Either[Throwable,a]]) =>
d.collect{case Left(x) => x}.headOption.toLeft(d.map{case Right(x) => x})
scala> Some(List(Right("4"),Right("3"))) map f
res11: Option[Product with Either[Throwable,List[java.lang.String]] with Serializable] = Some(Right(List(4, 3)))
scala> Some(List(Right("4"),Left(new RuntimeException),Right("3"))) map f
res12: Option[Product with Either[Throwable,List[java.lang.String]] with Serializable] = Some(Left(java.lang.RuntimeException))
scala> Some(List(Right("4"),Left(new RuntimeException("a")),Right("3"),Left(new RuntimeException("b")))) map f
@sadache
sadache / Application.scala
Created May 17, 2012 08:26
Play2: Stream results of parallel jobs as comet to the client
package controllers
import play.api._
import play.api.mvc._
object Application extends Controller {
def index = Action {
@teramako
teramako / thunderbird_dropbox.md
Created April 21, 2012 17:17
Thunderbirdに這いよるDropbox

Thunderbird (Daily) のエラーコンソールに貼り付けよう

Components.utils.import("resource://gre/modules/Services.jsm").Services.wm.getMostRecentWindow("mail:3pane").openDialog("chrome://messenger/content/cloudfile/addAccountDialog.xul","", "chrome, dialog, modal, resizable=yes",{accountKey:null})

@seratch
seratch / build.sbt
Created March 8, 2012 03:06
Using Anorm 2.0 without Play Framework
scalaVersion := "2.9.1"
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases"
libraryDependencies ++= Seq(
"play" %% "anorm" % "2.0-RC4",
"com.github.seratch" %% "scalikejdbc" % "[0.5,)",
"org.hsqldb" % "hsqldb" % "[2,)"
)
@bellbind
bellbind / ecc.py
Created December 1, 2011 08:08
[python]basics of elliptic curve cryptography
# Basics of Elliptic Curve Cryptography implementation on Python
import collections
def inv(n, q):
"""div on PN modulo a/b mod q as a * inv(b, q) mod q
>>> assert n * inv(n, q) % q == 1
"""
for i in range(q):
if (n * i) % q == 1:
@komamitsu
komamitsu / myecho.ml
Created November 13, 2011 14:14
a Lwt echo server for practice
(* ocamlfind c -w A -linkpkg -package lwt,lwt.unix,lwt.syntax -syntax camlp4o,lwt.syntax myecho.ml -o myecho *)
(* This code refers to https://github.com/avsm/ocaml-cohttpserver/blob/master/server/http_tcp_server.ml *)
open Lwt
let server_port = 12345
let so_timeout = Some 20
let backlog = 10
let try_close chan =
catch (fun () -> Lwt_io.close chan)
@kmizu
kmizu / Generator.scala
Created September 24, 2011 08:27
Yet another "generator" library implementation in Scala.
//To compile this, "-P:continuations:enable" option is needed.
import scala.util.continuations._
import scala.collection._
object Generator {
abstract sealed class Computation[+A]
case class Yielded[A](k: Unit => Computation[A], v: A) extends Computation[A]
case object Done extends Computation[Nothing]
type yieldable[A] = cps[Computation[A]]
@xuwei-k
xuwei-k / あんふぃるたー丼.md
Created September 16, 2011 04:40
build.sbt を DRY に書く方法

build.sbt って、かならず settingの値 じゃないといけないから、

val UnfilteredVersion = "0.5.0"

っていう行を定義できないけれど、こんな風 ↓ に書けば DRY に書けるね!っていう、超細かいどーでもいいテクニック !

Some("net.databinder","0.5.0").map{case (a,v) =>