Remove all images:
docker images --format "{{.ID}}" | xargs docker rmi
Stop and remove all containers:
docker ps -a --format "{{.ID}}" | xargs docker kill
docker ps -a --format "{{.ID}}" | xargs docker rm
Remove all images:
docker images --format "{{.ID}}" | xargs docker rmi
Stop and remove all containers:
docker ps -a --format "{{.ID}}" | xargs docker kill
docker ps -a --format "{{.ID}}" | xargs docker rm
//Let's say we have a list of Ints and function f from Int to Option: | |
val list = (1 to 10).toList | |
//List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
val f = (x: Int) => if (x%2==0) Some(x*2) else None | |
//f: Int => Option[Int] | |
//Now I'm going to apply f to the elements of the list and filter out empty results: | |
list map f flatten |
/* | |
for the test purposes function getValueAsync imitates some heavy lifting | |
and returns type constructor parametrized by T (same for getValueOpt) | |
in real life these could be different functions returning some type | |
constructors like Option, List and Future which values | |
should then be passed to a function which takes proper types | |
Apply type class from cats has methods with a flavor like that: |
type Payload = Array[Byte] | |
trait Driver { | |
def send(payload: Payload) | |
} | |
//a component which depends on Driver interface | |
class Sender(val driver: Driver){ | |
def send(message: String) = driver.send(message.getBytes) | |
} |
/* | |
Test: tail recursive map vs imperative map | |
*/ | |
object TailrecTest extends App{ | |
def measure[A](f: => A): (A, Long) = { | |
val start = System.currentTimeMillis() | |
(f, System.currentTimeMillis() - start) | |
} | |
/* |
object RabbitToRabbitFlow extends App { | |
implicit val actorSystem = ActorSystem("rabbit-akka") | |
implicit val materializer = ActorMaterializer() | |
val config = ConfigFactory.load("application.conf") | |
val sourceConnection = Connection(config.getConfig("source")) | |
val targetConnection = Connection(config.getConfig("target")) | |
val rabbitConsumer = Source.fromPublisher(sourceConnection.consume(config.getString("source.queue_name"))) |
maximum' :: (Ord a) => [a] -> a | |
maximum' = foldr1 (\x acc -> if x > acc then x else acc) | |
reverse' :: [a] -> [a] | |
reverse' = foldl (\acc x -> x : acc) [] | |
product' :: (Num a) => [a] -> a | |
product' = foldr1 (*) | |
filter' :: (a -> Bool) -> [a] -> [a] |
//single parameter function for different types | |
trait Size[A] { | |
def size(a: A): Int | |
} | |
def size[A: Size](a: A): Int = implicitly[Size[A]].size(a) | |
implicit object StringSize extends Size[String]{ | |
override def size(a: String): Int = a.length | |
} |
# Docker =========================== | |
# MacOS specific command to connect from host machine: cqlsh `boot2docker ip` | |
# Cassandra 1.2.9 | |
listen_address: 127.0.0.1 | |
rpc_address: 0.0.0.0 | |
# Cassandra 2.1 | |
listen_address: 127.0.0.1 | |
rpc_address: 0.0.0.0 |
package io.datastrophic | |
trait Monoid[A]{ | |
def append(a1: A, a2: A): A | |
def unit: A | |
} | |
object Monoid{ | |
implicit val IntMonoid = new Monoid[Int]{ | |
def append(a1: Int, a2: Int): Int = a1 + a2 |