Skip to content

Instantly share code, notes, and snippets.

View ktoso's full-sized avatar
🗻
Life is Study!

Konrad `ktoso` Malawski ktoso

🗻
Life is Study!
View GitHub Profile
@ktoso
ktoso / eventsourced-example.scala
Created March 31, 2014 22:34
eventsourced processor example
case class ManyCommand(nums: List[Int])
case class State(count: Int) {
def updated(more: Int) = State(count + more)
}
sealed trait Event
case class AddOneEvent(num: Int) extends Event
class MultiCounter extends EventsourcedProcessor {
for {
item <- items
transformed = transform(item)
} yield transformed
// let's say you need a println
def print(a: Any) = { println(a); a }
for {
item <- items
@ktoso
ktoso / EventStreamAllMessages.scala
Last active January 3, 2016 20:29
raft testing with akka
/**
* Use for testing.
*
* Forwards all messages received to the system's EventStream.
* Use this to deterministically `awaitForLeaderElection` etc.
*/
trait EventStreamAllMessages {
this: Actor =>
override def aroundReceive(receive: Actor.Receive, msg: Any) = {
@ktoso
ktoso / 0_reuse_code.js
Created January 12, 2014 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
def writeAsync(persistentBatch: immutable.Seq[PersistentRepr]): Future[Unit]
def deleteAsync(processorId: String, fromSequenceNr: Long, toSequenceNr: Long, permanent: Boolean): Future[Unit]
def confirmAsync(processorId: String, sequenceNr: Long, channelId: String): Future[Unit]
// and "replay":
def replayAsync(processorId: String, fromSequenceNr: Long, toSequenceNr: Long)
(replayCallback: (PersistentRepr) => Unit): Future[Long]
import pl.project13.hadoop.scalding.NoJarTool
import com.twitter.scalding
import org.apache.hadoop.util.ToolRunner
import org.apache.hadoop.conf.Configuration
val conf = new Configuration
val masterIp = "10.0.0.1"
scala> :javap MongoDB
public class MongoDB$ extends java.lang.Object {
public static final MongoDB$ MODULE$; // actual instance of our `object`
public static {};
public MongoDB$();
// ...
}
@ktoso
ktoso / Unzipper.scala
Created June 20, 2013 10:22
unzipper
package tv.yap.common.zip
import collection.mutable
import java.util.zip.{ZipEntry, ZipFile}
import java.io._
import tv.yap.logging.Logging
import collection.JavaConversions._
import tv.yap.common.util.{TimedVerb, StreamOperations}
import org.apache.commons.io.{IOUtils, FilenameUtils}
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
// or even more plain:
testCases.foreach((case) -> {
// given
Object given = case.given;
Object expected = case.expected;
it.should("return [%s] when applied to [%s]", given, expected, system -> {
// when
Object got = system.doThing(given);