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 / install_tensorflow.sh
Last active January 18, 2019 20:58
install tensorflow on Fedora
# install protobuf
sudo dnf install protobuf*
# install bazel
# https://docs.bazel.build/versions/master/install-redhat.html
sudo dnf copr enable vbatts/bazel
sudo dnf install bazel
# get TF src
git clone https://github.com/tensorflow/tensorflow.git
@izmailoff
izmailoff / print_multiplication_table.py
Created September 23, 2017 07:05
Prints multiplication table (for my kid)
#!/usr/bin/env python
print("Multiplication table")
for a in range(0, 11):
print("=============")
for b in range(0, 11):
print(str(a) + " x " + str(b) + " = " + str(a * b))
@izmailoff
izmailoff / ScheduleContinuously.scala
Created December 21, 2016 08:33
Schedules a task to be run continuously without using Akka system or other schedulers
import scala.concurrent._
import ExecutionContext.Implicits.global
object Main extends App {
def repeatEvery[T](timeoutMillis: Int)(f: => T): Future[T] = {
val p = Promise[T]()
val never = p.future
f
def timeout = Future {
@izmailoff
izmailoff / estimate_cpu_count_scala.sh
Last active December 19, 2016 15:48
Estimate number of cores/threads your system can scale to aka cpu count
#!/bin/sh
exec scala -Dscala.concurrent.context.minThreads=16 -Dscala.concurrent.context.maxThreads=64 "$0" "$@"
!#
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import java.util.concurrent.Executors
import scala.concurrent._
@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)
@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_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 / 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 / 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 / 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