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
-Dcom.github.fommil.netlib.BLAS=com.github.fommil.netlib.F2jBLAS | |
-Dcom.github.fommil.netlib.LAPACK=com.github.fommil.netlib.F2jLAPACK | |
-Dcom.github.fommil.netlib.ARPACK=com.github.fommil.netlib.F2jARPACK |
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
object Perms extends App { | |
def perms[T](xs: List[T]): Stream[List[T]] = | |
xs match { | |
case Nil => Stream.empty | |
case single@List(e) => Stream(single) | |
case l => | |
val s = for { | |
i <- (0 until l.length).toStream | |
(pref, suf) = l.splitAt(i) |
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 scala.concurrent.{Await, Future} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
import scala.util.Try | |
case class Node[T](value: T, children: List[Node[T]]) | |
object DagFuture extends App { | |
def run[A, B](node: Node[A], result: B)(nodeEval: (Node[A], B) => B)(aggregator: Traversable[B] => B): Future[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
// not optimized, just a quick way to code it up... | |
// data from: http://www.ncbi.nlm.nih.gov/nuccore/LC068776.1 | |
val s1 = "ccggcctcgggaag" | |
val s2 = "ttgcggacgctagc" | |
val s3 = "tcgggctccccccg" |
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
object Stats { | |
type Observations = List[Double] | |
def mean(xs: Observations) = xs.sum / xs.size | |
def variance(xs: Observations) = { | |
val m = mean(xs) | |
xs.map{ x => math.pow(x - m, 2) }.sum / (xs.size - 1) | |
} |
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 scala.concurrent._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
def someFunction(a: Int, b: Int): Future[Int] = Future(a * b) | |
val args = Map( | |
(true, true) -> List((0,0), (0,1), (1,0), (1,1)), | |
(true, false) -> List((0,0), (1,0)), | |
(false, true) -> List((0,0), (0,1)), |
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
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
import scala.io.Source | |
val url = "https://work.caltech.edu/lectures.html" | |
val html = Source fromURL(url) mkString | |
val href = """<a href="\s*(.+?)\s*">""".r | |
val links = (for (m <- href findAllMatchIn html) yield m group 1) toList |
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
#!/bin/bash | |
# Keep calling some API every second and check that it's working (status 200). | |
# If any other HTTP status is received print an error. | |
# | |
# Useful for observing server downtime and such. | |
while true | |
do | |
status="$(curl -sL -w '%{http_code}' https://api.com/something -o /dev/null)" |
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
object FormFieldsToJson extends App { | |
if(args.length != 1) { | |
println("Usage: FormDataParser <form data>") | |
System.exit(1) | |
} | |
val fieldDelimiter = "----" | |
val fieldNLines = 3 | |
val data = args(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
// Liquibase SBT dependency is something like this: | |
// "org.liquibase" % "liquibase-core" % "3.0.5" | |
import java.sql.Connection | |
import liquibase.Liquibase | |
import liquibase.resource.FileSystemResourceAccessor | |
import liquibase.database.DatabaseFactory | |
import liquibase.database.jvm.JdbcConnection | |
import liquibase.resource.ClassLoaderResourceAccessor | |
import net.liftweb.common.Logger |