Skip to content

Instantly share code, notes, and snippets.

View RayRoestenburg's full-sized avatar

Raymond Roestenburg RayRoestenburg

View GitHub Profile
package my.gists.test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import junit.framework.Assert;
import org.junit.Test;
import com.mongodb.BasicDBObject;
@RayRoestenburg
RayRoestenburg / autoproxy.pac.js
Created March 17, 2010 12:14
autoproxy pac file for company and home network
function FindProxyForURL(url, host) {
var lhost = host.toLowerCase();
var ip = myIpAddressEx();
// exclude localhost and some specific range on company network (123.45.*)
if ((lhost == "localhost")
|| (shExpMatch(lhost, "localhost.*"))
|| (lhost == "127.0.0.1")
|| shExpMatch(lhost, "123.45.*")) {
return "DIRECT";
}
@RayRoestenburg
RayRoestenburg / gist:823180
Created February 11, 2011 22:29
Some usage examples of akka.util.TestKit
package unit.akka
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.{WordSpec, BeforeAndAfterAll}
import akka.actor.Actor._
import akka.util.duration._
import akka.util.TestKit
import java.util.concurrent.TimeUnit
import akka.actor.{ActorRef, Actor}
import util.Random
@RayRoestenburg
RayRoestenburg / RemoteExampleForBangBang.scala
Created June 10, 2011 10:11
What is the expected behavior of remote bangbang?
package unit.akka
import org.junit.Test
import akka.remote.netty.NettyRemoteSupport
import akka.actor.Actor
import akka.event.slf4j.Logging
import org.scalatest.junit.{ShouldMatchersForJUnit, JUnitSuite}
import org.scalatest.BeforeAndAfterAll
import akka.actor.Actor._
import java.nio.channels.ClosedChannelException
@RayRoestenburg
RayRoestenburg / ReplyAfterProcessing.scala
Created September 1, 2011 18:02
Stackable trait for one-way actor testing
import akka.actor.Actor
trait ReplyAfterProcessing extends Actor {
abstract override def receive = {
super.receive andThen {
case msg => self.reply_?(msg)
}
}
}
@RayRoestenburg
RayRoestenburg / testReplyAfterProcessing.scala
Created September 1, 2011 18:10
Test example using ReplyAfterProcessing
class SomeSpec extends WordSpec {
"A oneway actor" should {
"Tell me when it's finished "in {
val testActor = Actor.actorOf(new SomeActor() with ReplyAfterProcessing)
var reply = testActor !! (message, 1000)
if(reply.isEmpty) fail("some message")
}
}
}
@RayRoestenburg
RayRoestenburg / gist:3518294
Created August 29, 2012 20:17
A node trait
trait Node { actor:Actor =>
def send(actorRef:ActorRef, m:Any) { actorRef.tell(m) }
def reply(m:Any) { sender ! m }
def forward(actorRef:ActorRef, m:Any) { actorRef.forward(m) }
def actorOf(props:Props):ActorRef = actor.context.actorOf(props)
def actorFor(actorPath:ActorPath):ActorRef = actor.context.actorFor(actorPath)
}
trait WebNode[Data,Request] extends Actor with Node {
// pathways coming into the node
protected val in = mutable.Set[ActorRef]()
// pathways going out of the node
protected val out = mutable.Set[ActorRef]()
// used to only handle a request once that travels
// through the web
protected var lastId:Option[UUID] = None
@RayRoestenburg
RayRoestenburg / gist:3518521
Created August 29, 2012 20:32
wrappedreceive
def wrappedReceive:Receive = {
case m:Any if ! m.isInstanceOf[(Request,Spider)] =>
recordInput(sender)
before(m)
super.receive(m)
after(m)
}
@RayRoestenburg
RayRoestenburg / gist:3518677
Created August 29, 2012 20:43
handlerequest
def handleRequest:Receive = {
case (req:Request, spider @ Spider(ref,WebTrail(collected, uuid))) if !lastId.exists(_ == uuid) =>
lastId = Some(uuid)
collect(req).map { data =>
sendSpiders(ref, data, (req,spider), collected)
}
}