This file contains 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 com.besterdesigns.bootstrap | |
/** | |
* Case Class defining header and body for accordion object. | |
*/ | |
case class Collapsible(header: String, body: String) | |
object Accordion { | |
def apply(parentId: String) = new Accordion(parentId) | |
} |
This file contains 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
/** Custom lift-json serializer | |
* Why does ordering of JFields matter - surely this is not desirable as JSON is unordered | |
*/ | |
class MyUpdateSerializer extends Serializer[UpdateWrapper] { | |
private val UpdateClass = classOf[UpdateWrapper] | |
private val fmt = ISODateTimeFormat.dateTime() | |
def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), UpdateWrapper] = { | |
case (TypeInfo(UpdateClass, _), json) => { | |
println("update serializer got json "+json) |
This file contains 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
/* | |
* Simple DPI check of file | |
*/ | |
import javax.imageio.ImageIO | |
import org.w3c.dom.Element | |
import java.io.File | |
object CheckDPI extends App { | |
val file = new File("test.jpg") |
This file contains 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
//Loaner pattern to ensure closing of bufferedsource | |
... | |
def using[T](r: BufferedSource)(handler: BufferedSource => T): T = { | |
try { | |
handler(r) | |
} finally { | |
r.close() | |
} | |
} |
This file contains 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
setupStream () { | |
let evtSource = new EventSource("http://localhost:8082/events") | |
evtSource.addEventListener('myEvent', event => { | |
let data = JSON.parse(event.data) | |
this.now = data.msg | |
}, false) | |
evtSource.addEventListener('error', event => { | |
if (event.readyState == EventSource.CLOSED) { |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Vue/Akka/SSE</title> | |
</head> | |
<body> | |
<div id="app"> | |
<h1>{{ message }}</h1> | |
<span>SSE Date: {{ now }}</span> |
This file contains 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
const app = new Vue({ | |
el: '#app', | |
data: { | |
message: 'Vue/SSE Example!', | |
now: 'wait for it ...' | |
}, | |
created () { | |
this.setupStream() | |
}, | |
methods: { |
This file contains 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
lazy val (sourceQueue, eventsSource) = Source.queue[String](Int.MaxValue, OverflowStrategy.backpressure) | |
.delay(1.seconds, DelayOverflowStrategy.backpressure) | |
.map(message => ServerSentEvent(message, Some("myEvent"))) | |
.keepAlive(1.second, () => ServerSentEvent.heartbeat) | |
.toMat(BroadcastHub.sink[ServerSentEvent])(Keep.both) | |
.run() |
This file contains 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 com.besterdesigns.rest.services | |
import akka.actor.{ActorRef, ActorSystem} | |
import akka.http.scaladsl.model.StatusCodes | |
import akka.http.scaladsl.model.sse.ServerSentEvent | |
import akka.http.scaladsl.server.Directives._ | |
import akka.http.scaladsl.server.Route | |
import akka.http.scaladsl.server.directives.MethodDirectives.{get, post} | |
import akka.http.scaladsl.server.directives.PathDirectives.path | |
import akka.http.scaladsl.server.directives.RouteDirectives.complete |
This file contains 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 com.besterdesigns.actors | |
import java.util.Calendar | |
import _root_.akka.actor.{Actor, Props} | |
import _root_.akka.stream.scaladsl.SourceQueueWithComplete | |
import com.besterdesigns.models.Json4sFormat | |
import scala.concurrent.duration._ | |
case object StartClock |
OlderNewer