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
{-# START_FILE {{name}}.cabal #-} | |
name: {{name}} | |
version: 0.1.0.0 | |
build-type: Simple | |
cabal-version: >=1.10 | |
executable solution | |
hs-source-dirs: . | |
main-is: Main.hs | |
ghc-options: -threaded -rtsopts -with-rtsopts=-N |
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 org.specs2.mutable.Specification | |
import spray.http._ | |
import spray.routing._ | |
import spray.testkit.Specs2RouteTest | |
class AnyParamSpec extends Specification with Specs2RouteTest with Directives { | |
val route = anyParam('p ? "default") { p => complete(StatusCodes.OK, p) } | |
// replace with the following workaround | |
//val route = (anyParam('p) | provide("default")) { p => complete(StatusCodes.OK, p) } |
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 org.specs2.mutable.Specification | |
import spray.http.{HttpResponse, StatusCodes} | |
import spray.httpx.SprayJsonSupport | |
import spray.httpx.marshalling._ | |
import spray.httpx.unmarshalling._ | |
import spray.json._ | |
/*** | |
* scalaVersion := "2.11.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
object Parser { | |
val Result = """mac: (\S+) sites: \[([^]]+)\]""".r | |
def parseLine(line: String): Option[(String,Seq[String])] = line match { | |
case Result(mac,sites) => Some((mac, sites.split(""",\s*""").toSeq)) | |
case _ => None | |
} | |
} | |
val input = io.Source.fromFile("input.txt") | |
val lines = input.getLines() |
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
TaskKey[Unit]("copy-plugin-dependencies") <<= (update) map { | |
(updateReport) => | |
updateReport.select(Set("compile", "runtime")) map { jar => | |
import java.util.jar.{JarFile, Manifest => JarManifest} | |
val jarFile = new JarFile(jar) | |
val jarAttributes = jarFile.getManifest().getMainAttributes() | |
val targetdir = file("plugins") | |
if (!targetdir.exists) targetdir.mkdir() | |
else if (!targetdir.isDirectory) error("%s is not a directory".format(targetdir)) | |
for (bundleSymName <- Option(jarAttributes.getValue("Bundle-SymbolicName")); |
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
class ManagedReference[T](private[this] val createF: => T, private[this] val closeF: Option[T => Unit] = None) { | |
import java.util.concurrent.atomic.{ AtomicReference } | |
private[this] val ref = new AtomicReference[Option[T]](None) | |
def apply(): T = { | |
val opt = ref.get | |
val value = opt.getOrElse(createF) | |
// test if ref was set by another thread between ref.get and opt.getOrElse |