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
// https://en.wikipedia.org/wiki/Collatz_conjecture | |
function collatzStep(n: number): number { | |
if (n % 2 === 0) { | |
return n/2; | |
} else { | |
return (n * 3) + 1; | |
} | |
} | |
let i: number = 1; |
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
// simple function to convert csv string with header to json string | |
function csv_to_json(csv_string, splitter = ','){ | |
const lines = csv_string.split("\n"); | |
const headers = lines[0].split(splitter); | |
const result = lines.map( line => { | |
let obj = {}; | |
const data_items = line.split(splitter); | |
headers.forEach( (header, i) => { | |
obj[header] = data_items[i]; | |
}); |
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
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; |
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
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 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 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 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 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 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 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) |
NewerOlder