This file contains 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 java.util.NoSuchElementException | |
import scala.util.control.Exception._ | |
import org.scalatra._ | |
trait SafeParams { self: ScalatraKernel => | |
def paramsSafely(key: String): Option[String] = { | |
catching(classOf[NoSuchElementException]).opt { | |
params(key) | |
} |
This file contains 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
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
val helpMessage = """ | |
Usage: | |
-n do not output the trailing newline | |
-x repeat x times |
This file contains 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
// see: https://github.com/szeiger/scala-query/blob/0.9.5/src/main/scala/org/scalaquery/ql/basic/BasicColumnOptions.scala | |
package com.github.tototoshi.example | |
import org.scalaquery._ | |
import session.{ Database, Session } | |
import ql._ | |
import basic.BasicDriver.Implicit._ | |
import basic.{ BasicTable => Table } |
This file contains 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.xml._ | |
import scala.util.parsing.combinator._ | |
trait SelectorParser extends RegexParsers { | |
val html: NodeSeq | |
def tagSelector(tag: String)(filter: NodeSeq => Boolean): NodeSeq = html \\ tag filter filter | |
def idFilter(id: String): NodeSeq => Boolean = (n: NodeSeq) => (n \ "@id" text) == id |
This file contains 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
package com.github.tototoshi.example | |
import scala.xml.{ NodeSeq, Elem } | |
import dispatch._ | |
import net.liftweb._ | |
import common._ | |
import util._ |
This file contains 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
interface Function1<T, U> { | |
U apply(T t); | |
} | |
interface Optional<T> { | |
T get(); | |
T getOrElse(T defaultValue); | |
boolean isDefined(); | |
<U> Optional<U> map(Function1<T, U> f); | |
} |
This file contains 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> val gt10: Int => Boolean = (n: Int) => n > 10 | |
gt10: Int => Boolean = <function1> | |
scala> val lt5: Int => Boolean = (n: Int) => n < 5 | |
lt5: Int => Boolean = <function1> | |
scala> 0 to 15 filter (lt5 |+| gt10) | |
res35: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 1, 2, 3, 4, 11, 12, 13, 14, 15) | |
This file contains 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( |
This file contains 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 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 } |