Instantly share code, notes, and snippets.

View Censor.scala
import ujson.{ Obj, Value }
object Censor{
def updateAll(root: Value, target: (String => Boolean), newValue: Value): Value = {
def update(value: Value, parent: Value = null, valueName: String = null): Unit = {
value match {
case Obj(values) => { case (name, v) => update(v, value, name) }
View FoldingValidationExamples.scala
import scala.util.{Failure, Try}
val li=List(1,2,3,4)
type Transform[F[_],A]=F[A] => F[A]
def filterSmall: Transform[Try,Int] ={ ti=>
ti.flatMap(i=>if (i>1) Try(i) else new Failure(new Exception(s"$i is too small")))

Keybase proof

I hereby claim:

  • I am fancellu on github.
  • I am fancellu ( on keybase.
  • I have a public key ASAIwD1-6lC-FAdHSUyefT5Xul7zEulj3OlQnMZ7uGYBtAo

To claim this, I am signing this object:

View TryFlatten.scala
import scala.util.{Success, Failure}
val seq=Seq(Success(1), Failure(new Exception("bang")), Success(2))
// all emit List(1, 2)
seq.collect{case Success(x) => x}
View .block
license: gpl-3.0
height: 600
View InfiniteStreamReceiver.scala
* Allows you to receive scala.collection.immutable.Stream
import org.apache.spark.streaming.receiver.Receiver
class InfiniteStreamReceiver[T](stream: Stream[T], delay:Int=0, storageLevel: StorageLevel) extends Receiver[T](storageLevel) {
View ES.scala
// Play 2.5 is not compatible with ES 5.x Java TCP, as ES demands Netty 4.1 vs Play's 4.0
import org.apache.http.HttpHost
import org.apache.http.entity.ContentType
import org.apache.http.nio.entity.NStringEntity
import org.apache.http.util.EntityUtils
import org.elasticsearch.client.RestClient
import play.api.libs.json.{Format, Json, Writes}
View Module.scala
import actors.ActorBrowserActor
import play.api.libs.concurrent.AkkaGuiceSupport
class Module extends AbstractModule with AkkaGuiceSupport{
def configure(): Unit = {
bindActor[ActorBrowserActor](ActorBrowserActor.NAME, _=>ActorBrowserActor.props)
View Module.scala
import actors.StartActorBrowser
class Module extends AbstractModule {
def configure(): Unit = {
View twirl.scala.html
@for((name, actor, status) <- actorsInfo) {
val camelCase=actorNameToCamelCase(name)
<td><a href={s"/actors/$camelCase"}>{camelCase}</a></td>