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.{ExecutorService, Executors} | |
| import cats.effect.{ContextShift, IO, Resource} | |
| import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} | |
| class KafkaContext(cs: ContextShift[IO]) { | |
| // A thread pool with exactly 1 thread | |
| private val threadPool = Executors.newFixedThreadPool(1) | |
| protected val synchronousExecutionContext = ExecutionContext.fromExecutor(threadPool) | |
| def execute[A](f: => A): IO[A] = cs.evalOn(synchronousExecutionContext)(IO(f)) |
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 cats.effect.{ConcurrentEffect, ExitCode, IO, IOApp} | |
| import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} | |
| object ConsumerApplication extends IOApp { | |
| implicit private val ec: ExecutionContextExecutor = ExecutionContext.global | |
| private val cs = IO.contextShift(ec) | |
| implicit private val concurrentEffect: ConcurrentEffect[IO] = IO.ioConcurrentEffect(cs) | |
| val config = ConsumerConfig("localhost:9092", "test-topic", "consumer-group-1") |
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.time.Duration | |
| import java.util.{Collections, Properties} | |
| import cats.effect.{IO, Resource, Timer} | |
| import org.apache.kafka.clients.consumer.{KafkaConsumer, ConsumerConfig => KafkaConsumerConfig} | |
| import org.apache.kafka.common.serialization.StringDeserializer | |
| import scala.collection.JavaConverters._ | |
| import scala.concurrent.ExecutionContext |
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
| def consumeFromKafka(topic: String) = { | |
| val props = new Properties() | |
| props.put("bootstrap.servers", "localhost:9094") | |
| props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer") | |
| props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer") | |
| props.put("auto.offset.reset", "latest") | |
| props.put("group.id", "consumer-group") | |
| val consumer: KafkaConsumer[String, String] = new KafkaConsumer[String, String](props) | |
| consumer.subscribe(util.Arrays.asList(topic)) | |
| while (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
| PROMPT='$(kube_ps1) '$PROMPT |
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 sys | |
| import signal | |
| def signal_handler(sig, frame): | |
| print(f"EMERGENCY LANDING BY USER!") | |
| scf.cf.commander.send_setpoint(0, 0, 0, 0) | |
| sys.exit(0) |
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
| package exampels | |
| import com.datastax.spark.connector.cql.CassandraConnector | |
| import org.apache.spark.{ SparkConf, SparkContext } | |
| import org.apache.spark.sql.cassandra.CassandraSQLContext | |
| import org.apache.spark.SparkContext._ | |
| import com.datastax.spark.connector._ | |
| object CassandraSparkExamples { | |
| // Connection |
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.deeplearning4j.nn.conf.NeuralNetConfiguration; | |
| import org.deeplearning4j.nn.conf.layers.RBM; | |
| import org.deeplearning4j.nn.weights.WeightInit; | |
| import org.deeplearning4j.nn.conf.distribution.UniformDistribution; | |
| import org.deeplearning4j.nn.api.OptimizationAlgorithm; | |
| import org.nd4j.linalg.lossfunctions.LossFunctions; | |
| import org.deeplearning4j.nn.conf.`override`.ClassifierOverride; | |
| import org.deeplearning4j.nn.multilayer.MultiLayerNetwork; | |
| import org.deeplearning4j.optimize.listeners.ScoreIterationListener; | |
| import org.deeplearning4j.optimize.api.IterationListener; |
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
| # Partition the following data into 2 lists: males and females | |
| users = [{ | |
| "name": "user_%s" % x, | |
| "gender": 'f' if x % 3 is random.randint(0,3) else 'm' | |
| } | |
| for x in range(1, 100)] | |
| # Which way do you prefer? | |
| # 1 |
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
| package com.cloud9ers.play2.sockjs.transports | |
| import scala.Array.canBuildFrom | |
| import scala.concurrent.Promise | |
| import scala.concurrent.duration.DurationInt | |
| import org.codehaus.jackson.JsonParseException | |
| import com.cloud9ers.play2.sockjs.{ JsonCodec, Session, SockJsFrames } | |
| import akka.actor.{ ActorRef, PoisonPill, Props, actorRef2Scala } | |
| import play.api.libs.concurrent.Execution.Implicits.defaultContext | |
| import play.api.libs.iteratee.Concurrent |
NewerOlder