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
#!/bin/bash | |
Try all available JDKs to find which one works for your Scala and sbt. | |
clear && printf '\e[3J' | |
function testWith(){ | |
java=$1 | |
echo Y | sdk install java "$java" | |
sdk use java "$java" | |
sbt clean test package 2>$java.log && rm $java.log && return 0 || return 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
/** | |
* An example of a polynomial applicative functor `1+X×X` build from two monads, 1+ and X×X, and | |
* which is not a monad. | |
* | |
* Idea: https://stackoverflow.com/questions/49742377/is-data-poe-a-empty-pair-a-a-a-monad/49742857#49742857 | |
*/ | |
object NotMonad { | |
sealed trait SquarePlusOne[+A] { | |
def map[B](f: A => B): SquarePlusOne[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
class Test extends AnyFlatSpec with Matchers { | |
"transformer" should "work" in { | |
// source: https://contributors.scala-lang.org/t/ability-to-force-the-caller-to-specify-a-type-parameter-for-a-polymorphic-method/2116/26 | |
sealed trait NotNothing[-T] | |
object NotNothing { | |
@implicitAmbiguous("inst() method needs a generic parameter type, which is missing") | |
implicit val nothingIsNothing = new NotNothing[Nothing]{} | |
implicit def notNothing[T] = new NotNothing[T] {} |
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 Experiments_1.Q2 | |
object Experiments_1: | |
// class Q1[+T]: | |
// def enqueue(x: T): Unit = println(s"Q1 enqueued $x") | |
// val x1: Q1[Any] = new Q1[Int] | |
class Q2[-T]: | |
def enqueue(x: T): Unit = println(s"Q2 enqueued $x") |
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 java.util.{Collections, Map => JavaMap} | |
import scala.collection.JavaConverters._ | |
trait EnvHacker { | |
/** | |
* Portable method for setting env vars on both *nix and Windows. | |
* @see http://stackoverflow.com/a/7201825/293064 | |
*/ | |
def setEnv(newEnv: Map[String, String]): Unit = { | |
try { |
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
// Before | |
def buildItem(eob:EOB)(props: Props): Result[EOB_item] = { | |
implicit val empty: String = "" // weird | |
for (sDate <- props valueOf DateOfServicePerItem; | |
date <- DateFormat("MM/dd/yyyy").parseCurrent(sDate); | |
description <- props valueOf ProcedureDescription; | |
sBilled <- props valueOf BilledPerItem; | |
billed <- dollars(sBilled); |
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 java.util.List; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.HashSet; | |
import java.util.Arrays; | |
import java.util.Map; | |
import java.util.IdentityHashMap; | |
import java.util.LinkedList; | |
import java.util.SortedSet; | |
import java.util.TreeSet; |
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
package object types { | |
import scala.language.reflectiveCalls | |
import scala.language.higherKinds | |
// quantifiers aka (co)ends | |
type Forall[+F[_]] = { def apply[X]: F[X] } | |
type Exists[+F[_]] = F[_] | |
// basic categorical notions |
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
case class BT[T](left: Option[BT[T]], value: T, right: Option[BT[T]]); | |
def inorder[T](t:BT[T], out: T=>Unit): Unit = { | |
val stack: mutable.Stack[(Boolean, BT[T])] = new mutable.Stack[(Boolean, BT[T])]() | |
def p(n: BT[T]) = stack.push((false, n)) | |
p(t) | |
while (!stack.isEmpty) { | |
(stack.pop() match { | |
case (true, top) => | |
out(top.value) |
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 downloadPDF(url: String): Result[(File, String)] = { | |
loadPage(url) andThen | |
waitForSelector("div.textLayer") andThen | |
runJS("return extractPdfContent()") andThen { | |
Thread.sleep(2000) // give browser a chance | |
val extracted = runJS("return intBuf2hex(extractedPdf)") map (_.toString) | |
val pdf = extracted flatMap | |
(_.decodeHex #> File.createTempFile("download", ".pdf")) | |
val html = runJS("return _$('div.textLayer').innerHTML") map (_.toString) |
NewerOlder