- Web Server: Play (framework) or http4s (library)
- Actors: akka
- Asynchronous Programming: monix (for tasks, reactors, observables, scheduler etc)
- Authentication: Silhouette
- Authorization: Deadbolt
- Command-line option parsing: case-app
- CSV Parsing: kantan.csv
- DB: doobie (for PostgreSQL)
This file contains hidden or 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 java.util.concurrent.ArrayBlockingQueue | |
| import scala.concurrent.{ExecutionContext, Future} | |
| /** | |
| * Rick's implementation of ghetto back-pressure algo | |
| * Implement this trait and pass it off to ProducerConsumer.Runner to run it | |
| * | |
| * @tparam R Type of result to be crunched | |
| * @tparam S State to iterate on |
This file contains hidden or 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 java.util.regex.{MatchResult, Pattern} | |
| import scala.collection.mutable | |
| /** | |
| * Supports named group finding | |
| * | |
| * @see http://stackoverflow.com/questions/39754604/ | |
| */ | |
| class GroupNamedRegex(pattern: Pattern, namedGroups: Set[String]) { | |
| def this(regex: String) = this(Pattern.compile(regex), GroupNamedRegex.namePattern.findAllMatchIn(regex).map(_.group(1)).toSet) |
This file contains hidden or 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.coatue.datascience.util | |
| import java.sql.{Connection, PreparedStatement} | |
| import com.typesafe.scalalogging.Logger | |
| import org.slf4j.LoggerFactory | |
| import slick.driver.PostgresDriver.api._ | |
| class DbBatchedJob(db: Database, sql: String, batchSize: Int) extends AutoCloseable { |
Input
p := Original Principal amount
apr := Annual Percentage Rate
t := Number of years of loan
Calcuation:
r := apr/100/12 # monthly interest rate
This file contains hidden or 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
| #!/usr/bin/env bash | |
| substring=$1 | |
| replace=$2 | |
| current_branch=$(git name-rev --name-only HEAD) | |
| echo "Replacing ${substring} with ${replace} in all new commits in ${current_branch}" | |
| cd $(git root) | |
| git filter-branch --msg-filter "'sed ""s/${substring}/${replace}/g""'" master..${current_branch} | |
| git push -f |
This file contains hidden or 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.collection.mutable | |
| type PQ[K, V] = mutable.SortedMap[K, V] | |
| object PQ { | |
| def apply[K, V: Ordering](elems: Seq[(K, V)]): PQ[K, V] = | |
| elems.foldLeft(PQ.empty[K, V])(_ += _) | |
| /** | |
| * A SortedMap which sorts keys by the value |
This file contains hidden or 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
| /** | |
| * Solves the n-Queen puzzle in O(n!) | |
| * Let p[r] be the column of the queen on the rth row (must be exactly 1 queen per row) | |
| * There also must be exactly 1 queen per column and hence p must be a permuation of (0 until n) | |
| * There must be n distinct (col + diag) and n distinct (col - diag) for each queen (else bishop attacks) | |
| * @return returns a Iterator of solutions | |
| * Each solution is an array p of length n such that p[i] is the column of the queen on the ith row | |
| */ | |
| def nQueens(n: Int): Iterator[Seq[Int]] = | |
| (0 until n) |
This file contains hidden or 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
| trait NotSubTypeOf[A, B] // encoding to capture A is not a subtype of B | |
| // Note: We can use infix notation to write `A NotSubTypeOf B` instead of `NotSubTypeOf[A, B]` | |
| // evidence for any two arbitrary types A and B, A is not a subtype of B | |
| implicit def isSub[A, B]: A NotSubTypeOf B = null | |
| // define ambigous implicits to trigger compile error in case A is a subtype of B (or A =:= B) | |
| implicit def iSubAmbig1[A, B >: A]: A NotSubTypeOf B = null | |
| implicit def iSubAmbig2[A, B >: A]: A NotSubTypeOf B = null |
This file contains hidden or 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
| class AutoSuggest(corpus: String, alphabet: Seq[Char] = 'a' to 'z', depth: Int = 2) { | |
| val words = s"[${alphabet.head}-${alphabet.last}]+".r | |
| .findAllIn(corpus.toLowerCase).toSeq | |
| .groupBy(_.toSeq).mapValues(_.size) | |
| .par withDefaultValue 0 | |
| def editDistance(a: Seq[Char], b: Seq[Char]) = { | |
| lazy val d: Stream[Stream[Int]] = Stream.tabulate(a.length + 1, b.length + 1) { | |
| case (i, j) if (i - j).abs > depth => Int.MaxValue | |
| case (i, 0) => i |