This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io._ | |
| import com.amazonaws.ClientConfiguration | |
| import com.amazonaws.auth.DefaultAWSCredentialsProviderChain | |
| import com.amazonaws.services.s3.AmazonS3Client | |
| import com.amazonaws.services.s3.model._ | |
| object S3Api { | |
| private val config = new ClientConfiguration() //in milliseconds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # confluent kafka(.8.2) producer | |
| import json | |
| from confluent_kafka import Producer | |
| class KafkaProducer: | |
| def __init__(self, hosts): | |
| self.hosts = hosts | |
| self.producer = Producer( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # confluent Kafka(.8.2) consumer | |
| from confluent_kafka import Consumer | |
| from confluent_kafka import TopicPartition | |
| class KafkaConsumer: | |
| def __init__(self,topic, hosts, partitions): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import akka.event.LoggingAdapter | |
| import akka.http.scaladsl.Http | |
| import akka.http.scaladsl.model.HttpRequest | |
| import akka.http.scaladsl.server.Directives._ | |
| import akka.http.scaladsl.server.Route | |
| import akka.http.scaladsl.server.RouteResult.{Complete, Rejected} | |
| import akka.http.scaladsl.server.directives.{DebuggingDirectives, LoggingMagnet} | |
| import akka.stream.ActorMaterializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.{Executors, ForkJoinPool} | |
| import scala.concurrent.ExecutionContext | |
| //For IO intensive applications | |
| object MyExecutionContext { | |
| private val concurrency = Runtime.getRuntime.availableProcessors() | |
| implicit val commonThreadPool: ExecutionContext = ExecutionContext.fromExecutor(Executors.newCachedThreadPool()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.apache.http.annotation.NotThreadSafe | |
| import org.apache.poi.ss.usermodel._ | |
| import scala.collection.JavaConversions._ | |
| import scala.util.control.NonFatal | |
| object IXLS2CSV { | |
| private val df = new DataFormatter(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import play.sbt.PlayRunHook | |
| import sbt._ | |
| import java.net.InetSocketAddress | |
| object Angular2 { | |
| def apply(log: Logger, base: File, target: File): PlayRunHook = { | |
| object Angular2Process extends PlayRunHook { | |
| private var watchProcess: Option[Process] = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io._ | |
| object Loop1 extends App { | |
| //Java way | |
| val inputStream: BufferedInputStream = new BufferedInputStream(new FileInputStream("input.csv")) | |
| val outputStream = new BufferedOutputStream(new FileOutputStream("output.csv")) | |
| val buffer = new Array[Byte](32 * 1024) | |
| var bytesRead: Int = inputStream.read(buffer) | |
| while (bytesRead > 0) { | |
| println("writing.......") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object FoldLeft extends App { | |
| def reverse(list: List[Int]): List[Int] = | |
| list.foldLeft[List[Int]](Nil)((acc, element) => element :: acc) | |
| def dedupe(list: List[Int]): List[Int] = { | |
| list.foldLeft[List[Int]](Nil)((acc, element) => if (acc.contains(element)) acc else acc :+ element) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.{BufferedReader, File, InputStreamReader} | |
| import javax.annotation.concurrent.NotThreadSafe | |
| import org.apache.hadoop.io.{LongWritable, Text} | |
| import org.apache.hadoop.mapred.{FileSplit, TextInputFormat} | |
| import org.apache.spark.broadcast.Broadcast | |
| import org.apache.spark.rdd.HadoopRDD | |
| import org.apache.spark.{SparkConf, SparkContext} | |
| @NotThreadSafe |