## Do I have an evil eye? (A bayesian proof that I don’t)

My mom says that I have an evil eye. Her claim is based on some evidences. One of the evidences are as follows:

Once I was in car, in a highway with my family. A nice car took us over speeding. I said something about the car, and a few minutes later we saw the car had an accident at the side of the highway.

So does that mean I have an evil eye? Isn’t the probability of someone talking about a car and the car crash a few minute later rare enough to be considered weird?

I would argue NOT! And prove it mathematically. Read on.

Having no additional knowledge, the P of me talking about a car and the car crashes in a few minutes is close to zero. However, there are a few more points to consider and the situation is not that simple. I would re-phrase the problem as:
“Having a speeding car that passed me and has had an accident, what is the probability that I have talked about it?”

Let’s gather some information. Please note that we limit the world to the cars that have passed me in the highway during my life:

First, the car that has had an accident has been speeding. Let’s say that P of a car that has accident in highway, have also been speeding is about 0.4. It is reasonable to assume most of the cars that crash in highways have been speeding. We call this P(S|X) = 0.4 (X for accident and S for speeding).

Second, I have talked about a car that took us over in highway, speeding. Actually I know this part! The P of me saying something about a car that takes us in a highway speeding is about 0.1. Let’s call this P(T|S) = 0.1. (T for talk and S for speeding).

Last thing I need is the P of a car being speeding having I talked about it in highway. P(S|T) which by experience I can say it is about 0.15.

So, the final question is formulated as what is the probability of me, speaking about a car having it has been speeding, and have had an accident?

Using the Bayes rule, we come up with the following formula:

P(T|S,X) = [P(T|S).P(S|X,T)] / [P(T|S).P(S|X,T) + P(~T|S).P(S|~T,X)] = [0.1*0.4*0.15]/[0.1*0.4*0.15+0.9*0.4*0.85] = 0.019

So, the probability of the accident which my mom considered extremely rare is actually more than 1.9%! Not so rare all of a sudden!

## An IoC Container for Dart (with Autofac like API)

I enjoy throwing Darts, and have been using it quiet a bit recently. The OO nature of Dart makes it suitable for most OO design patterns. I use the inversion of control patter almost everywhere, but Dart did not have a good IoC container library that I knew of. Hence, in order to give something back to the community I wrote a lightweight IoC container based on the API of my favorite “Autofac”. The main reason for this choice was that a C# programmer who has already worked with Autofac can start using “Autodart” in a few minutes!

Below is a sample of how Autodart can be used:

```class Baz{
}

class Bar{
Baz baz;
Bar(this.baz);
}

class Foo{
Bar bar;
Foo(this.bar);
}
void main(){
var b = new AutoBuilder();
b.register((c, p) => new Baz())
.As("Baz")
.singleInstance();

b.register((c, p) => new Bar(c.resolve("Baz")))
.As("Bar")

b.register((c, p) => new Foo(c.resolve("Bar")))
.As("Foo"); //Default is .instancePerDependency()

var c = b.build();

var foo = c.resolve("Foo") as Foo;
var foo2 = c.resolve("Foo") as Foo;

assert(foo != foo2);
assert(foo.bar === foo2.bar);
assert(foo.bar.baz === foo2.bar.baz);

/*
Other supported API include:
b.register(..).As(..).externallyOwned();
c.resolveLazy("Foo") as Lazy<Foo>;
var childScope = c.createLifetimeScope();
c.dispose(); //Disposes all disposables in the scope
*/
}
```

Autodart supports the following scopes: SingeInstance (Singleton), InstancePerLifetimeScope (Nester Scopes), and InstancePerDependency.

It also defines the Disposable concept, and manages the scopes for Disposable objects.

Shortcomings: There is no auto wiring, as Dart does not yet support reflection. Also there is still no “Type” type in Dart, so string type names are used as keys. I would update the library as soon as dart adds support for reflection.