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
| mkdir MyProject | |
| cd MyProject | |
| mkdir -p src/{main,test}/scala | |
| touch build.sbt | |
| echo -e 'name := "MyProject"\n\nversion := "0.1"\n\nscalaVersion := "2.10.1"' >> build.sbt | |
| touch src/main/scala/HelloWorld.scala | |
| echo -e 'object Main extends App { println("Hello World!") }' >> src/main/scala/HelloWorld.scala | |
| sbt run |
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
| wget http://www.scala-lang.org/downloads/distrib/files/scala-2.10.1.tgz | |
| tar xzf scala-2.10.1.tar.gz | |
| mv scala-2.10.1 /opt/scala/scala-2.10.1 | |
| echo 'PATH="/opt/scala/scala-2.10.1/bin:$PATH"' >> ~/.profile | |
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
| addSbtPlugin("me.lessis" % "np" % "0.2.0") | |
| resolvers += Resolver.url("sbt-plugin-releases", | |
| url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))( | |
| Resolver.ivyStylePatterns) |
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 play.api.libs.json._ | |
| case class Doc(name: String, content: String) | |
| val docWrites = Json.writes[Doc] |
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
| case class Profile(id: Option[String], name: String, docs: Seq[Doc]) | |
| case class Doc(name: String, content: String) | |
| implicit val docWrites = Json.writes[Doc] | |
| implicit val profileWrites = Json.writes[Profile] |
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
| pathPrefix("v1" / "users") { | |
| path("") { | |
| post { | |
| entity(as[CreateUserRequest]) { createUserRequest => | |
| log.info("Creating user for " + createUserRequest) | |
| complete { | |
| val res = userDao createUser createUserRequest | |
| MailNotifier(res) | |
| res | |
| } |
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
| object UserController extends Controller with RESTResponses { | |
| def create = Action.typedJson(UserCreateForm.reads, User.writes) { request => | |
| val user = request.body.create() | |
| rest.async.Created(dao.save(user)) | |
| } | |
| def get(id: String) = Action.httpToTypedJson(User.writes) { request => | |
| rest.async.Ok(dao.get(Id(id))) | |
| } |
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 countTokenized: Iteratee[String, List[Int]] = { | |
| def step(restCount: Int, resultList: List[Int])(i: Input[String]): Iteratee[String, List[Int]] = i match { | |
| case Input.Empty => | |
| Done(Nil, Input.Empty) | |
| case Input.EOF => { | |
| (restCount, resultList) match { | |
| case (0, Nil) => Done(Nil, Input.EOF) | |
| case (0, resList) => Done(resList, Input.EOF) | |
| case (rCount, Nil) => Done(List(rCount), Input.EOF) | |
| case (rCount, resList) => Done(resultList ::: List(restCount), Input.EOF) |
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
| function test(arg){ | |
| switch (true) { | |
| case arg === 'test': { | |
| const value = 'a'; | |
| return 'it was test'; | |
| } | |
| case art === 'foo': { | |
| const value = 'b'; | |
| return 'it was foo'; | |
| } |
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
| const mongoose = require('mongoose'); | |
| async function withTempDb(dbName, action) { | |
| const mongoUri = `mongodb://localhost:27017/${dbName}`; | |
| const opts = {useMongoClient: true, promiseLibrary: global.Promise }; | |
| const conn = mongoose.createConnection(mongoUri, opts); | |
| const onceOpen = new Promise( resolve => conn.once('open', resolve )); | |
| await onceOpen; |
OlderNewer