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
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
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
-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
# Prints % of total CPU and memory used in the system | |
# Requires psutil. Install with: | |
# `pip install psutil` | |
# or something like: | |
# `dnf install python3-psutil` | |
# Run with: | |
# `python3 profile_system.py` | |
# Ctrl + C to exit |
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 Error(message: String) | |
case class User(id: Int, name: String, accountId: Int) | |
case class Account(id: Int, balance: Double) | |
case class Item(id: Int, title: String, price: Double) | |
case class Failures(isUserFailure: Boolean, isAccountFailure: Boolean, isItemFailure: Boolean) | |
def getUser(id: Int, fail: Boolean = false): Either[Error, User] = | |
if(fail) Left(Error(s"No such user: $id")) else Right(User(id, "Bob", 3)) | |
def getAccount(id: Int, fail: Boolean = false): Either[Error, Account] = |
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
val `namespace` = "namespace" | |
val `elementTerminator` = "elementTerminator" | |
val `openBracket` = "openBracket" | |
val `closeBracket` = "closeBracket" | |
// list of partial functions from list of strings to string: | |
val patterns = List[PartialFunction[List[String], String]]( | |
{ case `namespace` :: value :: `elementTerminator` :: rest => "case1" }, | |
{ case `openBracket` :: rest => "case2" }, | |
{ case `closeBracket` :: `elementTerminator` :: rest => "case3" }) |
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
val add1 = (x: Int) => x + 1 | |
val add100 = (x: Int) => x + 100 | |
val square = (x: Int) => x * x | |
val allFunctions = List(add1, add100, square) |
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 take[A](xs: List[A], n: Int): List[A] = { | |
def loop(xy: List[A], rem: Int, accu: List[A]): List[A] = | |
if(rem <= 0) accu | |
else xy match { | |
case h :: t => loop(t, rem - 1, accu ::: List(h)) | |
case _ => accu | |
} | |
loop(xs, n, Nil) | |
} |
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
type Set = Int => Boolean | |
val setOf_1: Set = (i: Int) => (i == 1) | |
val empty: Set = (i: Int) => false | |
val union: (Set, Set) => Set = | |
(s1: Set, s2: Set) => (i: Int) => s1(i) || s2(i) |