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
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) |
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
trait ElasticSearchClient { | |
val indexName: String | |
val typeName: String | |
def executeWithESClient[T](f: TransportClient => T) = { | |
ElasticSearchTransport.transportClient.map(f) | |
} |
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 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) |
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
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 | |
) |
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 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)) | |
} | |
} |
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 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 <))) | |
} | |
} |
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
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 | |
} |
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 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 |
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
# 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 |
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
//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 | |
} |
OlderNewer