Skip to content

Instantly share code, notes, and snippets.

@yutaono
yutaono / gist:7c8297ce08c63878973b
Created April 28, 2015 07:41
stackable trait pattern
// stackable trait pattern
// http://www.artima.com/scalazine/articles/stackable_trait_pattern.html
abstract class IntQueue {
def get: Int
def put(x: Int)
}
import scala.collection.mutable.ArrayBuffer
@yutaono
yutaono / gist:9bca8e5c27018389a88c
Last active August 29, 2015 14:20
Marcov chain
trait State {
import State._
val seq: Seq[(Double, State)]
def next: State =
(seq sortWith { (s1, s2) =>
(s1._1 * randValue) > (s2._1 * randValue)
}).head._2
@yutaono
yutaono / gist:b4c28359905d8f016443
Last active August 29, 2015 14:21
Aerospike Int Long Spec: Aerospikeのjava clientで値の範囲によって自動的に型が変更される仕様の確認
import com.aerospike.client.policy.ClientPolicy
import com.aerospike.client.{AerospikeClient, Bin, Key}
object AerospikeIntLongSpec extends App {
val policy = new ClientPolicy
policy.user = ""; policy.password = ""
val client = new AerospikeClient(policy, "127.0.0.1", 3000)
val (keyName, binName) = ("budget", "spend")
sealed trait Animal
case class Dog(name: String) extends Animal
case class Cat(name: String) extends Animal
val dogs = List(Dog("pochi"), Dog("gon"))
val cats = List(Cat("tama"), Cat("kuro"))
val animals: List[Animal] = List(dogs, cats).flatten
@yutaono
yutaono / build.sbt
Created October 5, 2016 17:09
simple build sbt
name := "demoProject"
version := "1.0"
scalaVersion := "2.11.8"