Skip to content

Instantly share code, notes, and snippets.

View joesan's full-sized avatar
🎯
Focusing

Joesan joesan

🎯
Focusing
View GitHub Profile
@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 =>
find . | grep .git | xargs rm -rf
@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 {
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
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
})
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()} >>")
}
@joesan
joesan / WiFiConnector.scala
Last active February 2, 2017 21:15
Programatic WiFi Connectivity
object WiFiConnector extends App {
if (System.getProperty("os.name").contains("Mac"))
scanMac()
else
scanWindows()
def scanWindows() = {
val builder = new ProcessBuilder(
@joesan
joesan / sbt-utilities
Created May 15, 2017 20:59
Ignore Tests when Running SBT
sbt 'set test in Test := {}' clean assembly
@joesan
joesan / docker_build.sh
Last active January 2, 2023 10:11
Scala script from within a Bash
#!/bin/sh
exec scala "$0" "$@"
!#
/***
scalaVersion := "2.11.11"
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.1"
)
@joesan
joesan / linecounter
Created August 22, 2017 05:32
Count the Number of lines in a recursive way
find . -name "*.scala" -print | xargs wc -l