Skip to content

Instantly share code, notes, and snippets.

View izmailoff's full-sized avatar
🎯
Focusing

Aleksey Izmailov izmailoff

🎯
Focusing
View GitHub Profile
@izmailoff
izmailoff / FindReadPositionInGenome.scala
Created February 13, 2016 03:32
Solution for https://courses.edx.org/courses/course-v1:ColumbiaX+DS102X+1T2016 - You are given the following five 14-long reads below. Map them to the sequence of the gene responsible for the ABO blood type , keeping in mind that each read might include a single nucleotide error. Report their respective starting positions along the gene (answers…
// 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"
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] = {
@izmailoff
izmailoff / Perms.scala
Created April 14, 2016 03:34
Implementation of permutations in Scala (functional, recursive, lazy)
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)
@izmailoff
izmailoff / deeplearning4j.properties
Created April 18, 2016 09:27
Set these JVM args with -D flag to avoid using native BLAS library and use Java impl instead for deeplearning4j.
-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
@izmailoff
izmailoff / profile_system.py
Created June 25, 2016 07:54
Cross-platform Python script for collecting CPU and memory usage
# 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
@izmailoff
izmailoff / New_Right_Biased_Either_example.scala
Last active February 13, 2018 09:35
Illustrates the use of the new implementation of Either that supports map, flatMap, etc. It's available since 2.12.0-RC1.
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] =
@izmailoff
izmailoff / string_list_parser.scala
Created September 26, 2016 03:05
Just an example of matching arbitrary length of list with a list of matchers (PF)
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" })
@izmailoff
izmailoff / Function_composition_in_scala_example.scala
Created September 29, 2016 05:59
One of the ways to compose functions
val add1 = (x: Int) => x + 1
val add100 = (x: Int) => x + 100
val square = (x: Int) => x * x
val allFunctions = List(add1, add100, square)
@izmailoff
izmailoff / functional_take_first_n_elements_list.scala
Created September 29, 2016 08:25
Take first n elements from scala list example - functional
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)
}
@izmailoff
izmailoff / function_set_scala_example.scala
Last active December 15, 2017 03:44
Example of functional sets in Scala
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)