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 Animal | |
private class Dog extends Animal | |
private class Cat extends Animal | |
trait Wanna | |
case object WannaCat extends Wanna | |
case object WannaDog extends Wanna | |
trait AnimalFactory[Wanna] { | |
def create(): Animal |
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.concurrent.Await | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
import scala.concurrent.blocking | |
import scala.concurrent.duration.Deadline | |
import scala.concurrent.duration.Duration | |
import scala.concurrent.duration.DurationInt | |
import scala.concurrent.duration.DurationLong | |
import scala.concurrent.future | |
import scala.concurrent.promise |
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
/** | |
* A monad to abstract dependencies in the code, see https://coderwall.com/p/kh_z5g | |
*/ | |
object Reader { | |
/** | |
* an implicit to convert a function A => B in a Reader[A, B] | |
*/ | |
implicit def reader[C, R](block: C => R): Reader[C, R] = Reader(block) |
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 | |
#inspired by https://github.com/vide/nagios-scripts/blob/master/check_kafka_lag.sh | |
function printHelp() { | |
cat >&2 <<EOF | |
$@ | |
--warning|-w Warning threshold | |
--critical|-c Critical threshold |
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
/** | |
* CSS bar graph with Positive and Negative values | |
*/ | |
.graph { | |
width: 100px; | |
border: 1px solid #aeaeae; | |
background-color: #eaeaea; | |
} | |
/* Start of "Micro clearfix" */ | |
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.reflect.ClassTag | |
import scala.collection.mutable.WrappedArray | |
import scala.collection.mutable.ArrayLike | |
def ASeq[T](elt: T*)(implicit ct: ClassTag[T]): IndexedSeq[T] = { | |
val a = elt.toArray.clone | |
a.deep.asInstanceOf[IndexedSeq[T]] | |
} | |
val a = Array(1,2,3) //> a : Array[Int] = Array(1, 2, 3) |
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 test { | |
/** | |
* The companion object | |
*/ | |
object Reader { | |
/** | |
* automatically wrap a function in a reader | |
*/ |
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 com.twitter.util.{Duration, Time} | |
/** | |
* Sort of a lazy val, but that refreshes itselfs every so often; or a temporary cache for a value T, | |
* will be refreshed at a minimun at the specified interval. | |
* In practice, the refresh is done only when the value is accessed, so there are no guarantees | |
* to when it will actually be refreshed. You can just be sure that it won't be refreshed if two calls | |
* are made within `every`. | |
*/ | |
class RefreshEvery[T](every: Duration)(refresh: => T) { |
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 com.fasterxml.jackson.core._ | |
object ScalaJson { | |
lazy val factory = new JsonFactory() | |
implicit class JsonString(json: String) { | |
def jsonField(name: String) = ScalaJson.getFieldOnly(name, json) | |
} |
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 MyActor extends Actor { | |
var driver: ActorRef = null | |
val identifyId = //get a unique identifyId for that driverUrl | |
override def preStart() { | |
val driverSel = context.actorSelection(driverUrl) | |
driverSel ! Identify(identifyId) | |
} |
NewerOlder