Skip to content

Instantly share code, notes, and snippets.

View gszeliga's full-sized avatar

Guillermo Szeliga gszeliga

View GitHub Profile
def ~> [U](q: => Parser[U]): Parser[U] = { lazy val p = q // lazy argument
(for(a <- this; b <- p) yield b).named("~>")
}
def natural = rep1(single_digit) ^^ (_.mkString.toInt) named ("natural")
def signedInt = new Parser[Int] {
def apply(in: Input) = {
'-'(in) match {
case Success(_, rest) => natural(rest) map (_ * -1)
case _ => natural(in)
}
}
} named ("signed_int")
def list: Parser[BList] = {
delimitedBy(LIST_BEGIN, LIST_END) {
rep(string | int | list | dict)
} ^^ (BList(_)) named ("list")
}
def dict: Parser[BDict] = {
delimitedBy(DICT_BEGIN, DICT_END) {
rep(string ~ (string | int | list | dict))
} ^^ (_.map { case key ~ value => key -> value }) ^^ (l => BDict(l.toMap)) named ("dict")
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
class Configuration(val name: String, val timeout: Long = 2000, val failureThreshold: Int = 3)
class CircuitBreakerStillOpenException(msg: String) extends Exception(msg)
class CircuitBreaker(private val conf: Configuration) {
private object HalfOpen extends State {
/*
* Sentries
* Copyright (c) 2012-2013 Erik van Oosten All rights reserved.
*
* The primary distribution site is https://github.com/erikvanoosten/sentries
*
* This software is released under the terms of the BSD 2-Clause License.
* There is NO WARRANTY. See the file LICENSE for the full text.
*/
import java.util.concurrent.atomic.{ AtomicInteger, AtomicLong, AtomicBoolean }
import akka.AkkaException
import akka.actor.Scheduler
import akka.util.Unsafe
import scala.util.control.NoStackTrace
import java.util.concurrent.{ Callable, CopyOnWriteArrayList }
import scala.concurrent.{ ExecutionContext, Future, Promise, Await }
import scala.concurrent.duration._
import scala.util.control.NonFatal
import scala.util.Success
package com.covariantblabbering.rotatingmap
import scala.annotation.tailrec
import scala.collection.immutable.HashMap
class RotatingMap[K, V](val numBuckets: Int, val expiredCallback: Option[OnExpiration[K, V]]) {
assert(numBuckets > 2, "Number of buckets must be greater or equal to 2")
private var _buckets: List[Map[K, V]] = (1 to numBuckets).foldRight(List.empty[Map[K, V]])((_, l) => new HashMap[K, V] :: l)
package com.covariantblabbering
package object rotatingmap {
type OnExpiration[K,V] = ((K,V)) => Unit
}
type Curryable[-A,-B, +C] = { def curried: A => Function[B,C] }
trait BuildStep[+E, +A]
case class Continue[T](v: T) extends BuildStep[Nothing, T]
case class Failure[E](e: E) extends BuildStep[E, Nothing]