This file contains hidden or 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
#!/usr/bin/python2.7 -tt | |
# -*- coding: utf-8 -*- | |
""" | |
File Util | |
~~~~~~ | |
File and Directory util functions for common use. | |
:copyright: (c) 2013 by Diego T. Balduini. | |
:license: BSD, see LICENSE for more details. |
This file contains hidden or 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
class CacheSupervisorActor extends Actor with ActorLogging { | |
import CacheSupervisorActor._ | |
val cache = context.actorOf(Props[CacheHotSwapActor]) | |
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { | |
case e: ActorInitializationException => cache ! Memcached; Restart // When redis fails to connect, try memcached | |
case e: IllegalStateException => Stop // When memcached fails to connect | |
} |
This file contains hidden or 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 plugins | |
import play.api.Application | |
import play.api.cache.CachePlugin | |
import play.api.cache.CacheAPI | |
import play.Play.{application => App} | |
import scala.concurrent.Await | |
import scala.concurrent.duration.DurationInt |
This file contains hidden or 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 plugins | |
import net.spy.memcached.ConnectionFactoryBuilder.Protocol | |
import net.spy.memcached.auth.{PlainCallbackHandler, AuthDescriptor} | |
import play.api.{PlayException, Application} | |
import play.api.cache.CachePlugin | |
import play.api.cache.CacheAPI | |
import net.spy.memcached._ | |
import net.spy.memcached.transcoders.{SerializingTranscoder, Transcoder} |
This file contains hidden or 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
/** | |
* | |
* Statefull File Streaming class that write files with java.nio. | |
* | |
*/ | |
class FileStreaming(filename: String) { | |
val output = new java.io.File(ApplicationConf.outputDir, filename) | |
output.createNewFile() |
This file contains hidden or 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 akka.actor.{ActorLogging, Terminated, ActorRef, Actor} | |
import scala.collection.mutable | |
object Reaper { | |
case class WatchMe(ref: ActorRef) | |
} | |
class Reaper extends Actor with ActorLogging { | |
import Reaper._ |
This file contains hidden or 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
// src/test/scala/ | |
package integration.config | |
class CleanUpHook { | |
//DBs.closeAll() | |
println("CleanUpHook => Connection Closed!") | |
} | |
// build.sbt | |
testOptions in Test += Tests.Cleanup( (loader: java.lang.ClassLoader) => { |
This file contains hidden or 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
// The straightforward, but very slow version | |
def levenshteinDistance(a: String, b: String): Int = { | |
val aLen = a.length | |
val bLen = b.length | |
def minimum(x: Int, y: Int, z: Int) = Math.min(Math.min(x, y), z) | |
def max(i: String, j: String) = if (i >= j) i else j | |
def min(i: String, j: String) = if (i <= j) i else j | |
def cost = if (aLen - 1 == bLen - 1) 0 else 1 | |
if (min(a, b).length == 0) max(a, b).length |
This file contains hidden or 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 scala.concurrent.duration.FiniteDuration | |
import scala.concurrent.duration.{Duration => ScalaDuration} | |
import org.specs2.time.{Duration => Specs2Duration} | |
import org.specs2.time.TimeConversions._ | |
import java.util.concurrent.TimeUnit | |
object DurationBridge { |
This file contains hidden or 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 io.react2.reactdynamo._ | |
import io.react2.reactdynamo.exceptions.ReadsException | |
import org.joda.time.{Period, DateTime} | |
import org.joda.time.format.ISODateTimeFormat | |
trait MyDefaultFormats { | |
val fmt = ISODateTimeFormat.dateTime | |
implicit object DateTimeWrites extends Writes[DateTime] { |
OlderNewer