Stránky

Saturday, November 26, 2016

Monty Hall problem, host agenda.

Math free explanation of Monty Hall problem.

Key to understanding of why by switching initial selection leads to increased chance of win is to realize how balance is kept during the game.

Each time the decision has to be made two doors are closed. Situation is same for all variants of the game. 3 or 1000 doors.

  • There is one closed door with prize and one closed empty door

That's the natural consequence of game rules. Please think about it until you are pretty sure you understand why.

  • Role of the host is to keep this balance during the game by selecting second door WHICH WILL NOT BE OPENED

This is small shift in thinking about role of the host. Host has its own agenda. Just for a while think about the host as someone who must choose second door which will not be opened. Door(s) opened by the host are not interesting. We need to understand how and why second door was chosen.

  • Every time guest selects empty door, host MUST select the door with prize. 
  • Every time guest selects door with prize, host selects one of the remaining empty doors. 

All other empty doors are opened. Since there are more empty doors and only one door with prize:

  • Guest selects empty door more often, consequently host MUST select door with prize more often.
  • Guest selects door with prize rarely, consequently host rarely selects empty door.

And we are done!
If guest understands that his guess was likely to be incorrect, he can be sure to the same extent that the other closed door MUST contains the prize.

That is the simple mechanics of why changing the decision leads to winning more often.

Tuesday, May 31, 2016

Programming in Rust - Part 1:Modules and Libraries

After a few years of Java development it's time to look for interesting features new languages can offer. Choice came down to Go, Erlang/Elixir and Rust. I'll talk about how I came to these three in another post. For now it is important to note that my personal favorite is Rust.

Tutorial will be written as a diary while developing simple and/or trivial projects. I'll not cover Rust syntax. Rust programming language has really excellent tutorial at Rust book.

Modules vs Libraries


First lesson is to understand how Rust splits code into logical parts. Rust has source files (*.rs), modules and libraries - known as crates in rust terminology. I have come into confusion over Rust keywords related to usage of libraries and modules.

First create basic Rust project. We will use Cargo a build system which comes as part of a Rust install package.

Dedicate some directory to your Rust projects and within this directory create new Rust library project.

> cargo new mylib
> cd mylib/src

Inside created project you'll find src directory with lib.rs file. Cargo uses lib.rs as root module for library project, and main.rs for executable project. We'll create new executable root main.rs and two module files. This way we can experiment with modules and libraries within one project.

> touch main.rs
> touch moda.rs
> touch modb.rs
> cd ..
Insert following content into main.rs.

// file: src/main.rs
fn main() {
    println!("Hello World!");
}
Run application by:

> cargo run

Monday, May 2, 2016

CoreOS from scratch - Part 2: etcd

In previous post you have learned how to install three CoreOS instances on VirtualBox. Today we'll focus on creating etcd cluster.

Etcd is distributed key value store. Using etcd, CoreOS cluster shares configuration parameters. Etcd is used as well for sharing configuration information's between deployed applications.

There are several ways of how to create CoreOS cluster https://coreos.com/etcd/docs/latest/clustering.html '. We'll use public etcd discovery service one.

Start all CoreOS instances


First step is to boot all three CoreOS instances. After instances are up and running use ssh client to connect.

Obtain etcd token


Since we'll be using public etcd discovery service, we'll need to obtain unique token which will be used for our cluster members. Token can be obtained at:

https://discovery.etcd.io/new?size=3

Save returned token. We will use the same one for each cluster member.

Tuesday, April 26, 2016

CoreOS from scratch - Part 1: OS installation

In the "CoreOS from scratch" series I'll try to explain how to install CoreOS three node cluster on VirtualBox using manual process. I believe that understanding installation "the hard way" leads to better understanding of whats going on by using CoreOS with Vagrant as well as helps you to install CoreOS on bare metal.

But first really very fast description of what CoreOS is.

CoreOS is just like any other Linux Distro based on Gentoo.

Gentoo wiki states:

CoreOS is a new Linux distribution that has been rearchitected to provide features needed to run modern infrastructure stacks.

I think this describes CoreOS quite well. CoreOS is Linux operating system that is specially made to run containers (containerized applications) like Docker or Rocket. Meaning it is not operating system you would like to use for desktop, or as typical Linux server where you install any software your corporate IT environment needs. Besides running containerized applications CoreOS comes with full stack of tools needed to form and operate clusters.