This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def repeat(n: Int)(f: => Unit) { | |
for (i <- 0 until n) { | |
f | |
} | |
} | |
repeat(3){ | |
println("Hello") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import twitter4j._ | |
import conf._ | |
/* build.sbt | |
scalaVersion := "2.9.1" | |
libraryDependencies ++= Seq( | |
"org.twitter4j" % "twitter4j-core" % "2.2.5", | |
"org.twitter4j" % "twitter4j-stream" % "2.2.5" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.control.Exception._ | |
class ServerIsDownException extends Exception | |
object A extends App { | |
val remoteCalculatorService = new AnyRef { | |
def add(a: Int, b: Int): Int = { | |
a + b match { | |
case odd if odd % 2 == 1 => odd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalaquery.session.Database | |
scala> import org.scalaquery.session.Database | |
import org.scalaquery.session.Database | |
scala> import org.scalaquery.session.Database.threadLocalSession | |
import org.scalaquery.session.Database.threadLocalSession | |
scala> import org.scalaquery.simple.StaticQuery._ | |
import org.scalaquery.simple.StaticQuery._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import org.scalaquery.session.Database | |
import org.scalaquery.session.Database | |
scala> import org.scalaquery.session.Database.threadLocalSession | |
import org.scalaquery.session.Database.threadLocalSession | |
scala> import org.scalaquery.simple.StaticQuery._ | |
import org.scalaquery.simple.StaticQuery._ | |
scala> val db = Database.forURL("jdbc:postgresql:scala_query_example", driver="org.postgresql.Driver", user="user", password="password") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.DynamicVariable | |
object Main extends App { | |
val dyn = new DynamicVariable[Int](0) | |
println(dyn.value) | |
dyn.withValue(100) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalaquery._ | |
import ql._ | |
import basic.{BasicTable => Table, _} | |
import BasicDriver.Implicit._ | |
import session.{ Session, Database } | |
/* | |
scala_query_example=> select * from Coffees; | |
id | name | supid | price | |
----+-----------------+-------+------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
import Scalaz._ | |
import scala.util.parsing.combinator._ | |
object KanjiNumberParser extends RegexParsers { | |
def one = "一" ^^ { _ => 1L } | |
def two = "二" ^^ { _ => 2L } | |
def three = "三" ^^ { _ => 3L } | |
def four = "四" ^^ { _ => 4L } | |
def five = "五" ^^ { _ => 5L } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalaquery._ | |
import ql._ | |
import session.{ Session, Database } | |
import basic.{ BasicTable => Table } | |
import org.scalaquery.ql.basic.BasicDriver.Implicit._ | |
object Main extends App { | |
val db = Database.forURL("jdbc:postgresql:example", | |
driver="org.postgresql.Driver", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* build.sbt | |
libraryDependencies ++= Seq( | |
"org.scalaquery" % "scalaquery_2.9.0-1" % "0.9.5", | |
"postgresql" % "postgresql" % "8.4-702.jdbc4", | |
"commons-dbcp" % "commons-dbcp" % "1.4", | |
"com.github.seratch" %% "scalikejdbc" % "0.1.4" withSources () | |
) | |
resolvers ++= Seq( |