Skip to content

Instantly share code, notes, and snippets.

Think -> Code -> Solve

ShankarShastri shankarshastri

Think -> Code -> Solve
View GitHub Profile
View ExploreUnionTypes.scala
object ExploreUnionTypes {
final case class Some[T](t: T)
final case class None()
type Option[T] = Some[T] | None
def toOption[T](t: T): Option[T] = {
if (t == null) None() else Some(t)
View ExploreIntersectionTypes.scala
object ExploreIntersectionTypes {
trait Mapper[A, B] {
def map(l: List[A])(f: A => B): List[B] =
trait Reducer[A, B >: A] {
def reduce(l: List[A])(f: (B, B) => B): B = l.reduce(f)
View ExploreDependentFunctionValue.scala
object ExploreDependentFunctionValue {
trait Entry { type Key; val key: Key }
def extractKey(e: Entry): e.Key = e.key // a dependent method
val extractor: (e: Entry) => e.Key = extractKey // a dependent function value
final case class IntEntry() extends Entry {
type Key = Int
override val key = 10
shankarshastri / LearnXInYMinProtocolBuffer.proto
Last active Oct 6, 2020
Self-Explanatory Protocol Buffer Lang Guide (CheatSheet)
View LearnXInYMinProtocolBuffer.proto
* Self-Explanatory Protocol Buffer Lang Guide
* Why Protocol Buffers?
* Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.
* You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
* Protocol Buffers are Schema Of Messages. They are language agnostic.
View gist:fa57458b1c5c228346a25fddeb688652
to check if the server works -
View EditDistance.scala
def editDistance(s1: String, s2: String): Int = {
val s1Arr = s1.toCharArray
val s2Arr = s2.toCharArray
val mapOfEditDistance = scala.collection.mutable.HashMap.empty[(Int, Int), Int]
def editDistanceHelperDP(i: Int, j: Int): Int = {
mapOfEditDistance.getOrElseUpdate((i, j), if(i == -1) {
mapOfEditDistance.update((i, j), j + 1)
View MutableTrie.scala
import scala.annotation.tailrec
import scala.collection.mutable
case class MutableTrieNode(h: mutable.HashMap[Char, MutableTrieNode], isWord: Boolean = false)
object MutableTrieNode {
def empty = MutableTrieNode(mutable.HashMap.empty)
def buildTrieNode(s: List[Char], t: MutableTrieNode = MutableTrieNode.empty): MutableTrieNode = {
s match {
case Nil => t.copy(isWord = true)
View ImmutableTrie.scala
import scala.annotation.tailrec
import scala.collection.immutable.HashMap
case class TrieNode(h: HashMap[Char, TrieNode], isWord: Boolean = false)
object TrieNode {
def empty = TrieNode(HashMap.empty)
def buildTrieNode(s: List[Char], t: TrieNode = TrieNode.empty): TrieNode = {
s match {
case Nil => t.copy(isWord = true)
View Trie.scala
case class TrieNode[T](edgeList: Map[T, TrieNode[T]] = Map.empty[T, TrieNode[T]], isLeaf: Boolean = false,
isEntry: Boolean = false)
object TrieNode {
def emptyTrieNode[T]: TrieNode[T] = {
def newTrieNode[T](data: T): TrieNode[T] = {
TrieNode[T](edgeList = Map[T, TrieNode[T]]((data, emptyTrieNode[T])))
shankarshastri / Client example
Created Jun 8, 2020 — forked from rklaehn/Client example
akka http file server
View Client example
package akkahttptest
import akka.http.Http
import{Sink, Source}
import akka.http.model._
object TestClient extends App {
You can’t perform that action at this time.