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
| def compile(): List[CompiledScript] = { | |
| val outputCache = directory / ".cache" | |
| if(!outputCache.exists()) outputCache.mkdirs() | |
| val engine: IMain = new ScriptEngineManager().getEngineByName("scala").asInstanceOf[IMain] | |
| engine.settings.usejavacp.value = true | |
| // TODO: This breaks things. No idea why. | |
| // engine.settings.outdir.value = outputCache.getCanonicalPath | |
| directory.listFiles().toList collect { |
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 com.wieck.base | |
| package controllers | |
| import play.api.{Application, Play, mvc, i18n}, mvc._, i18n._ | |
| abstract class ApplicationController extends Controller { | |
| private val messagesApiCache = Application.instanceCache[BaseMessagesApi] | |
| implicit def messages(implicit lang: Lang): Messages = new Messages(lang, messagesApiCache(Play.current)) | |
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
| trait I18nComponents { | |
| def environment: Environment | |
| def configuration: Configuration | |
| // NOTE line 10! Load subproject messages, and override with available root project messages. | |
| lazy val messagesApi: MessagesApi = new DefaultMessagesApi(environment, configuration, langs) { | |
| override protected def loadAllMessages: Map[String, Map[String, String]] = { | |
| langs.availables.map(_.code).map { lang => | |
| (lang, loadMessages("messages.mysubproject." + lang) ++ loadMessages("messages." + lang)) |
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
| val firstLove = future { | |
| Thread.sleep(500) | |
| "i love you" | |
| } | |
| val thenBetray = firstLove map { | |
| case loveLetter => { | |
| Console.println(loveLetter) | |
| Thread.sleep(500) | |
| "not really" | |
| } |
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 class PhotoListItem(title: Option[String], filename: Option[String]) { | |
| // Not bad: | |
| def displayTitle(implicit messages: Messages): String = { | |
| (title, filename) match { | |
| case (Some(title), _) => title // So I want the title if present. | |
| case (_, Some(filename)) => filename // Fallback to filename. | |
| case _ => messages("label.titleNotAvailable") // Otherwise return a canned message. | |
| } | |
| } |
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 class Contains(test: String) { | |
| def unapply(list: List[_]): Boolean = list contains test | |
| } |
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 helpers { | |
| type Closeable = { def close() } | |
| def using[T, S <: Closeable](source: S)(f: S => T) = { | |
| val result = f(source) // Simplified for the example. | |
| source.close() | |
| result | |
| } | |
| } |
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 Job extends Actor { | |
| def receive = idle | |
| def idle: Receive = { | |
| case Parse(_uri) => | |
| uri = _uri | |
| requestor = context.sender() | |
| sources ! Open(_uri) |
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
| trait Parser { self: Actor => | |
| def parse: PartialFunction[Opened, Unit] | |
| def receive: Receive = parse orElse(super.receive) andThen(_ => done()) | |
| def collectWork: Receive | |
| def done(): Unit = { | |
| context become collectWork |
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._ | |
| object Scraper { | |
| def props = Props[Scraper] | |
| } | |
| class Scraper extends Actor with ActorLogging with Unhandled { | |
| import MigrationProtocol._ |