Skip to content

Instantly share code, notes, and snippets.

View duanebester's full-sized avatar

Duane Bester duanebester

View GitHub Profile
@duanebester
duanebester / VeryBigSum.scala
Created July 4, 2015 20:02
Hacker Rank Warmup - Very Big Sum
//
// Code for: https://www.hackerrank.com/challenges/a-very-big-sum
//
object Solution {
def main(args: Array[String]) {
val num = readInt()
// See if number is positive or negative
@duanebester
duanebester / find-usb-windows.go
Last active October 1, 2015 23:23
Enter your USB Vendor ID and print the "Friendly Name"
package main
/*
#cgo LDFLAGS: -lSetupapi
#ifdef __MINGW32__
#include <ntdef.h>
#endif
#include <windows.h>
#include <setupapi.h>
@duanebester
duanebester / ObjectIdSerialization.scala
Last active December 11, 2015 21:04
Spray Json to Reactive Mongo ObjectId
import spray.json.DefaultJsonProtocol
/**
* Created by duane on 12/11/2015.
*/
trait ObjectIdSerialization extends DefaultJsonProtocol {
import reactivemongo.bson.BSONObjectID
import spray.json._
@duanebester
duanebester / svg2png.sh
Created February 10, 2018 13:58
Svg to Png for React Native asset conversion
#!/bin/sh
rsvg-convert -v > /dev/null 2>&1 || { echo "rsvg-convert is not installed, use: brew install librsvg." >&2; exit 1; }
ASSETS_FOLDER=$1
if [ "$ASSETS_FOLDER" == "" ]; then
echo "Usage: $0 /path/to/svg/assets/" >&2
exit 1
fi
trait OCR {
val tesseract: Tesseract = new Tesseract
tesseract.setDatapath("/usr/local/Cellar/tesseract/3.05.01/share/")
}
// Dependencies
libraryDependencies += "net.sourceforge.tess4j" % "tess4j" % "4.0.0"
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.12"
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.1.1"
libraryDependencies += "com.typesafe.akka" %% "akka-http-spray-json" % "10.1.1"
// Plugins
addSbtPlugin("org.bytedeco" % "sbt-javacv" % "1.16")
object Main extends App with OCR {
implicit val system: ActorSystem = ActorSystem("ocr")
implicit val executor: ExecutionContextExecutor = system.dispatcher
implicit val materializer: ActorMaterializer = ActorMaterializer()
implicit val jsonStreamingSupport = EntityStreamingSupport.json()
import MyJsonProtocol._
def imageDeSkew:Flow[BufferedImage] = ???
def imageToBinaryImage:Flow[BufferedImage] = ???
def bufferedImageToMat:Flow[BufferedImage] = ???
def imageToBinaryImage = Flow[BufferedImage].map(img => {
val bin = ImageHelper.convertImageToBinary(img)
bin
})
def imageDeSkew(skewThreshold:Double = 0.05) = Flow[BufferedImage].map(bi => {
val deSkew = new ImageDeskew(bi)
val imageSkewAngle = deSkew.getSkewAngle
if (imageSkewAngle > skewThreshold || imageSkewAngle < -skewThreshold) {
ImageUtil.rotate(bi, -imageSkewAngle, bi.getWidth() / 2, bi.getHeight() / 2)
} else {
bi
}
})
val route =
path("image" / "process") {
post {
fileUpload("fileUpload") {
case (_, fileStream) =>
val inputStream = fileStream.runWith(StreamConverters.asInputStream())
val image: BufferedImage = ImageIO.read(inputStream)
val preProcessed: Source[ByteString, NotUsed] = Source
.single(image)