Skip to content

Instantly share code, notes, and snippets.

@yamashiro
yamashiro / gist:2594443
Created May 4, 2012 12:06
呼び出し順番むずいぉ
trait Base extends App {
def doRun(args:Array[String]);
doRun(args)
}
object ConcreteClass extends Base {
def doRun(args:Array[String]) {
println(args)
}
}
@yamashiro
yamashiro / Build.scala
Created May 8, 2012 05:30
sbtのマルチプロジェクト構成
import sbt._
import Keys._
import com.github.retronym.SbtOneJar
object AggregateBuild extends Build {
val specs = "org.specs2" %% "specs2" % "1.9" % "test"
val specsResolver = Seq("snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
"releases" at "http://oss.sonatype.org/content/repositories/releases")
lazy val dependencies = Seq(specs)
@yamashiro
yamashiro / AppInjector.scala
Created May 10, 2012 05:39
ScalaでDIというかServiceLocator的な名状しがたい何か
trait ApiInjector {
var twitter : TwitterApi = new TwitterApiImpl;
//他にもいろいろなサービス
}
@yamashiro
yamashiro / SpecsStudyTest.scala
Created May 11, 2012 06:45
Test Specs2 Tag functionality
import org.specs2.mutable._
class SpecsStudyTest extends Specification with Tags {
"world" should {
"have 5 characters" in {
"world".size must_== 5
}
"is beutiful" in {
"world" must_== "beutiful"
}
@yamashiro
yamashiro / gist:2717307
Created May 17, 2012 08:07
sbtで既存のタスクの前に処理を実行したいのだが…
val hello = TaskKey[Unit]("hello")
val helloTask = hello <<= streams map { (s: TaskStreams) =>
s.log.info("Hello!")
println("hello")
}
val compile = TaskKey[Unit]("compile")
compile <<= (compile in Compile) dependsOn (hello)
@yamashiro
yamashiro / Build.scala
Created May 17, 2012 12:46
マルチプロジェクトなBuild.scala
import sbt._
import Keys._
import com.github.retronym.SbtOneJar
import scala._
object Build extends Build {
val specs = "org.specs2" %% "specs2" % "1.9" % "test"
val specsResolver = Seq("snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
"releases" at "http://oss.sonatype.org/content/repositories/releases")
val mysqlDriver = "mysql" % "mysql-connector-java" % "5.1.19" % "runtime"
@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) );
@yamashiro
yamashiro / gist:2834130
Created May 30, 2012 06:45
どういう変換が起こっているのかわからない…
import org.specs2.mutable._
class FunctionArgument {
def hoge(func: => AnyRef, condition:Boolean = true) : String = {
if (condition) {
func.toString
} else {
"false"
}
}
@yamashiro
yamashiro / gist:2835272
Created May 30, 2012 09:55
Traitつき無名クラス
import org.specs2.mutable._
trait BarTrait {}
class Hoge {}
class TraitGetClassTest extends Specification {
"Trait mixin " should {
"getClass " in {
val hoge = new Hoge with BarTrait
hoge.getClass.toString must_== "Hoge"
}
}
package study
import org.specs2.mutable.Specification
import scalaz.Identity
import org.sisioh.dddbase.core.Entity
import java.io._
class Hoge extends Specification {
"Serial " should {