Skip to content

Instantly share code, notes, and snippets.

View satendrakumar's full-sized avatar
:octocat:

Satendra Kumar satendrakumar

:octocat:
View GitHub Profile
@satendrakumar
satendrakumar / JsonUtility.scala
Last active February 12, 2019 06:32
Scala Utility class for parsing and writing Json(Write once and use everywhere )
import org.json4s._
import org.json4s.native.{JsonMethods, Serialization}
object JsonUtility {
implicit val formats = DefaultFormats
def write[T <: AnyRef](value: T): String = Serialization.write(value)
Prelude> let forall :: (a -> Bool) -> [a] -> Bool ; forall f []= True; forall f (x:xs) = f x && forall f xs
Prelude> forall even [2,4,6]
True
Prelude> forall even [2,4,5]
False
Prelude> let forall :: (a -> Bool) -> [a] -> Bool ; forall f []= True; forall f (x:xs) = if (f x) then forall f xs else False
Prelude> forall even [2,4,5]
False
Prelude> forall even [2,4,6]
True
@satendrakumar
satendrakumar / GenericTypeConverter.scala
Created March 23, 2017 12:44
Generic Type Converter
object GenericTypeConverter extends App{
def convert[T: ClassTag](value:Any): Option[T] = {
val ct = implicitly[ClassTag[T]]
value match {
case ct(x) => Some(x)
case _ => None
}
}
@satendrakumar
satendrakumar / kafka-consumer
Last active May 31, 2016 18:08
Read data from kafka cluster.
//Worker code
import org.apache.kafka.clients.consumer.ConsumerRecord;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
public class Worker implements Callable<Boolean> {
ConsumerRecord record;
package slicks.docs.dao
import scala.slick.driver.PostgresDriver.simple._
import scala.slick.driver._
trait Profile {
val profile: JdbcProfile
}
@satendrakumar
satendrakumar / kafka.md
Last active August 29, 2015 14:21 — forked from ashrithr/kafka.md

Introduction to Kafka

Kafka acts as a kind of write-ahead log (WAL) that records messages to a persistent store (disk) and allows subscribers to read and apply these changes to their own stores in a system appropriate time-frame.

Terminology:

  • Producers send messages to brokers
  • Consumers read messages from brokers
  • Messages are sent to a topic
@satendrakumar
satendrakumar / JavaNullWithScala.scala
Last active April 15, 2017 04:32
Handling Java null with Scala
object play {
println("Welcome to the Scala worksheet")
case class User(id:Int, name:String)
def getUser:User = null
def processUser(u:User):String= u.name
Option(getUser)
Option(getUser).fold("Sky")(u=>processUser(u))