This file contains 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 NonDefaultResources { | |
implicit object MySpecificUrlResource extends Resource[URL] { | |
// ... | |
} | |
} | |
def main(args: Array[String]) { | |
import NonDefaultResources.MySpecificUrlResource | |
println("Children of URL: \n: " + |
This file contains 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
// Ad 1) Type class trait ("utility" rozhraní, na které budou | |
// adaptovány konkrétní zdroje): | |
trait Resource[R] { | |
def hasChildren(res: R): Boolean | |
def children(res: R): Seq[R] | |
} | |
// Ad 2) Companion object s výchozími implicitními implementacemi | |
// type class traitu pro URL a File: | |
object Resource { |
This file contains 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.examples.img | |
import java.io.File | |
import scala.sys.process._ | |
class ImageMagickConverter(convertExec: String) { | |
def resizeImage(in: File, out: File, width: Int, height: Int, quality: Int = ImageMagickConverter.DefaultQuality): Boolean = { | |
val qual = if (quality < 0) ImageMagickConverter.DefaultQuality else if (quality > 100) 100 else quality | |
val inAbsPath = in.getAbsolutePath() |
This file contains 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 controllers | |
import play.api.mvc.Action | |
import play.api.mvc.Controller | |
import scala.concurrent.future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import play.api.Logger | |
object Performance extends Controller { |
This file contains 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
concurrent.Future { | |
// Nejaky blokujici kod pristupujici k databazi | |
}(Contexts.myDbOperationContext) |
This file contains 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
play { | |
my-db-context { | |
fork-join-executor { | |
parallelism-factor = 1.0 | |
parallelism-max = 200 | |
} | |
} | |
} |
This file contains 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 Contexts { | |
implicit val myDbOperationContext: ExecutionContext = | |
Akka.system.dispatchers.lookup("my-db-context") | |
} |
This file contains 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 play.api.libs.concurrent.Execution.Implicits._ | |
def someAsyncAction = Action { | |
Async { | |
WS.get("http://www.someservice.com").get().map { | |
response => | |
Ok("Response code: " + response.status) | |
} | |
} | |
} |
This file contains 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 Contexts.myDbOperationContext | |
concurrent.Future { | |
// Nejaky blokujici kod pristupujici k databazi | |
} |
This file contains 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 dojo | |
import java.net.URL | |
import java.io.File | |
import scala.io.Source | |
import java.io.InputStream | |
import scala.util.Try | |
import scala.util.Success | |
trait Resource[R] { |
NewerOlder