Instantly share code, notes, and snippets.

Some Dude ericacm

View GitHub Profile
View MyTweets.scala
import java.text.SimpleDateFormat
import twitter4j.{Paging, TwitterFactory}
import collection.JavaConverters._
object MyTweets extends App {
val twitter = TwitterFactory.getSingleton
val sdf = new SimpleDateFormat("yyyy-MM-dd")
var maxId = Long.MaxValue
(1 to 6) foreach { i =>
View RemoteActorResolver.scala
import java.util.concurrent.atomic.AtomicInteger
import concurrent.{Future, Promise}
import akka.actor._
import concurrent.duration._
import util.control.NoStackTrace
object RemoteActorResolver {
val resolverCount = new AtomicInteger(0)
type LookupMap = Map[ActorPath, Promise[ActorRef]]
View MessageSequenceTest.scala
package akka.contrib.pattern
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, BeforeAndAfterAll}
import akka.testkit.TestKit
import akka.actor._
import java.util
import concurrent.duration._
import akka.serialization.SerializationExtension
View MessageSequence.scala
package akka.contrib.pattern
import akka.actor.{Cancellable, ActorLogging, ActorRef, Actor}
import java.util
import akka.serialization.SerializationExtension
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import scala.util.{Try, Failure, Success}
import scala.language.existentials
import java.util.UUID
View ScalingThreadPoolExecutor.scala
import scala.concurrent.ExecutionContext
import java.lang.Thread.UncaughtExceptionHandler
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{ThreadPoolExecutor, LinkedBlockingQueue, ThreadFactory, TimeUnit}
import java.util.concurrent.{Executors, RejectedExecutionHandler, RejectedExecutionException}
object ScalingThreadPoolExecutor {
val defaultSecondsBeforeEviction = 60
def apply(minThreads: Int, maxThreads: Int, threadFactory: ThreadFactory): ScalingThreadPoolExecutor = {
View gist:7234947
trait ActorStack extends Actor {
/** Actor classes should implement this partialFunction for standard
* actor message handling
*/
def wrappedReceive: Receive
/** Stackable traits should override and call super.receive(x) for
* stacking functionality
*/
def receive: Receive = {
View ReliableProxy.scala
/**
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.pattern
import akka.actor._
import akka.remote.RemoteScope
import scala.concurrent.duration._
import scala.util.Try
View CancellableFuture.scala
trait FutureCancelSupport {
def cancellableFuture[T](fun: Future[T] => T)(implicit ex: ExecutionContext): (Future[T], () => Boolean) = {
val p = Promise[T]()
val f = p.future
val funFuture = Future(fun(f))
funFuture.onComplete(p tryComplete(_)) // Akka 2.0
// p tryCompleteWith funFuture // Scala 2.10
(f, () => p.tryComplete(Left(new CancellationException))) // Akka 2.0
View startThread.scala
def startThread(name: String)(thunk: => Unit): Thread = {
val t = new Thread(name) {
override def run() { thunk }
}
t.setDaemon(true)
t.start()
t
}
View startServer.scala
def startServer(serverStartFunc: () => Unit) {
val serverStarted = new Semaphore(0)
var serverStartException: Option[Exception] = None
startThread("startZookeeper") {
try {
log.info("Starting ZooKeeper server. clientPort=" + clientPort +
" class=" + zkServer.getClass.getName)
serverStartFunc()
serverStarted.release()