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
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) |
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 spendNotMoreThan[T](time: Duration) = new { | |
def on(op: => Result[T]): Result[T] = { | |
var res:Result[T] = Empty | |
var done = new AtomicBoolean(false) | |
val nanos = time.toNanos | |
val upto = System.nanoTime + nanos | |
val worker = new Thread { | |
override def run { | |
res = op | |
done.set(true) |
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
// we already have a bunch of patient properties on one tab (in props1); now get another bunch from another tab | |
// we click it and wait for the element to show up; then: | |
val props2 = extractProperties("div#ctl00_ContentPlaceHolder1_Details_Container2") map (_.trimPrefixes) | |
// trimming prefixes means we do not care about all the additional keys, but just a variety of values | |
// now let's blend the two sets together; <*> will produce either Good((p1,p2)) or Bad(errors1 ++ errors2) | |
val propsOpt: Result[(Props, Props)] = props1 <*> props2 | |
// then we want to merge together two sets of patient properties; that's what we do in map | |
val patientData = propsOpt map ((xy:(Props, Props)) => (xy._1 ++ xy._2)) | |
debug(s"Got patient data\n $patientData") |
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
/** | |
* This trait (typeclass) defines one operation for a parametrized type F | |
* the operation is known as fmap in Haskell, f1 in internal categories. | |
* | |
* For each pair of arbitrary types X, Y and an arbitrary function:X=>Y, | |
* it should provide a function F[X]=>F[Y]. | |
* Providing means that the implementation depends on a specific type F | |
* E.g. given F = List, and a function f(n: Int): String = "{{" + n + "}}", | |
* we should have a function List[Int]=>List[String] that wraps elements in double braces. | |
* |
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 Ch(c: Char) { def ~=(x: Char) = c == '.' || c == x } | |
class RE(val regexp: String) { | |
def skip(n: Int) = RE(regexp.substring(n)) | |
implicit def token(c: Char) = Ch(c) | |
def c0 = Ch(regexp(0)) | |
def c1 = regexp(1) | |
def ~=(text: String): Boolean = { |
NewerOlder