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 series(items: List[Int]) { | |
if (items.nonEmpty) { | |
Future { | |
doHeavyWork(items.head) | |
} onComplete { | |
case res => | |
// handler results | |
series(items.tail) | |
} |
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
echo '{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ "terms": { "person": ["bob", "jake"] } }, | |
{ "range": { "score": { "gt": 0 } } } | |
] | |
} | |
}, | |
"aggs": { |
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 ScaleFactor { | |
val T1MicroSpeed = 10.0 | |
def calcNeedInstances(avgSpeed: Int, queueSize: Int): Int = { | |
val taskPerHour = avgSpeed * 3600 | |
val maxInstances = math.ceil(avgSpeed / T1MicroSpeed) | |
queueSize / taskPerHour.toDouble match { | |
case h if h < 1 ⇒ math.ceil(maxInstances * h).toInt |
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 Solution extends App { | |
val bf = Array.newBuilder[String] | |
(1 to Console.readLine().toInt) | |
.map(_ => Console.readLine()) | |
.foreach(s => println(calc(s))) | |
@annotation.tailrec | |
def sum(n: Int, res: Int = 0): Int = if (n <= 0) res else sum(n - 1, res + n) |
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 MC(ids: List[Int], matchType: String = "one") | |
def weight(mcType: String) = 1 | |
val values = List(MC(List(1, 2, 3, 4, 5)), MC(List(3, 4, 5, 3, 6)), MC(List(3, 1, 5, 2, 3))) | |
val winners = values.foldLeft(collection.mutable.Map.empty[Int, Int])({ (acc, mc) ⇒ | |
mc.ids foreach (id ⇒ acc.update(id, acc.getOrElse(id, 0) + weight(mc.matchType))) | |
acc | |
}).foldLeft(collection.immutable.TreeMap.empty[Int, Int]) { case (best, (id, weight)) ⇒ |
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
it should "test" in { | |
// var prev = 0 | |
// var max = List.empty[Int] | |
// val n = ListBuffer.empty[Int] | |
val l = List(5, 1, 4, 2, 3, 3, 8) | |
var tail = l | |
val res = ListBuffer.empty[List[Int]] |
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/bash | |
for i in $(seq $1 300000 $2) | |
do | |
echo "$i" | |
/home/ubuntu/export-to-csv.sh $i 300000 | |
echo "curl $i" | |
curl -s -XPOST $3:9200/_bulk --data-binary @/mnt/vk-csv/vk-$i.out > /dev/null | |
done |
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.util.{Success, Failure} | |
import akka.actor._ | |
import spray.client.pipelining._ | |
import spray.http._ | |
object Test extends App { | |
implicit val system = ActorSystem() |
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.util.parsing.combinator._ | |
object JSON extends JavaTokenParsers { | |
val obj: Parser[Map[String, Any]] = | |
"{" ~> repsep(member, ",") <~ "}" ^^ (Map() ++ _) | |
val arr: Parser[List[Any]] = | |
"[" ~> repsep(value, ",") <~ "]" |
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.libitec.sce.util.amqp | |
import com.rabbitmq.client._ | |
import com.rabbitmq.client.AMQP.BasicProperties | |
import com.typesafe.config.Config | |
/** | |
* Simple amqp-client | |
*/ |