This file contains 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.akka.websocket | |
import akka.NotUsed | |
import akka.actor.typed.scaladsl.Behaviors | |
import akka.actor.typed.{ActorRef, ActorSystem, Behavior} | |
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.model.StatusCodes | |
import akka.http.scaladsl.model.ws.{BinaryMessage, Message, TextMessage} | |
import akka.http.scaladsl.server.Directives._ | |
import akka.stream.scaladsl.{Flow, Keep, Sink, Source} |
This file contains 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.NotUsed | |
import akka.actor.typed.scaladsl.Behaviors | |
import akka.actor.typed.{ActorRef, ActorSystem, Behavior} | |
import scala.concurrent.duration.DurationInt | |
object PingPongActorMain extends App { | |
case class Ping(counter: Int, replyTo: ActorRef[Pong]) |
This file contains 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 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) | |
} | |
@main |
This file contains 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 ExploreIntersectionTypes { | |
trait Mapper[A, B] { | |
def map(l: List[A])(f: A => B): List[B] = l.map(f) | |
} | |
trait Reducer[A, B >: A] { | |
def reduce(l: List[A])(f: (B, B) => B): B = l.reduce(f) | |
} |
This file contains 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 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 | |
} |
This file contains 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
to check if the server works - https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice | |
stun: | |
stun.l.google.com:19302, | |
stun1.l.google.com:19302, | |
stun2.l.google.com:19302, | |
stun3.l.google.com:19302, | |
stun4.l.google.com:19302, | |
stun.ekiga.net, | |
stun.ideasip.com, |
This file contains 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 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) |
This file contains 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 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) |
NewerOlder