Skip to content
View NgramExtractor.scala
object Boot extends App {
val extractor = new SentenceAnalyzer
with NGramExtraction
with Unigrams
with Bigrams
with Trigrams
val sentences = Source.fromInputStream(getClass.getResourceAsStream("/input.txt")).getLines().toIterable
println(extractor.analyze(sentences))
}
View CombinerBase.scala
def ~>[Out](junction: UniformFanInShape[T, Out])(implicit b: Builder[_]): PortOps[Out, Unit] = {
def bind(n: Int): Unit = {
if (n == junction.inSeq.length)
throw new IllegalArgumentException(s"no more inlets free on $junction")
else if (b.module.upstreams.contains(junction.in(n))) bind(n + 1) // it's already part of the graph
else b.addEdge(importAndGetPort(b), junction.in(n)) // b.add(), add it to the graph
}
bind(0)
junction.out
}
View ProposalOfImplicitAddToGraph.scala
val src = Source.actorRef[ByteString](1000, OverflowStrategy.dropHead)
FlowGraph.closed(src) { implicit builder =>
byteStringSource =>
import FlowGraph.Implicits._
// for junctions / fan-in / fan-out shapes we need to builder.add explicitly
// val broadcaster = builder.add(Broadcast[String](2))
val broadcaster: UniformFanOutShape[String,String] = Broadcast[String](2) // builder.add is done implicitly
View Flows.scala
val src = Source.actorRef[ByteString](1000, OverflowStrategy.dropHead)
FlowGraph.closed(src) { implicit builder =>
byteStringSource =>
import FlowGraph.Implicits._
// for junctions / fan-in / fan-out shapes we need to builder.add explicitly
val broadcaster = builder.add(Broadcast[String](2))
// for Flows builder.add is implicit, if I'm not mistaking
View Build.scala
object ApplicationBuild extends Build {
val appName = "my-app"
val appVersion = "1-SNAPSHOT"
val appDependencies = Seq(
jdbc,
cache
)
val main = play.Project(appName, appVersion, appDependencies)
View SetCharacterEncodingFilter.java
package nl.ibanx.web.filter;
import java.io.IOException;
import javax.servlet.*;
/**
* Set the character encoding of the request to UTF-8.
*/
public class SetCharacterEncodingFilter implements Filter {
View JsonUtil.scala
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
object JsonUtil {
val mapper = new ObjectMapper with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
def toJson(value: Map[Symbol, Any]): String = {
View Build.scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "tweetsearch"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
View posts_router.js.coffee
class Blog.Routers.PostsRouter extends Backbone.Router
routes:
"posts/:page" : "index"
".*" : "index"
index: (page) ->
pageNumber = page || 1
@posts = new Blog.Collections.PostsCollection()
@view = new Blog.Views.Posts.IndexView({model:@posts, page:parseInt(pageNumber)+1})
View index.html.erb
<div id="posts"></div>
<script type="text/javascript">
$(function() {
// Blog is the app name
window.router = new Blog.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
Something went wrong with that request. Please try again.