Tuesday, February 21, 2017

C# / Mono servo control added for Raspberry Pi

Due to several requests, we added support to control a servo in the C# Mono repositories for the Raspberry Pi. This includes both the GpioExamples and GpioWeb (extensible web service) repos.  You can find the latest updates below.

GPIO Examples
https://bitbucket.org/PaulTechGuy/raspberrypi.dotnet.gpioexamples

GPIO RESTful Web Service
https://bitbucket.org/PaulTechGuy/raspberrypi.dotnet.gpioweb

Friday, February 10, 2017

Great GPIO web service for the Raspberry Pi (.NET C#)

I finally got around to updating all the new C# repositories for controlling GPIO from C#. This includes a repo for C# GPIO examples, as well as a super cool C# RESTful web service to control the GPIO pins (extensible architecture).  This was written in Microsoft Visual Studio 2015, .NET 4.6+.

Enjoy.

GPIO Examples
https://bitbucket.org/PaulTechGuy/raspberrypi.dotnet.gpioexamples

GPIO RESTful Web Service
https://bitbucket.org/PaulTechGuy/raspberrypi.dotnet.gpioweb

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

Wednesday, September 30, 2015

Raspberry Pi / Windows 10 Iot - Getting Started

Microsoft updated their Iot Windows 10 content for several platforms, including the Pi.  I started from scratch getting my Pi hardware installed with Windows 10 (core) on the Pi, then proceeded to use Visual Studio 2015 to get my lil' LED light blinking.  Surprisingly I was able to stay within Visual Studio the entire time to write the C# code (no Mono involved), compile, deploy, and execute the application remotely on the Pi (oh yes...even debug the code executing remotely on the Pi).  The latest help/instructions from the Microsoft side have been updated to walk you through the steps in enough detail to be successful without having to search to the end of the Internet for answers.

Here are a few links that lay out the short journey (all you need to have is your Pi assembled).  The last link is the new C# Microsoft GPIO (General Purpose Input/Output hardware pin headers) library which makes is really nice to interface to the hardware.

Download Windows 10 for Raspberry Pi
http://ms-iot.github.io/content/en-US/Downloads.htm

Getting Started (select Raspberry Pi)
http://ms-iot.github.io/content/en-US/GetStarted.htm

Raspberry Pi Source Code Examples
https://github.com/ms-iot/samples/archive/develop.zip

C# Windows.Device.Gpio namespace
https://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.gpio.aspx

Saturday, February 14, 2015

Powershell to add Read permission on all files in a directory

Recently I needed to update all the files in a specific directory, adding Read permission for the "Users" NTFS group.  Here is a Powershell script to do that.  It can be easily modified to update other users/groups or different permission sets.

$base = "C:\somefolder"
$files = get-childitem $base
foreach ($file in $files) {
    $Acl = Get-Acl $file.FullName
    $Ar = New-Object  system.security.accesscontrol.filesystemaccessrule("Users","Read","Allow")
    $Acl.SetAccessRule($Ar)
    Set-Acl $file.FullName $Acl
}

Wednesday, February 4, 2015

Basic rules for using ResolveClientUrl in master pages (ASP.NET)

When writing ASP.NET Web Forms, the basic rules for using ResolveClientUrl in master pages are:
<img src="<%= ResolveClientUrl("~/x/resource.jpg")%>" />
<script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
If you want to use ResolveClientUrl in the master page <head> section for script tags:
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
   <script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
</asp:PlaceHolder>

You do not need to use ResolveClientUrl for CSS link elements in the <head> section (they will automatically be resolved by ASP.NET).

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 ...