Skip to content

Instantly share code, notes, and snippets.

View akirillov's full-sized avatar

Anton Kirillov akirillov

View GitHub Profile
class Figure(val x: Int, val y: Int, val figureType: Int)
class ChessBoard(val m: Int, val n: Int){
val board = Array.ofDim[Int](m,n)
def putFigure(f: Figure){
f.figureType match {
case -2 => putKing(f.x,f.y)
trait ElasticSearchClient {
val indexName: String
val typeName: String
def executeWithESClient[T](f: TransportClient => T) = {
ElasticSearchTransport.transportClient.map(f)
}
@akirillov
akirillov / FlumeFingleClient
Created September 25, 2014 11:50
Finagle Clietn Naive Example
def send[T <: WebLogEvent](event: T) = {
val client: Service[HttpRequest, HttpResponse] = ClientBuilder()
.codec(Http())
.hosts(servers.mkString(","))
.hostConnectionLimit(10)
.retries(3)
.build()
val request = createFlumeRequest(event)
val future = client(request)
@akirillov
akirillov / FinalgeHttpClientWithRetries
Created October 7, 2014 13:06
Finagle default HttpClient configured with timeouts and retry filters
val retry = new RetryingFilter[HttpRequest, HttpResponse](
retryPolicy = RetryPolicy.tries(3),
timer = DefaultTimer.twitter
)
val timeout = new TimeoutFilter[HttpRequest, HttpResponse](
timeout = 3.seconds,
timer = DefaultTimer.twitter
)
@akirillov
akirillov / QuickSort.scala
Created October 13, 2014 09:45
Scala QuickSort
def sort(list: List[Int]): List[Int] = {
list match {
case Nil => list
case _ => sort(list.tail.filter(_ <= list.head)) ::: list.head :: sort(list.tail.filter(_ > list.head))
}
}
@akirillov
akirillov / OderskyQuickSort.scala
Created October 13, 2014 09:50
QuickSort Example from "Scala by Example"
def sort(xs: Array[Int]): Array[Int] = {
if (xs.length <= 1) xs
else {
val pivot = xs(xs.length / 2)
Array.concat(sort(xs filter (pivot >)),xs filter (pivot ==), sort(xs filter (pivot <)))
}
}
@akirillov
akirillov / MonoidPML.scala
Last active August 29, 2015 14:19
Pimp My Library + Monoid List Operation
trait Monoid[A]{
def mappend(a1: A, a2: A): A
def mzero: A
}
object Monoid {
implicit val IntMonoid: Monoid[Int] = new Monoid[Int] {
def mappend(a: Int, b: Int): Int = a + b
def mzero: Int = 0
}
@akirillov
akirillov / MonoidPML.scala
Last active August 29, 2015 14:19
Pimp my library with monoid operations on list
package io.datastrophic
trait Monoid[A]{
def append(a1: A, a2: A): A
def unit: A
}
object Monoid{
implicit val IntMonoid = new Monoid[Int]{
def append(a1: Int, a2: Int): Int = a1 + a2
@akirillov
akirillov / cassandra.yaml
Last active August 29, 2015 14:25
Different combinations of listen/rpc addresses for Docker/EC2/hardware setups
# Docker ===========================
# MacOS specific command to connect from host machine: cqlsh `boot2docker ip`
# Cassandra 1.2.9
listen_address: 127.0.0.1
rpc_address: 0.0.0.0
# Cassandra 2.1
listen_address: 127.0.0.1
rpc_address: 0.0.0.0
@akirillov
akirillov / ad-hoc_polymorphism.scala
Last active October 20, 2015 17:57
Simple example of ad-hoc polymorphism in Scala
//single parameter function for different types
trait Size[A] {
def size(a: A): Int
}
def size[A: Size](a: A): Int = implicitly[Size[A]].size(a)
implicit object StringSize extends Size[String]{
override def size(a: String): Int = a.length
}