Skip to content

Instantly share code, notes, and snippets.

Avatar

Tim Harper timcharper

View GitHub Profile
@timcharper
timcharper / bayes.scala
Last active Aug 29, 2015
Functional Scala Implementation of Bayes Graph Solver (https://www.youtube.com/watch?v=pPTLK5hFGnQ)
View bayes.scala
#!/bin/sh
exec scala "$0" "$@"
!#
object Factor extends Enumeration {
val Econ = Value("Econ")
val Stock = Value("Stock")
}
import Factor._
View Main.scala
package main
import akka.stream.{ FlowMaterializer, MaterializerSettings }
import akka.stream.scaladsl.{Source,ForeachSink,FlowGraph,FlowGraphImplicits}
import akka.actor.ActorSystem
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
import scala.util.Try
object Main extends App {
View Main.scala
package main
import akka.actor.{Actor,ActorSystem, Props}
import akka.stream.scaladsl.Source
import akka.stream.FlowMaterializer
import scala.concurrent.Future
import scala.util.{Try,Success,Failure}
// import scala.Predef.identity
object Counter {
@timcharper
timcharper / company.el
Last active Aug 29, 2015
Some initializers
View company.el
(require 'company)
(global-company-mode t)
(global-set-key (kbd "s-;") 'company-dabbrev)
(global-set-key (kbd "s-:") 'company-complete)
(global-auto-complete-mode 0) ;; disable this!!! they fight eachother and it is annoying.
View MergeUnordered.scala
package m
import akka.actor.{ ActorSystem, Props, ActorRef }
import akka.stream.FlowMaterializer
import akka.stream.actor.{RequestStrategy, ActorPublisherMessage, ActorSubscriberMessage, ActorSubscriber, MaxInFlightRequestStrategy, ActorPublisher }
import akka.stream.scaladsl.{ Sink, Source }
import akka.stream.stage._
import scala.annotation.tailrec
import scala.collection.mutable.Queue
import scala.util.{Failure, Success}
@timcharper
timcharper / ack-via-helper.scala
Last active Aug 29, 2015
Akka-Stream-Acknowledgements
View ack-via-helper.scala
val source = Source(RabbitSource(
"Worker",
rabbitMq,
channel(qos = 100),
consume(topic("app.domain.class", topics = List(Pg.Table("MainTable").all, Pg.Table("RelatedTable").all))),
body(as[PgChange]).map(getPrimaryId)))
source.
map { case (p, primaryId) => Delivery(p, primaryId) }.
mapConcat { delivery =>
View acked-graph.scala
val input = (Stream.continually(Promise[Unit]) zip Range.inclusive(1, 5)).toList
implicit val materializer = ActorMaterializer()
val source = AckedSource(input)
val Seq(s1, s2) = (1 to 2) map { n => AckedSink.fold[Int, Int](0)(_ + _) }
val g = AckedFlowGraph.closed(s1, s2)((m1, m2) => (m1, m2)) { implicit b =>
(s1, s2) =>
View acked-stream-example.scala
// RabbitSource in op-rabbit v1.0.0-M9 returns an AckedSource
val source = RabbitSource(
"Worker",
rabbitMq,
channel(qos = 100),
consume(topic("app.domain.class", topics = List(Pg.Table("MainTable").all, Pg.Table("RelatedTable").all))),
body(as[PgChange]).map(getPrimaryId))
source.
collect { case Some(i) => i }.
View example.scala
// psuedo-code; will not actually compile
import com.spingo.op_rabbit.Json4sSupport._ // allows you to use Json4s directly to serialize / deserialize published messages
trait MarketOrEv
case class Market(mkt_id: Int, ev_id: Int, model_type:Market”) extends MarketOrEv
case class Ev(ev_id: Int, model_type:Ev”) extends MarketOrEv
You can’t perform that action at this time.