Skip to content

Instantly share code, notes, and snippets.

View seratch's full-sized avatar

Kazuhiro Sera seratch

View GitHub Profile
@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 / 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 / Gemfile
Created August 10, 2012 11:14
Scaruby compose/and_then example
source "http://rubygems.org/"
gem 'scaruby'
@seratch
seratch / KeyczarService.scala
Created July 10, 2012 13:06
KeyczarService.scala
import java.net.URLDecoder
import java.io.File
import org.keyczar.Crypter
case class KeyczarService(keypath: String) {
lazy val keyLocation = URLDecoder.decode(
new File(classOf[KeyczarService].getClassLoader.getResource(keypath).getFile).getAbsolutePath,
"UTF-8"
)
@seratch
seratch / ThymeleafSupport.scala
Created June 28, 2012 09:19
ThymeleafSupport for Scalatra
import org.scalatra.ScalatraKernel
import org.thymeleaf.templateresolver._
import org.thymeleaf.TemplateEngine
import org.thymeleaf.context.WebContext
trait ThymeleafSupport {
self: ScalatraKernel =>
lazy val thymeleafResolver: TemplateResolver = {
@seratch
seratch / sample.scala
Created June 11, 2012 00:22
Improved error message for generalized type constraints
class Foo[A, B <: Option[A]] {
@annotation.implicitNotFound(msg = "Should be Some!")
sealed abstract class =:=[From, To] extends (From => To) with Serializable
private[this] final val singleton_=:= = new =:=[Any,Any] { def apply(x: Any): Any = x }
object =:= {
implicit def tpEquals[A]: A =:= A = singleton_=:=.asInstanceOf[A =:= A]
}
type This = Foo[A, B]
@seratch
seratch / build.sbt
Created June 10, 2012 09:54
Generalized type constraints in ScalikeJDBC
libraryDependencies ++= Seq(
"com.github.seratch" %% "scalikejdbc" % "1.3.0",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"com.h2database" % "h2" % "[1.3,)"
)
initialCommands := """import scalikejdbc._
|Class.forName("org.h2.Driver")
|ConnectionPool.singleton("jdbc:h2:mem:tmp", "", "")
|implicit val session = DB.autoCommitSession
@seratch
seratch / iris_reader.scala
Created June 1, 2012 01:59
Iris data set reader example
import util.control.Exception._
def using[R <: { def close() }, A](resource: R)(f: R => A): A = ultimately {
ignoring(classOf[Throwable]) apply resource.close()
} apply f(resource)
case class Sepal(length: Double, width: Double)
case class Petal(length: Double, width: Double)
case class Species(name: String)
case class Iris(sepal: Sepal, petal: Petal, species: Species)
import org.scalatest._
import org.scalatest.matchers._
import org.joda.time.DateTime
import java.util.concurrent.Executors
import akka.dispatch._
import akka.util.Duration
import akka.util.duration._
class RendezvousSpec extends FlatSpec with ShouldMatchers {
@seratch
seratch / readme.md
Created May 18, 2012 00:51
Finagle Developer Guide (December 15, 2011 Draft) の適当な和訳

細かい点で間違いなどあるかと思います。fork して直していただけると助かります。

Finagle is built using sbt. We've included a bootstrap script to ensure the correct version of sbt is used. To build:

Finagle は sbt を使ってビルドしています。私たちは確実に適切なバージョンの sbt を使うようにブートストラップ用のスクリプトを含めています。このように実行します。

    $ ./sbt test