Skip to content

Instantly share code, notes, and snippets.

def series(items: List[Int]) {
if (items.nonEmpty) {
Future {
doHeavyWork(items.head)
} onComplete {
case res =>
// handler results
series(items.tail)
}
echo '{
"query": {
"bool": {
"must": [
{ "terms": { "person": ["bob", "jake"] } },
{ "range": { "score": { "gt": 0 } } }
]
}
},
"aggs": {
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
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)
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)) ⇒
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]]
#!/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
import scala.util.{Success, Failure}
import akka.actor._
import spray.client.pipelining._
import spray.http._
object Test extends App {
implicit val system = ActorSystem()
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, ",") <~ "]"
@kulikov
kulikov / rabbitmq-client.scala
Last active December 17, 2015 03:58
Simple RabbitMQ client for scala
package com.libitec.sce.util.amqp
import com.rabbitmq.client._
import com.rabbitmq.client.AMQP.BasicProperties
import com.typesafe.config.Config
/**
* Simple amqp-client
*/