Skip to content

Instantly share code, notes, and snippets.

View DmitryBe's full-sized avatar

Dmitry B DmitryBe

View GitHub Profile
@DmitryBe
DmitryBe / Retry.scala
Created August 4, 2016 13:28 — forked from Mortimerp9/Retry.scala
A retry implementation for Scala, a bit of explanations here: http://pierreandrews.net/posts/retry-fail-scala.html
import scala.concurrent.Await
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.blocking
import scala.concurrent.duration.Deadline
import scala.concurrent.duration.Duration
import scala.concurrent.duration.DurationInt
import scala.concurrent.duration.DurationLong
import scala.concurrent.future
import scala.concurrent.promise
@DmitryBe
DmitryBe / hyperLogLogExample.scala
Last active January 31, 2017 09:17
Algebird Hyper Log Log
import com.twitter.algebird.HyperLogLogMonoid
//define test data
val data = Seq("aaa", "bbb", "ccc")
//create algebird HLL
val hll = new HyperLogLogMonoid(bits = 10)
//convert data elements to a seq of hlls
val hlls = data.map { str =>
val bytes = str.getBytes("utf-8")
hll.create(bytes)
@DmitryBe
DmitryBe / example.scala
Created February 3, 2017 04:47
scala akka dependency management using cake pattern
import akka.actor.Status.Failure
import akka.actor.{Actor, ActorLogging, ActorRef, ActorRefFactory, ActorSystem, PoisonPill, Props}
import akka.dispatch.ExecutionContexts
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest._
import scala.concurrent.duration._
import akka.pattern.{ask, pipe}
import akka.util.Timeout
/*
@DmitryBe
DmitryBe / pf.scala
Created February 6, 2017 01:08
Scala: Combine several partial functions into one
val a: PartialFunction[String, Int] = { case "a" => 1 }
val b: PartialFunction[String, Int] = { case "b" => 2 }
val c: PartialFunction[String, Int] = { case "c" => 3 }
val ab = a orElse b // combine functions a and b
ab("a") // 1
ab("b") // 2
ab("c") // MatchError
@DmitryBe
DmitryBe / example.sh
Last active February 7, 2017 08:19
redis && spark
# docker image: https://hub.docker.com/_/redis/
# start redis server with append
docker run -itd --name redis --net=host -v /docker/redis/data:/data redis redis-server --appendonly yes
# start redis cli (localhost)
docker run -it --net=host --rm redis redis-cli -h localhost -p 6379
# get multiple values
MGET key1, keyN
@DmitryBe
DmitryBe / round.java
Created February 15, 2017 00:49
Round double with required precision
// using math.pow
public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
long factor = (long) Math.pow(10, places);
value = value * factor;
long tmp = Math.round(value);
return (double) tmp / factor;
}
@DmitryBe
DmitryBe / vim_tutorial.txt
Last active February 20, 2017 02:19
vim tutorial
### Pattern matching
1. CTRL-G displays your location in the file and the file status.
G moves to the end of the file.
number G moves to that line number.
gg moves to the first line.
2. Typing / followed by a phrase searches FORWARD for the phrase.
Typing ? followed by a phrase searches BACKWARD for the phrase.
@DmitryBe
DmitryBe / build_tensorflow.sh
Last active February 23, 2017 03:59
build tensor flow with bazel
# install dependencies
sudo apt-get install python-pip python-dev
pip install --upgrade pip
sudo apt-get install openjdk-8-jdk git python-dev python3-dev python-numpy python3-numpy build-essential python-pip python3-pip python-virtualenv swig python-wheel libcurl3-dev
# install bazel
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
sudo apt-get update
@DmitryBe
DmitryBe / .tmux.conf
Created February 23, 2017 03:59
tux help
set -g prefix `
bind ` send-keys `
unbind %
bind \ split-window -h
bind - split-window -v
@DmitryBe
DmitryBe / example_couner_service.sh
Last active February 23, 2017 05:20
implement simple counter service using python && tornado sync
COUNTER_URL=http://172.17.6.114:8888/count
# get uniq increment val by key
curl ${COUNTER_URL}/my_key
# reset counter by key
curl -X DELETE ${COUNTER_URL}/my_key
# post key value
curl -X POST -d '{"key": "my_key", "val": "some_value"}' ${COUNTER_URL}/count