Skip to content

Instantly share code, notes, and snippets.

@leogrim
leogrim / InjectorProvider.scala
Created July 23, 2013 04:51
Dependency Injection and Testing at FortyTwo Inc.More in our blog post: "Lightweight Testing with Custom Guice Injectors" http://eng.kifi.com/lightweight-testing-with-custom-guice-injectors/
package com.yourApplication.inject
import com.google.inject._
import net.codingwell.scalaguice.InjectorExtensions.ScalaInjector
import net.codingwell.scalaguice.ScalaModule
import com.google.inject.util.Modules
import play.api.Mode._
import play.api.Mode
import java.util.concurrent.atomic.AtomicBoolean
@leogrim
leogrim / IO.scala
Created February 14, 2014 01:31
IO Helpers - Automated Backup and Restoration of Lucene Indices with Amazon S3 - http://eng.kifi.com/automated-backup-and-restoration-of-lucene-indices-with-amazon-s3/
import java.io._
import java.util.zip.{GZIPInputStream, GZIPOutputStream}
import org.apache.commons.compress.archivers.tar.{TarArchiveInputStream, TarArchiveEntry, TarArchiveOutputStream}
import org.apache.commons.io.{IOUtils, FileUtils}
object IO {
def addToArchive(tarArchive: TarArchiveOutputStream, file: File, base: String = ""): Unit = {
val entryName = base + file.getName
val entry = new TarArchiveEntry(file, entryName)
import scala.reflect.runtime.universe._
import scala.util.{Failure, Success, Try}
object CompanionTypeSystem {
def apply[SealedClass: TypeTag, Companion: TypeTag](fBoundedType: String): Set[Companion] = {
val sealedClassType = typeOf[SealedClass]
val companionType = typeOf[Companion]
val upperBound = sealedClassType
val refineCompanionWithTypeParameter = getTypeWithTypeParameterOrElseCheckTypeMember(companionType, fBoundedType, upperBound, isSelfRecursive = false)
Verifying that +leogrim is my blockchain ID. https://onename.com/leogrim
class ServiceAModule extends ScalaModule {
def configure() {
bind[ClassC].to[CommonImplementation]
bind[ClassA].to[ImplementationA]
}
def classDProviderForServiceA: ClassD = serviceAInstanceOfClassD
}
class ServiceBModule extends ScalaModule {
def configure() {
val devModule = Modules.override(
Modules.override(ServiceAModule).`with`(ServiceBModule)
).`with`(CommonDevelopmentModule)
val serviceATestModule = Modules.override(ServiceAModule).`with`(FakeClassAModule)
class ConfigurationModule(functionalModules: ScalaModule*) extends ScalaModule with Logging {
final def configure() {
log.info(s"Configuring ${this}")
functionalModules.foreach { module =>
log.info(s"Install ${module}")
install(module)
}
}
}
case class FunctionalModuleAInProduction extends FunctionalModuleA {
def configure() {
bind[ClassA].to[ImplementationA]
}
}
case class FunctionalModuleAInDevelopment extends FunctionalModuleA {
def configure() {
bind[ClassA].to[FakeImplementationA]
}
MyTest extends Specification {
"My feature" should {
"do something" in {
test block
}
}
}