Input
p := Original Principal amount
apr := Annual Percentage Rate
t := Number of years of loan
Calcuation:
r := apr/100/12 # monthly interest rate
| /** | |
| * 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) |
| 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 |
| #!/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 |
Input
p := Original Principal amount
apr := Annual Percentage Rate
t := Number of years of loan
Calcuation:
r := apr/100/12 # monthly interest rate
| 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 { |
| 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) |
| 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 |
| git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done |
| 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) { |