Skip to content

Instantly share code, notes, and snippets.

View masahitojp's full-sized avatar
🎯
Focusing

Masato Nakamura masahitojp

🎯
Focusing
View GitHub Profile
@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})

@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 {
@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
@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 {
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, _ }
@taichi
taichi / log.md
Last active December 15, 2021 02:12
ログ、その時の為に。
@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 {
@udzura
udzura / fgcs.git.sh
Last active October 7, 2015 10:17
Fxcking git cheet sheet
# stage の操作
git add . # stage に加える
git add -p # stage にインタラクティブに加える
git add -N . # stage にファイルだけ加える
git rm hoge/hoge.rb # stage から消す
git rm -f hoge/hoge.rb # stage から無理矢理消す、先にファイルを消してしまった場合
git mv hoge/hoge.rb hoge/hoge2.rb # ファイル名変える
# 差とか状態を確認する系
git diff # HEADとunstagedの差分を確認する
@almost
almost / glacier.py
Created August 21, 2012 17:59
Amazon Glacier from Python. There's now a branch for this, see here: https://github.com/almost/boto/tree/glacier
# Thomas Parslow http://almostobsolete.net
# Just a work in progress and adapted to what I need right now.
# It does uploads (via a file-like object that you write to) and
# I've started on downloads. Needs the development version of Boto from Github.
#
# Example:
#
# glacierconn = GlacierConnection(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY)
# writer = GlacierWriter(glacierconn, GLACIER_VAULT)
# writer.write(somedata)
@kmizu
kmizu / UseEither.scala
Created September 6, 2012 12:04
Avoid nested pattern match with Either
object UseEither {
def doSomething(arg: String): Either[Throwable, Option[String]] = arg match {
case "none" => Right(None)
case "some" => Right(Some("some"))
case _ => Left(new Exception("example exception"))
}
def main(args: Array[String]) {
val somethingEither = for {
s <- doSomething(args(0)).right