Skip to content

Instantly share code, notes, and snippets.

View asethia's full-sized avatar

Arun Sethia asethia

  • United States
View GitHub Profile
@asethia
asethia / RestSourceStream.scala
Created May 24, 2018 02:31
This example shows how we can expose REST Akka Http end point using Source Streaming
import akka.NotUsed
import akka.http.scaladsl.common.{EntityStreamingSupport, JsonEntityStreamingSupport}
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.model.headers.Accept
import akka.http.scaladsl.model.{MediaRange, MediaTypes}
import akka.http.scaladsl.server.{Directives, Route}
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.stream.scaladsl.Source
import org.scalatest.{Matchers, WordSpec, WordSpecLike}
import spray.json.DefaultJsonProtocol
@asethia
asethia / LinkedList.scala
Last active June 15, 2018 20:20
Linked List Using Scala
package linkedlist
sealed trait AbstractCons[+A] {
def value: A
def next: AbstractCons[A]
}
/**
@asethia
asethia / ZAlgorithm.scala
Last active June 15, 2018 16:42
ZAlgorithm for String pattern search
package searchpattern
import scala.annotation.tailrec
/**
* ZIndex String Pattern Search
* inspired from https://www.youtube.com/watch?v=CpZh4eF8QBw
* Created by Arun Sethia on 6/6/18.
*/
@asethia
asethia / KMPAlgorithm.scala
Last active June 15, 2018 16:42
KMP Pattern Matching
package searchpattern
import scala.annotation.tailrec
/**
* KMP Pattern Matching
* inspired from https://www.youtube.com/watch?v=GTJr8OvyEVQ
* Created by Arun Sethia on 6/13/18.
*/
object KMPAlgorithm extends App {
@asethia
asethia / UniqueCharacters.scala
Last active July 25, 2018 19:23
Implement an algorithm to determine if a string has all unique characters.
import scala.annotation.tailrec
/**
* find given string has unique characters
*
* Created by Arun Sethia on 5/21/18.
*/
trait UniqueCharacters {
//ASCII Characters 128
def isUnique(input: String): Boolean = {
@asethia
asethia / AnagramString.scala
Created July 5, 2018 14:54
Given two strings, write a method to decide if one is a permutation of the other.
import scala.annotation.tailrec
/**
* given two strings, write a method to decide if one is a permutation of the other.
* Created by Arun Sethia on 7/5/18.
*/
trait AnagramString {
final val ASCII_CHAR_LEN: Int = 128
@asethia
asethia / URLify.scala
Last active July 7, 2018 00:00
Write a method to replace all spaces in a string with '%20'
/**
* Write a method to replace all spaces in a string with '%20:
* You may assume that the string has sufficient space at the end to hold the additional characters
* Input: "hello world "
* Output: "hello%20world"
* Created by Arun Sethia on 7/5/18.
*/
trait URLify {
/**
@asethia
asethia / PalindromePermutation.scala
Last active July 6, 2018 23:59
From given string input can we make Palindrome or not
import scala.annotation.tailrec
/**
* From given string input can we make Palindrome or not
* Input: Tact Coa
* Output: True
* (permutations: "taco cat". "atco cta". etc.)
* Created by Arun Sethia on 7/6/18.
*/
trait PalindromePermutation {
@asethia
asethia / OneAway.scala
Last active July 18, 2018 15:53
There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character.
import org.scalatest.{Matchers, WordSpec}
import scala.annotation.tailrec
/**
* There are three types of edits that can be performed on strings: insert a character, remove a character,
* or replace a character.
* Given two strings, write a function to check if they are one edit (or zero edits) away.
* pale, pIe -> true
* pales, pale -> true
@asethia
asethia / StringCompression.scala
Last active July 12, 2018 03:14
basic string compression using the counts of repeated characters
package arraystring
import org.scalatest.{Matchers, WordSpec}
import scala.annotation.tailrec
import scala.collection.mutable.StringBuilder
/**
* basic string compression using the counts of repeated characters.
* For example, the string aabcccccaaa would become a2b1c5a3.