Skip to content

Instantly share code, notes, and snippets.

View theon's full-sized avatar

Ian Forsey theon

View GitHub Profile
import akka.actor.ActorSystem
import akka.testkit.{TestActorRef, EventFilter, TestKit}
import org.scalatest.{BeforeAndAfterAll, WordSpecLike}
class FailingTest
extends TestKit(ActorSystem("MyActorTest"))
with WordSpecLike
with BeforeAndAfterAll {
override def afterAll() {
import akka.actor.ActorSystem
import akka.testkit.{TestActorRef, EventFilter, TestKit}
import org.scalatest.{OneInstancePerTest, BeforeAndAfterAll, WordSpecLike}
class PassingTest
extends TestKit(ActorSystem("MyActorTest"))
with WordSpecLike
with BeforeAndAfterAll
with OneInstancePerTest {
@theon
theon / PrecannedExample.scala
Created January 28, 2014 11:36
Pre-canned example
import com.netaporter.precanned.dsl.fancy._
val animalApi = httpServerMock(system).bind(8766)
animalApi expect
get and path("/animals") and query("name" -> "giraffe") and
respond using
resource("/responses/giraffe.json") end()
import scala.io.Source
val reverseLetters = ( ('a' to 'z') zip ('a' to 'z').reverse ).toMap.withDefault(identity)
val words = Source.fromFile("/usr/share/dict/words").getLines.toVector
def isWordMatch(word: String) = {
val reverseLetterWord = word.toLowerCase.map(reverseLetters)
reverseLetterWord.reverse == word
}
@theon
theon / snakes_and_ladders.scala
Created April 8, 2019 19:27
My son's copy of Snakes and Ladders. Looks like worse case game would be 480ish turns XD
val snakes = Map(
16 -> 6,
47 -> 26,
49 -> 11,
56 -> 53,
62 -> 18,
64 -> 60,
87 -> 24,
92 -> 72,
95 -> 75,
// GAME ENGINE
trait View[A] {
protected def update(before: A, after: A): Unit
def onModelChange(before: A, after: A): Unit =
if(before != after) {
update(before, after)
}