This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [info] play - Application started (Dev) | |
| [debug] s.s.s.BaseSession - Preparing statement: select x2."id", x2."name", x2."started", x2."patient_id" from "problems" x2 where x2."patient_id" = 1 | |
| [debug] s.s.s.BaseSession - Preparing statement: select x2."id", x2."problem_id", x2."patient_id", x2."description", x2."date", x2."error" from "evolutions" x2 where x2."patient_id" = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var coso = (function() { | |
| var that = {}; | |
| function privada() { | |
| } | |
| that.publica = function() { | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package model | |
| import scala.concurrent._ | |
| import scala.concurrent.duration._ | |
| import play.libs.Akka | |
| import play.api.libs.concurrent.Execution.Implicits._ | |
| object TimeoutFuture { | |
| def apply[A](timeout: FiniteDuration)(block: => A): Future[A] = { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.zeromq.ZMQ; | |
| // | |
| // Reading from multiple sockets in Java | |
| // This version uses a simple recv loop | |
| // | |
| public class msreader { | |
| public static void main (String[] args) throws Exception { | |
| // Prepare our context and sockets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sbt._ | |
| import Keys._ | |
| import play.Project._ | |
| object ApplicationBuild extends Build { | |
| val appName = "firehose" | |
| val appVersion = "1.0-SNAPSHOT" | |
| val appDependencies = Seq( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enumeratee transforms a stream from type A to B. | |
| // It only needs you to specify the A type, it can infer B (in this case JsValue) | |
| val json = Enumeratee.map[StatusUpdate] { status => Json.toJson(status)} | |
| // Now `jsonStream` is a stream of JsValue! :D | |
| val jsonStream = stream.through(json) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import play.api.libs.json._ | |
| // We need to make an implicit `Writes` for our StatusUpdate class available. | |
| // Play can convert any case class into a JsValue, using macros. | |
| implicit private val StatusWrites = Json.writes[StatusUpdate] | |
| val status = StatusUpdate(user = "pablo", update = "serialize this") | |
| val json = Json.toJson(status) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Stacktrace | |
| [error] /Users/pfernand/projects/firehose/app/controllers/Application.scala:31: Cannot write an instance of model.StatusUpdate to HTTP response. Try to define a Writeable[model.StatusUpdate] | |
| [error] SimpleResult(header, stream) | |
| [error] ^ | |
| [error] one error found | |
| [error] (compile:compile) Compilation failed | |
| [error] Total time: 5 s, completed May 26, 2013 10:37:05 PM | |
| # The message without the noise: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Our controller method. | |
| def firehose = Action { | |
| // Http headers, we sent the Content-Length to -1 since this is a stream and will never end. | |
| // We also set Connection: close to explicit that the connection should not be reused. | |
| val headers = Map("Content-Length" -> "-1", "Connection" -> "close","Content-Type" -> "application/json") | |
| val header = ResponseHeader(200, headers) | |
| // Return the header + our Enumerator[StatusUpdate] | |
| SimpleResult(header, stream) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Create some updates. | |
| val statuses = Array( | |
| StatusUpdate("pablo", "Are stream updates cool or what?"), | |
| StatusUpdate("hn_comments", "Nice tutorial!"), | |
| StatusUpdate("fake_profile", "lorem ipsum bla bla bla bla."), | |
| StatusUpdate("funes_mori", "please kill me before next match.") | |
| ) | |
| // Use Play's scheduler to send them (actually Akka, but it's an implementation detail). | |
| // We send roughly 20 updates/second. The first number (0.seconds) is |