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 / 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 / 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 / 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 / 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 / setup_docker_fedora.sh
Created October 22, 2017 08:13
Setup docker on Fedora without sudo
sudo dnf install docker
# Start/enable service
sudo systemctl start docker
sudo systemctl enable docker
# Allow docker to run without sudo/root privs
sudo groupadd docker && sudo gpasswd -a ${USER} docker && sudo systemctl restart docker
newgrp docker
@izmailoff
izmailoff / functional_sets_in_python.py
Last active December 15, 2017 03:37
Example of functional sets in Python
set_of_1 = lambda i: i == 1
set_of_1(1)
set_of_1(2)
empty = lambda i: False
empty(1)
@izmailoff
izmailoff / ExpressionProblemWithImplicits.scala
Last active February 13, 2023 13:00 — forked from elnygren/expression_problem.clj
Solving the Expression Problem with Scala's Implicits
object Main extends App {
import math._
// The Expression Problem and my sources:
// http://stackoverflow.com/questions/3596366/what-is-the-expression-problem
// http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/
// http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/
// http://www.ibm.com/developerworks/library/j-clojure-protocols/
@izmailoff
izmailoff / expression_problem.hs
Created January 2, 2018 08:47 — forked from chrisdone/expression_problem.hs
Solving the Expression Problem with Haskell
{-# LANGUAGE NamedFieldPuns #-}
-- The Expression Problem and my sources:
-- http://stackoverflow.com/questions/3596366/what-is-the-expression-problem
-- http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/
-- http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/
-- http://www.ibm.com/developerworks/library/j-clojure-protocols/
-- To begin demonstrating the problem, we first need some
@izmailoff
izmailoff / max_subarray.py
Created February 9, 2018 05:49
Implements maximum subarray algorithm as described in: https://en.wikipedia.org/wiki/Maximum_subarray_problem
def max_subarray(xs):
if not xs:
return [], 0
start = 0
end = 1
cur_sum = 0
max_sum = xs[0]
for i in range(len(xs)):
tmp_sum = cur_sum + xs[i]
if xs[i] > tmp_sum:
@izmailoff
izmailoff / balanced_binary_tree.py
Created February 12, 2018 06:06
A function that checks if binary tree is balanced
def height_min_max(tree):
if not tree:
return 0, 0
else:
_, l, r = tree
lmin, lmax = height_min_max(l)
rmin, rmax = height_min_max(r)
return 1 + min(lmin, rmin), 1 + max(lmax, rmax)