Skip to content

Instantly share code, notes, and snippets.

View seratch's full-sized avatar

Kazuhiro Sera seratch

View GitHub Profile
@seratch
seratch / README.md
Created August 23, 2012 10:56
Working with Scala 2.10.0-M7
$ echo 'scalaVersion := "2.10.0-M7"' > build.sbt
$ sbt console
[info] Set current project to default-e9c0f6 (in build file:/Users/seratch/tmp/scala_2.10/)
Getting Scala 2.10.0-M7 ...
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.10.0-M7/scala-compiler-2.10.0-M7.jar ...
	[SUCCESSFUL ] org.scala-lang#scala-compiler;2.10.0-M7!scala-compiler.jar (2113ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.0-M7/scala-library-2.10.0-M7.jar ...
	[SUCCESSFUL ] org.scala-lang#scala-library;2.10.0-M7!scala-library.jar (2921ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.0-M7/scala-reflect-2.10.0-M7.jar ...
@seratch
seratch / console.scala
Created August 23, 2012 12:30
SQLInterpolation prototype
scala> case class SQLInterpolationResult[P](strings: Seq[String], param: P)
defined class SQLInterpolationResult
scala> class SQLInterpolation(val s: StringContext) extends AnyVal {
| def sql[P](param: P) = new SQLInterpolationResult(s.parts, param)
| }
defined class SQLInterpolation
scala> @inline implicit def interpolation(s: StringContext) = new SQLInterpolation(s)
warning: there were 1 feature warnings; re-run with -feature for details
@seratch
seratch / scala.pl
Created August 31, 2012 03:49
scala.pl
#!/usr/bin/env perl
use strict;
use warnings;
package Seq;
sub apply {
my ($class, @seq) = @_;
bless { seq => \@seq }, $class;
@seratch
seratch / build.sbt
Created September 11, 2012 02:58
ScalikeJDBC Left Join Query Example
libraryDependencies ++= Seq(
"com.github.seratch" %% "scalikejdbc" % "[1.3,)",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"org.hsqldb" % "hsqldb" % "[2,)"
)
@seratch
seratch / config.ru
Created September 11, 2012 05:18
Redirect Rack app
def redirect(arg)
new_host = 'new.example.com'
uri = arg["REQUEST_URI"]
[
302,
{'content-type' => 'text/plain', 'location' => "http://#{new_host}#{uri}"},
"http://#{new_host}#{uri}".chars
]
end
run method(:redirect)
@seratch
seratch / build.sbt
Created September 27, 2012 05:35
My first JGit sample in Scala
// http://www.eclipse.org/jgit/download/
resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"
libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "[2.1,)"
@seratch
seratch / Tx.scala
Created September 29, 2012 00:36
Play20 Transactional Action sample
trait Tx { self: Controller =>
def localTx[A](action: Action[A]) = LocalTxActionDecorator[A](action)
}
case class LocalTxActionDecorator[A](action: Action[A]) extends Action[A] {
def parser: BodyParser[A] = action.parser
override def apply() = DB localTx { implicit s => action.apply() }
@seratch
seratch / SQLRunner.scala
Created October 3, 2012 15:28
sbt dbconsole?
case class SQLRunner(sql: String) {
def run(): Seq[Map[Symbol, Any]] = {
try {
SQL(sql).map(_.toSymbolMap()).list.apply()
} catch { case e: java.sql.SQLException =>
val result = SQL(sql).execute.apply()
Seq(Map('RESULT -> result))
}
}
}
@seratch
seratch / config.yml
Created October 11, 2012 10:19
CDPStudyGroup S3 example
access_key_id: xxx
secret_access_key: yyy
@seratch
seratch / developer-contest-ja.md
Created October 18, 2012 10:41
Developer Contest: Japanese Translation

NOTE: The following is a Japanese translation for the guidelines of Typesafe Developer Contest.

http://typesafe.com/resources/developer-contest

Typesafe 社は、Scala、Akka または Play(もしくはそのすべて!)を使ったプログラミングのデモンストレーションとなる、素晴らしいアプリケーションを求めています。

このようなアプリケーションの例として提供できる、誇れるプログラムがありますか?もしあれば、あなたのエントリを心よりお待ちしております。

Martin Odersky が JAX Java Ambassador Award で獲得した賞金をこのコンテストに寄付しました。