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
4.5e15 + (2e-1 + 2e-1) != (4.5e15 + 2e-1) + 2e-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 com.rubiconproject.dt.silvergate.sparktest.SharedSparkSession | |
import com.rubiconproject.science.util.SparkImplicitsWithoutSqlContext._ | |
import org.specs2.mutable.Specification | |
import scala.util.Random | |
import ExampleRollupTest._ | |
class ExampleRollupTest extends Specification with SharedSparkSession { | |
"a" should { | |
"b" in { |
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 encodePair(pair: (Char, Char)): (Char, Char) = findLetterInSquare(pair._1) match { | |
case (a, b) => findLetterInSquare(pair._2) match { | |
case (`a`, `b`) => throw new Exception("UNPOSSIBLE!") // same cell | |
case (`a`, d ) => (indexToLetter((a, (b+1)%5)), indexToLetter((a, (d+1)%5))) // same row | |
case ( c, `b`) => (indexToLetter(((a + 1)%5, b)), indexToLetter(((c+1)%5, b))) // same column | |
case ( c, d ) => (indexToLetter((a, d)),indexToLetter((c, b))) | |
} | |
} |
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
final class ListOps[A](val l: List[A]) extends AnyVal { | |
def distinctBy[K](f: A => K): List[A] = { | |
val seen = collection.mutable.HashSet.empty[K] | |
@tailrec | |
def loop(l: List[A], distinctAccum: List[A]): List[A] = l match { | |
case Nil => distinctAccum | |
case t :: ts => | |
val k = f(t) | |
if (seen.contains(k)) loop(ts, distinctAccum) |
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
/// A double floating point number which allows values in the range [0.0,100.0]. | |
object ProperPercentage { | |
type L = W.`0.0`.T | |
type H = W.`100.0`.T | |
type P = Interval.Closed[L, H] | |
type N = Double | |
type T = N Refined P | |
val gen: Gen[Refined[N, Closed[L, H]]] = intervalClosedArbitrary[Refined, N, L, H].arbitrary | |
def safely(d: Double): String \/ T = refineV[P].apply(d).fold(_.left, _.right) | |
def unsafe(d: Double): T = safely(d).valueOr(m => throw new Exception(m)) |
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 play.api.libs.json._ | |
import scalaz.NonEmptyList | |
import scala.reflect.ClassTag | |
import scala.reflect.runtime.universe.TypeTag | |
/** | |
* Provides a Play JSON Format for an ADT with case classes and possibly case object members. | |
* | |
* Heavily inspired by https://gist.github.com/realpeterz/aecb53a67fb723485eb66d544a67d580 |
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 IndexedSeqSyntax { | |
@specialized(Specializable.Bits32AndUp) | |
implicit class IndexedSeqOps[T](ts: IndexedSeq[T]) { | |
/** | |
* Accumulates values, S, derived from T, and returns the first T, if any when p is true for S. | |
* | |
* It's kind of like a lazy conjunction of the standard library's `scan` and `find`. | |
* | |
* It could be implemented less efficiently as: |
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 QueryUtil { | |
/** | |
* Generates an SQL comment that indicates where in Scala source the query originated. | |
*/ | |
def locationFragment(implicit file: sourcecode.File, line: sourcecode.Line): Fragment = { | |
Fragment.const(s"/* Query from ${file.value}:${line.value} */\n") | |
} | |
} |
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
/** | |
* Reads the version number out of the manifest. | |
*/ | |
object Version { | |
def apply: Option[String] = { | |
val myClass = this.getClass | |
val classFileName = s"${myClass.getSimpleName}.class" | |
val myUrl = myClass.getResource(classFileName) | |
val myUrlString = myUrl.toString | |
val lastBang = myUrlString.lastIndexOf('!') |
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
class ReducingIterator[A] private (iterator: Iterator[A], shouldGroup: (A, A) => Boolean, reduce: (A, A) => A) extends Iterator[A] { | |
// Basic implementation robbed from https://github.com/fulcrumgenomics/fgbio/blob/27b0bc20f8baf26f555bb056073bb8de528c4ef3/src/main/scala/com/fulcrumgenomics/util/BetterBufferedIterator.scala#L36 | |
private var buffer: Option[A] = maybeNext | |
/** Returns a Some(A) if there is a next in the iterator else None. */ | |
private def maybeNext = if (this.iterator.hasNext) Some(this.iterator.next()) else None | |
/** True if head() and hasNext() will return an item, false otherwise. */ | |
override def hasNext: Boolean = this.buffer.nonEmpty |
NewerOlder