Skip to content

Instantly share code, notes, and snippets.

View beranradek's full-sized avatar

Radek Beran beranradek

View GitHub Profile
object NonDefaultResources {
implicit object MySpecificUrlResource extends Resource[URL] {
// ...
}
}
def main(args: Array[String]) {
import NonDefaultResources.MySpecificUrlResource
println("Children of URL: \n: " +
// 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 {
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()
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 {
concurrent.Future {
// Nejaky blokujici kod pristupujici k databazi
}(Contexts.myDbOperationContext)
play {
my-db-context {
fork-join-executor {
parallelism-factor = 1.0
parallelism-max = 200
}
}
}
object Contexts {
implicit val myDbOperationContext: ExecutionContext =
Akka.system.dispatchers.lookup("my-db-context")
}
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)
}
}
}
import Contexts.myDbOperationContext
concurrent.Future {
// Nejaky blokujici kod pristupujici k databazi
}
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] {