Skip to content

Instantly share code, notes, and snippets.

@kastoestoramadus
kastoestoramadus / fileReporter
Created July 16, 2015 08:18
file logger com.codahale.metrics fix akka
// cancel sheduler and cloase file as one cancelable
private def fileLogger(): Cancellable with Object {def cancel(): Boolean; def isCancelled: Boolean} = {
val w = new BufferedWriter(new FileWriter(
s"../metrics_${TcpUtil.firstPartFromIp}_${numberOfClients}_${LocalTime.now()}.dat"))
val scheduled = context.system.scheduler.schedule(Config.STAT_PROBE_DURATION, Config.STAT_PROBE_DURATION) {
w.write( LineLog.toFileString(LocalTime.now(),
beats.getCount, fails.getCount, closings.getCount, receives.getCount, reconnects.getCount)+"\n")
w.flush()
}
@kastoestoramadus
kastoestoramadus / pwd_jdk7
Created July 16, 2015 08:12
pwd with jdk7
import java.nio.file.Paths
val pwd = Paths.get(".").toAbsolutePath().normalize().toString()
package pl.japila.scalania.s99
object S99_P03 {
def nth[T](k: Int, ts: List[T]): Option[T] = {
if (k > 0) ts match {
case a :: tail => nth(k - 1, tail)
case Nil => None
}
else if (k == 0) Some(ts.head)
else None
package pl.japila.scalania.s99
object S99_P02 {
def penultimate[T](ts: Seq[T]): T = ts match {
case a :: b :: Nil => Some(a)
case a:: tail => None
case _ => penultimate(ts.tail)
}
}