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
/* | |
* Copyright (C) 2012 47 Degrees, LLC | |
* http://47deg.com | |
* [email protected] | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 |
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 example | |
import java.util.concurrent.ConcurrentHashMap | |
import java.util.concurrent.ConcurrentLinkedQueue | |
import com.typesafe.config.Config | |
import com.typesafe.config.ConfigFactory | |
import akka.actor.Actor | |
import akka.actor.ActorContext | |
import akka.actor.ActorRef | |
import akka.actor.ActorSystem |
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
case object BackendRegistration | |
case class Job(text: String) | |
class Frontend extends Actor { | |
var backends = IndexedSeq.empty[ActorRef] | |
var jobCounter = 0 | |
def receive = { | |
case job: Job if backends.isEmpty => |
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.cluster.Cluster | |
import akka.cluster.ClusterEvent._ | |
val clusterListener = system.actorOf(Props(new Actor with ActorLogging { | |
def receive = { | |
case state: CurrentClusterState ⇒ | |
log.info("Current members: {}", state.members) | |
case MemberUp(member) ⇒ | |
log.info("Member is up: {}", member) | |
// send a message to the "world" actor running at the member node |
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.pattern.CircuitBreaker | |
val breaker = | |
CircuitBreaker(system.scheduler, | |
maxFailures = 5, | |
callTimeout = 10.seconds, | |
resetTimeout = 1.minute) | |
def dangerous: Future[String] = | |
breaker.withCircuitBreaker(Future(dangerousCall)) |
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
mkdir -p ~/.vim/{ftdetect,indent,syntax} && for d in ftdetect indent syntax ; do wget -O ~/.vim/$d/scala.vim https://raw.github.com/scala/scala-dist/master/tool-support/src/vim/$d/scala.vim ; done |
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.ActorDSL._ | |
val ref = actor("fred")(new Act { | |
become { | |
case "hello" => sender ! "world!" | |
} | |
}) | |
implicit val recv = inbox() | |
ref ! "hello" // uses the `recv` as sender ref |
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
This ClojureScript REPL is able to work in restrictive environment, like Chrome Extension. | |
Requirements: | |
- WebSocket :: to receive JavaScript forms and send results back, | |
- 'unsafe-eval' :: Content Security Policy needs to allow 'unsafe-eval' for script-src | |
Security warning: Do *not* use in production! | |
Tested on Chrome, might work on other HTML5 enabled browsers. |
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 scala.math.{BigInt, BigDecimal} | |
object RecursiveStreams | |
{ | |
// natural numbers | |
lazy val N: Stream[BigInt] = Stream.cons(BigInt(1), N.map(_ + 1)) | |
// fibonacci series | |
lazy val fib: Stream[BigInt] = Stream.cons(BigInt(0), Stream.cons(BigInt(1), fib.zip(fib.tail).map(a => a._1 + a._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
import java.io.ByteArrayInputStream | |
import java.io.ByteArrayOutputStream | |
import java.io.EOFException | |
import java.io.InputStream | |
import java.io.OutputStream | |
import org.bson.BSONCallback | |
import org.bson.BSONObject | |
import com.mongodb.DBCallback |