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
Just some random development ramblings mostly related to the Microsoft .NET platform.
Wednesday, March 30, 2016
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
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
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
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
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.
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")%>" />
If you want to use ResolveClientUrl in the master page <head> section for script tags:<script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
<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).
Friday, January 23, 2015
PowerShell: Get a unique list of file name extensions within a directory folder (and sub-folders)
Here is a basic PowerShell script that will provide you a nice list of unique file name extensions for a given directory path. Nothing fancy here, but comes in handle once and a while.
Notice the -Recurse parameter that will drill down every sub-directory as well; remove this if you only want the top level directory.
Woo-hoo!
Notice the -Recurse parameter that will drill down every sub-directory as well; remove this if you only want the top level directory.
Get-ChildItem -Path C:\Scripts -Recurse | Select-Object Extension | Sort-Object Extension | Get-Unique -asString
Woo-hoo!
Saturday, October 25, 2014
Microsoft OWIN: Getting base path for web services (C#)
In my recent post on using OWIN and WebApi, I described how to separate your controllers into a separate DLL. Often the controllers need to call other methods that may need access to the base path of the web service (e.g. the bin folder).
The code below can be used to find that base path from other classes, without having to always pass a path parameter from method to method.
The code below can be used to find that base path from other classes, without having to always pass a path parameter from method to method.
Thursday, October 23, 2014
OWIN hosting using a Separate WebApi Controller DLL
Here is a bare bones demonstration (4 minutes) showing you how to create a standalone class library of a WebApi controller, then hosting the controller in Microsoft's OWIN (in IIS). This is done using Visual Studio 2013 Update 3.
The video can be watched here: YouTube Watch
The source can be downloaded here: Download Source
What do you think?
The video can be watched here: YouTube Watch
The source can be downloaded here: Download Source
What do you think?
Sunday, October 12, 2014
WeightedRandom - Select content based on weights (C# / .NET)
Need to select content from a collection based on weights? Here is a great .NET 4+ class that is very helpful.
The class can be used with just about any collection and you can pass in a delegate/lamda to determine what the weight is on each collection object.
The class can be used with just about any collection and you can pass in a delegate/lamda to determine what the weight is on each collection object.
Subscribe to:
Posts (Atom)
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 ...
-
Don't want Office 2007 installed on your web server to access Excel 2007 content? Here is a Visual Studio C# solution that demonstrates ...
-
I finally found a good algorithm to validate a file path (had to fix two bugs in it though). I use this static method in Windows Forms when...