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
// Translated from https://github.com/gliese1337/vitter-sample/blob/master/src/index.ts | |
// TODO: The returns were yields and the entire algorithm should create a Seq or Iterable of Ints | |
import scala.util.control.Breaks._ | |
object SequentialRandomSampling { | |
val negalphainv = -13 | |
def skip(_k: Int, _N: Int) { | |
var k = _k | |
var N = _N | |
var qu1 = N - k + 1 | |
var S = 0 |
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
def constantStringThenContent[F[_] : Timer : Concurrent, A](constantString: String, result: F[A])( | |
implicit W: EntityEncoder[F, A] | |
): Response[F] = { | |
val resultStream = Stream.eval(result) | |
val preStream = EntityEncoder.stringEncoder[F].toEntity(constantString).body | |
val composedStream = (Stream[F, Option[A]](None, None, None) ++ resultStream.map(Option.apply)) | |
.switchMap[F, Byte] { | |
case None => | |
fs2.Stream.awakeEvery[F](10.second).flatMap(_ => preStream) | |
case Some(v) => W.toEntity(v).body |
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 $ivy.`com.chuusai::shapeless:2.3.3` | |
import shapeless._ | |
trait Fields[T] { | |
def fields: List[String] | |
override def toString: String = fields.mkString(", ") | |
} | |
object Fields extends LabelledProductTypeClassCompanion[Fields] { | |
def apply[T](fs: List[String]): Fields[T] = new Fields[T] { | |
override def fields: List[String] = fs |
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
case class MapIncluding[K](keys: Seq[K], optionally: Seq[K] = Seq()) { | |
def unapply[V](m: Map[K, V]): Option[(Seq[V], Seq[Option[V]])] = | |
if (keys.forall(m.contains)) { | |
Some((keys.map(m), optionally.map(m.get))) | |
} else { | |
None | |
} | |
} | |
sealed trait MapRequirements[K] { | |
type ResultType[V] |
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
// ==UserScript== | |
// @name Remove Github notifications | |
// @namespace Violentmonkey Scripts | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js | |
// @match https://github.com/* | |
// @grant GM_addStyle | |
// ==/UserScript== | |
//- The @grant directive is needed to restore the proper sandbox. | |
$(".notification-indicator").remove(); |
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 cats.effect._ | |
import scala.concurrent.{ExecutionContext, Future} | |
class FutureConcurrentEffect()(implicit ec: ExecutionContext) extends FutureEffect with ConcurrentEffect[Future] { | |
def start[A](fa: Future[A]): Future[Fiber[Future, A]] = Future.successful { | |
FutureFiber(fa) | |
} | |
def racePair[A, B](fa: Future[A], fb: Future[B]): Future[Either[(A, Fiber[Future, B]), (Fiber[Future, A], B)]] = ??? |
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
@startuml | |
sprite $graphql [48x48/16] { | |
000000000000000000000001100000000000000000000000 | |
0000000000000000000002CFFC2000000000000000000000 | |
000000000000000000002FFFFFF200000000000000000000 | |
000000000000000000007FFFFFF700000000000000000000 | |
00000000000000000000FFFFFFFF00000000000000000000 | |
00000000000000000000CFFFFFFC00000000000000000000 | |
00000000000000000004FFFFFFFF40000000000000000000 | |
000000000000000003CF58FFFF85FC300000000000000000 |
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 ammonite.ops._ | |
import mill._ | |
import mill.util.Ctx | |
import mill.modules.Jvm | |
trait FlywayModule extends JavaModule { | |
def flywayMigrationPaths: T[Seq[PathRef]] = T { resources() } | |
def flywayUser: T[String] | |
def flywayPassword: T[String] | |
def flywayJdbcUrl: T[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
import $ivy.{ | |
`org.typelevel::frameless-cats:0.4.0`, | |
`org.typelevel::frameless-dataset:0.4.0`, | |
`org.typelevel::frameless-ml:0.4.0`, | |
`org.apache.spark::spark-core:2.2.1`, | |
`org.apache.spark::spark-sql:2.2.1`, | |
`eu.timepit::refined:0.8.7` | |
} | |
import scala.language.higherKinds |
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 org.apache.spark.sql.DataFrame | |
def compareDataFrames(dfA: DataFrame, dfB: DataFrame, joinFields: Array[String]): (DataFrame, Seq[String]) = { | |
val nonJoinFields = (dfA.schema.fieldNames ++ dfB.schema.fieldNames).distinct.diff(joinFields) | |
val joined = dfA.join(dfB, joinFields) | |
val differing = joined.where(nonJoinFields.map(f => dfA(f) =!= dfB(f)).reduce(_ || _)).cache | |
val differingFields = nonJoinFields.filter(f => differing.select(dfA(f)).except(differing.select(dfB(f))).count + differing.select(dfB(f)).except(differing.select(dfA(f))).count > 0) | |
val nonDifferingNonJoinFields = nonJoinFields.diff(differingFields) | |
val differingRenamed = differingFields.foldLeft(differing) { case(df, field) => df.withColumn(s"${field}_a", dfA(field)).withColumn(s"${field}_b", dfB(field)).drop(field) } | |
val comparisonDf = nonDifferingNonJoinFields.foldLeft(differingRenamed) { case(df, field) => df.withColumn(s"${field}_common", dfA(field)).drop(field) } |