Skip to content

Instantly share code, notes, and snippets.

View wertlex's full-sized avatar
🙈
Balance

Alex V. Povar wertlex

🙈
Balance
View GitHub Profile
// 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;
// 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];
});
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;
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';
}
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)
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)))
}
pathPrefix("v1" / "users") {
path("") {
post {
entity(as[CreateUserRequest]) { createUserRequest =>
log.info("Creating user for " + createUserRequest)
complete {
val res = userDao createUser createUserRequest
MailNotifier(res)
res
}
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]
import play.api.libs.json._
case class Doc(name: String, content: String)
val docWrites = Json.writes[Doc]
@wertlex
wertlex / build.sbt
Last active December 18, 2015 21:18
addSbtPlugin("me.lessis" % "np" % "0.2.0")
resolvers += Resolver.url("sbt-plugin-releases",
url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(
Resolver.ivyStylePatterns)