Skip to content

Instantly share code, notes, and snippets.

View joesan's full-sized avatar
🎯
Focusing

Joesan joesan

🎯
Focusing
View GitHub Profile
class MyObserver(actorRef: ActorRef, sourceName: String)
(implicit s: Scheduler) extends Subscriber[String] {
private[this] def logger = LoggerFactory.getLogger(this.getClass)
override implicit def scheduler: Scheduler = s
override def onError(ex: Throwable): Unit = {
logger.error(s"error happened when processing the stream: error message << ${ex.printStackTrace()} >>")
}
override def unsafeSubscribeFn(subscriber: Subscriber[String]): Cancelable = {
val bufferedObs = Observable.fromLinesReader(bufferedReader)
val obs1 = Observable.interval(1.second)
.flatMap(elem => {
val out = new PrintStream(socket.getOutputStream)
out.print(s"test$elem\n")
out.flush()
bufferedObs
})
package my.samples.deviceManager
import akka.actor.{Actor, ActorLogging, ActorRef, Kill, Props, Terminated}
import akka.io.IO
import akka.util.ByteString
import ch.jodersky.flow.Serial.Command
import ch.jodersky.flow.{Parity, Serial, SerialSettings}
import my.samples.deviceManager.DeviceExplorerActor.DeviceSerialNumber
import my.samples.deviceManager.DeviceWatcherActor.InitializeSerialPort
@joesan
joesan / DeviceExplorerActor.scala
Last active January 5, 2017 15:16
Akka Flow Serial Actor Example
import akka.actor.{Actor, ActorRef, Props, Terminated}
import akka.util.ByteString
import ch.jodersky.flow.Serial
import com.typesafe.scalalogging.LazyLogging
import my.samples.deviceManager.DeviceWatcherActor.InitializeSerialPort
class DeviceExplorerActor(serialActorRef: ActorRef)
extends Actor with LazyLogging {
find . | grep .git | xargs rm -rf
@joesan
joesan / gist:203d8a33726c29caead08a01eea98537
Created May 28, 2016 11:42
String K-Reduction implemented in Scala
val input = "abccaaaba" // cccaaaba -> ccbaaba -> caaaba -> baaba -> caba -> bba -> bc -> a
val distinctChars = input.distinct.sorted.toList
@tailrec
def reduceString(acc: List[Char], seq: List[Char]): List[Char] = seq match {
case Nil =>
if (acc.toSet.size == 1) acc
else reduceString(List.empty[Char], acc)
case x :: Nil =>