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 / 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 / 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)
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 / 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"
@izmailoff
izmailoff / Stats.scala
Created February 8, 2016 00:47
Basic statistics functions (not optimized)
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)
}
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)),
@izmailoff
izmailoff / genDownloadCommands.sh
Created February 4, 2016 06:38
Generates unix commands (wget, youtube-dl) to download files based on the links found on a web page.
#!/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
@izmailoff
izmailoff / check_api.sh
Last active August 8, 2016 10:15
Check webpage/API continuously for availability
#!/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)"
@izmailoff
izmailoff / FormFieldsToJson.scala
Last active March 31, 2023 07:53
Convert `Content-Type: multipart/form-data` to JSON format because I can't read the former
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)
@izmailoff
izmailoff / SchemaMigration.scala
Last active January 21, 2022 18:22
Liquibase for Scala
// 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