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 java.lang.System.currentTimeMillis | |
import java.util.concurrent.TimeUnit.{MILLISECONDS, SECONDS} | |
import java.util.concurrent.{TimeUnit, Executors} | |
import java.util.concurrent.Executors.newFixedThreadPool | |
import scala.concurrent.ExecutionContext.fromExecutorService | |
import scala.concurrent.{Future, ExecutionContext} | |
import scala.util.{Failure, Success} | |
/** |
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
val collected = list collect { case 1 => 2 case 2 => 1 case 3 => 0 } | |
collected foreach println |
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
trait B | |
trait A { | |
def bar: Boolean | |
} | |
def foo: A with B = new A with B { | |
def bar: Boolean = true | |
} |
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 CharactersCount extends App { | |
val src = fromFile(new File("/Users/akrasnyanskiy/IdeaProjects/spark-sql-example/src/main/resources/words.txt")) | |
var mapped = src.map((_, 1)) | |
val combiner: (((Char, Int), (Char, Int)) => ((Char, Int))) = { | |
case ((a, b), (c, d)) => ('_', b + d) | |
} | |
val wordsAmount = (mapped reduce combiner)._2 |
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
/** | |
* @author Alexander Krasniansky | |
*/ | |
object PointCover extends App { | |
case class Point(x: Int) | |
case class Segment(start: Int, end: Int) | |
def cover(points: Seq[Point], segmentLength: Int): Seq[Segment] = points match { | |
case x :: _ => |
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 java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.math.BigInteger; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.atomic.AtomicReference; | |
import static com.jayway.awaitility.Awaitility.await; | |
import static java.lang.Integer.parseInt; | |
import static java.lang.System.in; |
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 fib(i: Int): Int = i match { | |
case 0 => 0 | |
case 1 => 1 | |
case x if x > 1 | |
=> fib(i - 1) + fib(i - 2) | |
case _ => throw new IllegalArgumentException | |
} |
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 akka.actor.{Actor, ActorSystem, Props} | |
import akka.util.Timeout | |
import akka.pattern.ask | |
import scala.concurrent.duration._ | |
implicit val timeout = Timeout(2.seconds) | |
class Loafer extends Actor { | |
// def receive = PartialFunction.empty | |
def receive = { |
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
sealed trait Plus[P] { | |
def ~+[T <: Plus[T]](x: T, y: T): T | |
} | |
sealed trait Int extends Plus[Int] | |
class PlusInt[PI] extends Plus[PI] { | |
def ~+[T <: Plus[T]](x: T, y: T) = x.~+(y, x) | |
} |
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
package com.netaporter.routing | |
import akka.actor.SupervisorStrategy.Stop | |
import akka.actor.{OneForOneStrategy, _} | |
import com.netaporter._ | |
import com.netaporter.routing.PerRequest._ | |
import org.json4s.DefaultFormats | |
import spray.http.StatusCode | |
import spray.http.StatusCodes._ | |
import spray.httpx.Json4sSupport |