Scala Parser for YAML File


import java.io.{File, FileInputStream}
import java.text.SimpleDateFormat
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.Constructor

object Main {
def main(args: Array[String]): Unit = {
val text = scala.io.Source.fromInputStream(getClass.getResourceAsStream(
"codes.yaml")).mkString
val yaml = new Yaml
val obj = yaml.load(text)
val codes = obj.asInstanceOf[java.util.LinkedHashMap[String,java.util.Map[String, Any]]]
var values = codes.get("duration").get("values").asInstanceOf[java.util.ArrayList
[java.util.Map[String,Any]]]
values.toArray.foreach(c=> println(c.asInstanceOf[java.util.LinkedHashMap[String,Any]]
.get("code")))
}
}

codes.yaml:

duration:
values:
-
code: 1
from: 0
to: 1
-
code: 2
from: 1
to: 3

build.sbt

libraryDependencies += "org.yaml" % "snakeyaml" % "1.8"

Advertisements

Hello World with Play

wget https://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip?_ga=1.140741362.1365550810.1438956173

sudo unzip ~/Downloads/typesafe-activator-1.3.6.zip -d /opt/

export PATH=$PATH:/opt/activator-dist-1.3.6

java -version
java version “1.8.0_45”
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)

sudo chmod o+X /opt/activator-dist-1.3.6/activator

./activator new hello-world-app play-scala

cd hello-world-app

// in app/controllers/Application.scala
// change line
// Ok(views.html.index(“Your new application is ready.”)) -> Ok(“Hello World”)

./activator run

// in browser http://localhost:9000/

// to generate intillig idea project
mkdir -p ~/.sbt/0.13/plugins/
echo ‘addSbtPlugin(“com.github.mpeltonen” % “sbt-idea” % “1.6.0”)’ >>~/.sbt/0.13/plugins/build.sbt
./activator gen-idea