Skip to content

Instantly share code, notes, and snippets.

autoCompilerPlugins := true,
libraryDependencies <+= scalaVersion {
v => compilerPlugin(
"org.scala-lang.plugins" %
"continuations" %
"2.10.0-RC5")
// Use the final Scala version once it's released
},
scalacOptions += "-P:continuations:enable",
public Future<List<String>> crawl(final String url, final int maxDepth, final int currentDepth) {
if (maxDepth == currentDepth) {
// no need to call
return Future.succesful(Collections.emptyList());
} else {
// 1. get crawl the URL and get its URLs
Future<List<String>> foundUrlsFuture = future(new Callable<List<String>>() {
public List<String> call() throws Exception {
import play.api._
import com.typesafe.config.ConfigFactory
import akka.actor.ActorSystem
object Global extends GlobalSettings {
override def onStart(app: Application) {
val config = ConfigFactory.parseString("""
akka {
actor {
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import org.junit.runner.RunWith
@RunWith(classOf[JUnitRunner])
class MySpec extends Specification {
"The number 1" should {
"equal the number 2" in {
1 must_== 2
}
implicit val system = ActorSystem("jse-system")
implicit val timeout = Timeout(5.seconds)
val engine = system.actorOf(Rhino.props(), "engine")
def tempResourceFile(resourceName: String): File = {
import org.apache.commons.io._
val url = this.getClass.getResource(resourceName);
val file = File.createTempFile(
FilenameUtils.getBaseName(resourceName),
val PlayBaseDirProp = Tags.Tag("PlayBaseDirProp")
concurrentRestrictions in Global += Tags.limit(PlayBaseDirProp, 1)
def withSystemProperty[T](name: String, value: String)(f: => T) = {
println(s"*** Setting property $name = $value")
System.setProperty(name, value)
try {
f
} finally {
println(s"*** Clearing property $name")
macro invert {
rule { { $x:ident <- $y:expr } } => {
$y(function($x) { return $x })
}
rule { { $x:ident <- $y:expr $rest ... } } => {
$y(function($x) {
return invert { $rest ... }
})
}
rule { { $y:expr } } => { $y }
@richdougherty
richdougherty / Global.scala
Created February 7, 2014 22:05
Removing leading slashes before routing requests
import play.api._
import play.api.mvc._
object Global extends GlobalSettings {
case class RewrittenRequestHeader(val path: String, delegate: RequestHeader) extends RequestHeader {
def id = delegate.id
def tags = delegate.tags
def uri = delegate.uri
def method = delegate.method
@richdougherty
richdougherty / Global.scala
Created February 7, 2014 22:38
Strip duplicate leading slashes before both routing and handling requests
import play.api._
import play.api.mvc._
import scala.concurrent.Future
object RewrittenRequestHeader {
def rewrite(header: RequestHeader): RequestHeader = {
if (header.path.startsWith("//")) {
val newPath = header.path.substring(1)
RewrittenRequestHeader(newPath, header)
} else {
@richdougherty
richdougherty / Global.scala
Created February 7, 2014 22:45
Removing leading slashes before handling requests
import play.api._
import play.api.mvc._
object Global extends GlobalSettings {
case class RewrittenRequestHeader(val path: String, delegate: RequestHeader) extends RequestHeader {
def id = delegate.id
def tags = delegate.tags
def uri = delegate.uri
def method = delegate.method