Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am andrewconner on github.
  • I am adc (https://keybase.io/adc) on keybase.
  • I have a public key whose fingerprint is 5ED1 9137 2BCA C7BC 5E5D 3806 7C3F 80BE DD1B CDBD

To claim this, I am signing this object:

implicit class AnyExtensionOps[A](val x: A) extends AnyVal {
def |>[B](f: A => B): B = f(x)
}
final class Lazily[A](f: () => A) {
private[this] var thunk: () => A = f
@volatile private var inst = false
private lazy val value: A = {
val r = thunk()
thunk = null // scalastyle:off
inst = true
r
}
def get: A = value
<?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;">
class Parent {
val a = 1
val b = a
}
class Kid extends Parent {
override val a = 100
}
new Kid().b // == 0
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")