Cofee shop closing down.

Based on a recent law, every cofee shop operating in Tehran has to install cameras monitored by government. These emotional photos depict the last day at Cafe Perague, which did not accept to install cameras and had to close down.

Quickly Count Number of Lines of Code in Your .Net Project

This new year holidays, my wife was busy working and getting ready for her IELTS exam, so there was no vacation. I took this chance to work on a project I have been dreaming about last year long.

The holidays are over and I have to go back to my daily job from monday, so I decided to count the number of lines I’ve been writing this christmas. This could give me in indication of how much fun I have these days. So I opened the powershell console and ran the following commands. My project doesn’t have much generated code, so I can say the results seem to be a rough estimate of reality.

cd \ProjectDirectory
$cs = ls -recurse -filter *.cs | gc | where {$_.Trim().Length -gt 5}
$sql = ls -recurse -filter *.sql | gc | where {$_.Trim().Length -gt 5}
$view = ls -recurse -filter *.cshtml | gc | where {$_.Trim().Length -gt 5}
$cs.Count + $sql.Count + $view.Count


Of course the above number is just a joke. I couldn’t possibly write a million lines in a couple of weeks even if I’ve had my keyboard connected to the treadmill!

Wish you all a successful and merry 2013.


Easiest way to remember Covariance and Contravariance

I have seen people struggling to remember the definition of co and contra variance. Below are a few lines of code that help you keep it in mind. Just ignore the fancy names but remember that in .Net we use <in T> and <out T> instead of the fancy names when defining the type of variance allowed in generics. That should be enough for 100% of times.

in: CollectionAdder<Cat> is CollectionAdder<Animal> // Can add cats to a list of animals
 CollectionAdder<Dog> is CollectionAdder<Animal>
 CollectionAdded<Animal> is NOT CollectionAdder<Cat> // Can not add animals to a list of cats (animals can be dogs)

out: CollectionGetter<Cat> is NOT CollectionGetter<Animal> // Can not read cats out of a list of animals (animals can be dogs)
 CollectionGetter<Animal> is CollectionGetter<Cat> // Can read a bunch of animals out of a list of cats, all cats are animals by the way
 CollectionGetter<Animal> is CollectionGetter<Dog>