Skip to content

Instantly share code, notes, and snippets.

View Softsapiens's full-sized avatar

Daniel Pous Montardit Softsapiens

View GitHub Profile
val e1: Enumeratee[String, String] = ...
val e2: Enumeratee[String, String] = ...
val e3: Enumeratee[String, String] = ...
val iteratee: Iteratee[String, String] = ...
// Compose the 3 Enumeratees together and apply the result to
// the Iteratee to get a new Iteratee
val filteredIteratee = e1 ><> e2 ><> e3 &> iteratee
object Socket extends Controller {
def connect = WebSocket.using[String] { request =>
Logger.info("Someone just connected!")
Concurrent.joined[String]
}
}
implicit def onClick(handler: View => Unit) = new OnClickListener() {
override def onClick(source: View) = handler(source)
}
import java.util.{Timer, TimerTask}
import scala.concurrent.duration._
import rx.lang.scala.{Observable, Observer, Subscription, Scheduler}
import rx.lang.scala.observables.ConnectableObservable
import rx.lang.scala.subscriptions.{CompositeSubscription, MultipleAssignmentSubscription}
import rx.lang.scala.schedulers.NewThreadScheduler
object RxExplorations{
implicit class SchedulerOps(val s: Scheduler) extends AnyVal {
package com.codetinkerhack
import akka.actor.{ ActorRef, Props, Actor, ActorLogging }
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import akka.actor.Actor.Receive
import akka.pattern.pipe
import scala.util.Success
import scala.util.Failure
scala> :paste
// Entering paste mode (ctrl-D to finish)
case class Address(street : String, city : String, postcode : String)
case class Person(name : String, age : Int, address : Address)
// Exiting paste mode, now interpreting.
defined class Address
defined class Person
scala> import syntax.typeable._
import syntax.typeable._
scala> val wat: Any = List(1, 2, 3, 4)
wat: Any = List(1, 2, 3, 4)
scala> wat.cast[List[Int]].map(_.sum)
res0: Option[Int] = Some(10)
scala> val wat2: Any = "foo"
// Run this with scala <filename>
/**
* A Two-phase commit Monad
*/
trait Transaction[+T] {
def map[U](fn: T => U): Transaction[U] = flatMap { t => Constant(fn(t)) }
def flatMap[U](fn: T => Transaction[U]): Transaction[U] =
FlatMapped(this, fn)
package demo
// Adapted from Jonas Bonér's example https://gist.github.com/jboner/9990435
import akka.actor.{Props, ActorSystem}
import akka.persistence.{EventsourcedProcessor, SnapshotOffer}
object PersistedPingPong extends App {
case object Ball //The Command
// Sample usage of ...
// - Dispatch (http://dispatch.databinder.net)
// - SJSON (https://github.com/debasishg/sjson)
// ... to create a basic REST Web Service client for Twitter API
import dispatch._
import scala.reflect.BeanInfo
import sjson.json.Serializer.SJSON
// Model