- 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
/** | |
* Dumb O(n^3) version: Check if all n^2 substrings are palindromes | |
*/ | |
def countPalindromes3(s: String): Int = | |
(1 to s.length).flatMap(s.sliding).count(t => t.reverse == t) | |
/***********************************************************************/ | |
/** | |
* O(n^2) solution - count how many (odd and even) palindromes are centered at index i by expanding left and right | |
*/ |
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.util.control.NonFatal | |
import better.files.Scanner.Read | |
/** | |
* Extend this trait to create your application config | |
* | |
* Pros of this approach: | |
* 1) Library free approach - only 15 lines of dependency free "library" (four one-line defs for you to override) | |
* 2) Failures happen when the Config object is loaded instead of when a config value is accessed | |
* 3) Strongly typed |
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 | |
/** | |
* A thread-safe Scala port of the KShingling implementation of https://github.com/tdebatty/java-string-similarity | |
*/ | |
class KShingling(k: Int = 3) {self => | |
private[this] val shingles = mutable.Map.empty[String, Int] | |
def profile(s: String) = { |
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 CircularBuffer<T> { | |
private T[] array = (T[]) new Object[1<<4]; | |
private int start = 0, end = 0; | |
public T get(int i) { | |
assert(0 <= i && i < size()); | |
return array[mod(start + i)]; | |
} | |
public void set(int i, T elem) { |
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
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done |
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