Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
trait DbConnection {
def readOnly(): Connection
def readWrite(): Connection
}
class PostgresDbConnection extends DbConnection {
def readOnly() = PostgresDbHandler.getReadOnlyConnection()
def readWrite() = PostgresDbHandler.getReadWriteConnection()
}
package common.modules
import com.tzavellas.sse.guice.ScalaModule
import common.translation._
class ProdModule extends ScalaModule {
def configure() {
bind[Translator].to[FrenchTranslatorImpl]
}
}
object Global extends GlobalSettings {
private lazy val injector = {
Play.isProd match {
case true => Guice.createInjector(new ProdModule)
case false => Guice.createInjector(new DevModule)
}
}
override def getControllerInstance[A](clazz: Class[A]) = {
injector.getInstance(clazz)
package controllers
import play.api._
import play.api.mvc._
import common.translation.Translator
import com.google.inject._
@Singleton
class Translate @Inject()(translator: Translator) extends Controller {
def greet(name: String) = Action {
class TranslateSpec extends Specification {
"Translate" should {
// The normal Play! way
"accept a name, and return a proper greeting" in {
running(FakeApplication()) {
val translated = route(FakeRequest(GET, "/greet/Barney")).get
status(translated) must equalTo(OK)
contentType(translated) must beSome.which(_ == "text/html")
def timer(f: => Any): Long = {
val startTime = System.nanoTime
val ret = f
val endTime = System.nanoTime
endTime - startTime
}
def iterTest(f: => Any): Double = {
(for(i <- 0 to 10000) yield timer(f)).sorted.apply(5000)
trait Translator {
def translate(input: String): String
}
class FakeTranslator extends Translator {
def translate(input: String): String = input
}
class FrenchTranslatorImpl extends Translator {
val wordReplacements = Map(
trait Translator {
def translate(input: String): String
}
class FrenchTranslatorImpl extends Translator {
val wordReplacements = Map(
"hello" -> "bonjour",
"hi" -> "salut",
"greetings" -> "salutations"
)
$ curl -i http://www.42go.com/ | grep Server
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4425 100 4425 0 0 79467 0 --:--:-- --:--:-- --:--:-- 149k
Server: Don't Panic!