Sunday, April 17, 2016

Zipf distribution using .NET / C#

Zipfian distribution, named after American linguist George Zipf, is often used to demonstrate the Pareto principle that states 80% of the effects come from 20% of the causes.

Attached is a small C# class library that demonstrates this principle (Visual Studio 2015, C# 4.6.1).  The class library allows you to provide an IEnumerable collection that will be examined for the 80% / 20% principle.

The class library is easy to use and two (2) examples are provided along with the source code.

Examples:

1) ConsoleWordCount - Reads all words from the book, War and Peace, and reports on the 80% / 20% principle.  This is modeled after a single set of text where each datum (i.e. word) is a single occurrence to be examined.

2) ConsoleStatePopulation - Reads individual records comprised of both a state name and a population, and reports on the 80% / 20% principle.  This demonstrates how specific records (i.e. objects comprised of multiple properties) can also be used by the Zipf class library.

Download source and example code now!

Also, there is a nice video by vsauce on Zipf on youtube.

Enjoy!

Wednesday, March 30, 2016

Best regular expression for phone number that accepts many variations

Here is a handy regular expression that will accept many variations of an U.S. phone number, allowing the input to be somewhat flexible.

^\s*[(]?\d{3}[).\-]?\s*\d{3}(\s*|[.\-]?)\d{4}\s*$

// accepted
8015551212
801 555 1212
(801)5551212
801.555.1212
801.555-1212
801-555-1212
(801)555-1212
(801) 555-1212
801-555.1212
(801 555 1212
(801 555 1212
801)5551212

// rejected
8015551212a
80155512122
801a5551212
8015;551212
(801))5551212

Friday, February 19, 2016

.NET async / await - Great article on best practices (must read)

This is probably the best article I've read on the best practices on using async and await in .NET. It does a great job of explaining return types, exceptions, SynchronizationContext (how I originally stumbled on the article), and the differences between console apps, web apps, and GUI apps.

Definitely worth a read...twice.

https://msdn.microsoft.com/en-us/magazine/jj991977.aspx

I've also attached a PDF of the content in case you want to save that off.

Download PDF

Friday, February 12, 2016

Favorite Videos to watch...

I thought I should start a list of my favorite videos.

The surprising truth about what motivates us
https://youtu.be/u6XAPnuFjJc

Spotify Engineering Culture (Part 1)
https://www.youtube.com/watch?v=Mpsn3WaI_4k

Spotify Engineering Culture (Part 2)
https://youtu.be/X3rGdmoTjDc

Product Strategy in 7 Minutes
https://vimeo.com/81544164

Friday, January 15, 2016

TPL extension and samples library from Microsoft (Parallel Programming)

This is a repost to the Microsoft TPL (task parallel library) samples library at:

https://code.msdn.microsoft.com/ParExtSamples/Release/ProjectReleases.aspx?ReleaseId=4179

This sample includes example applications and library functionality that demonstrate, utilize, and augment this support (it is not production quality). This sample is a single .zip containing a single Visual Studio .sln file, which then contains multiple Visual Studio projects that highlight key capabilities provided by the .NET Framework 4 and the parallel programming support it provides. Below are descriptions of the included examples.

Specifically, if you are looking for the TPL extensions extras, visit the samples page and search for "ParallelExtensionExtras".

In case this page ever disappears, the samples download can also be downloaded here.

https://drive.google.com/file/d/0B6o_2blMHEfRbmJaRklOUDhHR2s/view?usp=sharing

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...