Skip to content

Instantly share code, notes, and snippets.

View samuelorji's full-sized avatar

Samuel Orji samuelorji

View GitHub Profile
@samuelorji
samuelorji / producing.scala
Last active July 17, 2018 13:28
A very simple Kafka producer that writes to a given topic without a key
package kafka
import java.util.Properties
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
import scala.io.StdIn
object producing extends App{
@samuelorji
samuelorji / consuming.scala
Last active July 20, 2018 00:48
Simple conusmer code for kafka only compatible with kafka 0.10.x
package kafka
import java.util.{Collections, Properties}
import java.util
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.common.TopicPartition
import org.apache.log4j.Logger
import scala.collection.JavaConverters._
@samuelorji
samuelorji / battles.scala
Created July 20, 2018 10:14
A simple script that connects to a cassandra cluster and fetches data from it
package cassandra
import com.datastax.spark.connector.rdd.CassandraTableScanRDD
import org.apache.spark.{SparkConf, SparkContext}
object battles {
case class Battle(
battle_number: Option[Integer],
year: Option[Integer],
@samuelorji
samuelorji / build.sbt
Created November 23, 2018 16:32
A sample build.sbt file ffor multiple projects
val Snapshots = "Snapshots" at "url to repo "
val Releases = "Releases" at "url to repo "
lazy val sharedSettings = Seq(
scalaVersion := "2.12.6",
version := "0.1.6",
resolvers ++= Seq(
Snapshots,
Releases,
"Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/",
sealed trait Animal {
def speakLikeAnimal : Unit
//some other method for animals
}
case class Cat (name : String , sound : String) extends Animal{
override def speakLikeAnimal: Unit = println(s"I am $name and the sound i make is $sound")
}
trait HumanTendency[A]{
def makeHumanLike(a : A) : String
}
implicit val humanLike = new HumanTendency[Parrot] {
override def makeHumanLike(a: Parrot): String = s"I am ${a.name}, the sound i make is ${a.sound},and i can talk like a human :) "
}
def speakLikeHuman(p :Parrot)(implicit humanTendency: HumanTendency[Parrot]) : String = {
humanTendency.makeHumanLike(p)
}
println ( speakLikeHuman(parrot) ) // prints out ---------> I am Casey, the sound i make is prrrrr,and i can talk like a human :)
implicit class ToParrot( p : Parrot){
def speakLikeHuman(implicit humanlike : HumanTendency[Parrot]) : String = {
humanlike.makeHumanLike(p)
}
}
//let us create our closed model object type Parrot
val parrot = Parrot("Casey", "prrrrr")
//closed object type Cat
(messageGateway ? SendMessageToClientRequest (
id = id,
phoneNumber = pNumber,
msg = message
)).mapTo[SendMessageToClientResponse] onComplete {
case Success(res) => res match {
case SendMessageToClientResponse(true) =>
currentSender ! SendCustomMessageResponse(true)
case SendMessageToClientResponse(false) =>
currentSender ! SendCustomMessageResponse(false)