Skip to content

Instantly share code, notes, and snippets.

View yaroslav-ulanovych's full-sized avatar

Yaroslav Ulanovych yaroslav-ulanovych

View GitHub Profile
package foo
import java.util.concurrent.TimeUnit
import akka.actor.{ActorSystem, Props}
import akka.pattern.ask
import akka.persistence.{PersistentActor, RecoveryCompleted}
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import org.scalatest.{FunSuite, Matchers}
package foo
import java.util.concurrent.TimeUnit
import akka.actor.{ActorSystem, Props}
import akka.pattern.ask
import akka.persistence.{PersistentActor, RecoveryCompleted}
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import org.scalatest.{FunSuite, Matchers}
@yaroslav-ulanovych
yaroslav-ulanovych / weak-refs-and-lambdas.scala
Last active August 29, 2015 14:17
Proof that lambdas don't work with listeners on weak references.
package foo
import java.lang.ref.WeakReference
class Listeners[T] {
private var buffer = List[WeakReference[T => Unit]]()
def fire(e: T): Unit = {
buffer.map(_.get()).filter(_ ne null).foreach(_.apply(e))
buffer = buffer.filter(_.get() ne null)
classOf[String].getDeclaredMethods.map(_.getName).toSet[String].map(x => (x, math.abs(x.hashCode) % 256)).groupBy(_._2).toList.sortBy(_._1).map(x => s"${x._1}(${x._2.size}}): ${x._2.map(_._1).mkString(", ")}").foreach(println)
package foo
class Entity extends DelayedInit {
def delayedInit(x: => Unit) {x}
class Field
protected def EntityField[T <: Entity: Manifest] = new Field
package com.mahpella.snake.core
import collection.mutable
import scala.collection.mutable.{ListBuffer, ArrayBuffer}
import scala.util.control.Exception._
class Field(map: GameMap) extends Object with ClockDriven {
val width = map.width
val height = map.height
// any to json
Extraction.decompose(a: Any)(implicit formats: Formats): JValue
// json to case class
Extraction.extractOpt[A](json: JValue)(implicit formats: Formats, mf: Manifest[A]): Option[A]
// json to string
Printer.compact(d: Document): String
Printer.pretty(d: Document): String
JsonAST.render(value: JValue): Document
implicit def toEqualable[T](obj: T) = new {
def === (other: T): Boolean = {
obj == other
}
}