Skip to content

Instantly share code, notes, and snippets.

View abdolence's full-sized avatar

Abdulla Abdurakhmanov abdolence

View GitHub Profile
import $ivy.`com.github.pemistahl:lingua:1.0.1`, com.github.pemistahl.lingua.api._, com.github.pemistahl.lingua.api.Language._
private val DefaultPattern = "txt"
private val QuotePattern = """("(?<dqt>[^"]*)")|('(?<sqt>[^']*)')""".r
private val SplitMatched = """([-,/])""".r
private val SplitCameCase = """(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])""".r
private val MinKeywordLen = 3
private val CacheDir = os.Path("/tmp/.detect-non-english-cache")
/**
* A stateful implementation of an auto-closable lock/monitor
* for the specified lockwith an ability to unlock it preliminarily.
* The class philosophy and namings are borrowed from C++ std::unique_lock<>.
*
* @apiNote this class isn't reentrant and isn't supposed to be shared across threads
* or to be used as a field.
* The instances of this class should be used as
* stack/method local variables with try-with-resources.
*/
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Main where
import GHC.Generics
import Data.Aeson(ToJSON)
import Web.Scotty (ActionM, ScottyM, get, header, scotty, scottyApp, status, json, middleware, html)
val conf = new SparkConf()
//.setMaster("local") for local development
.setAppName("FizzBuzz App")
val spark = SparkSession
.builder()
.config(conf)
.getOrCreate()
import spark.implicits._
// FizzBuzzNumber.avsc
{
"namespace": "fizzbuzz",
"type": "record",
"name": "FizzBuzzNumber",
"fields":[
{
"name": "value",
"type": {
"type": "int"
package fizzbuzz
import cloudflow.akkastream._
import cloudflow.akkastream.scaladsl._
import cloudflow.streamlets._
import cloudflow.streamlets.avro._
class FizzBuzzPrinter extends AkkaStreamlet {
val inlet = AvroInlet[FizzBuzzResult]( "in" )
val shape = StreamletShape.withInlets( inlet )
package fizzbuzz
import cloudflow.akkastream._
import cloudflow.akkastream.scaladsl._
import cloudflow.streamlets.{ RoundRobinPartitioner, StreamletShape }
import cloudflow.streamlets.avro._
class FizzBuzzProcessor extends AkkaServerStreamlet {
def basicFizzbuzzRules( x: Int ): String = {
package fizzbuzz
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import cloudflow.akkastream._
import cloudflow.akkastream.util.scaladsl._
import cloudflow.streamlets._
import cloudflow.streamlets.avro._
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
def reactiveFizzbuzz( n: Int )( rules: Int => String ): Source[( Int, String ), _] = {
Source(
1 to n
import scala.collection.parallel.CollectionConverters._
import scala.collection.parallel.ParSeq
def parallelFizzbuzz( n: Int )( rules: Int => String ): ParSeq[( Int, String )] = {
(1 to n).par
.map(x => ( x, rules( x ) ) )
}
parallelFizzbuzz( N )( basicFizzbuzzRules ).foreach( println )