Saturday, March 11, 2017

Git: Sync a single local repository to both Github and Bitbucket

It turns out to be fairly simple to sync a single local git repository to both Github and Bitbucket. I use SourceTree for my single repository, which originally pointed solely to Bitbucket.  I did an Import of that repository into Github and now want all my commits using SourceTree to push to both remote repositories.

I just modified my local .git/config file to include another pushUrl.  No changes required in SourceTree, but when SourceTree does a push, both remotes will be updated.

Before:

[remote "origin"]
url = https://bitbucket.org/xyz/bitbucket.repository.name
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = https://bitbucket.org/xyz/bitbucket.repository.name

After:

[remote "origin"]
url = https://bitbucket.org/xyz/bitbucket.repository.name
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = https://bitbucket.org/xyz/bitbucket.repository.name
pushurl = https://github.com/xyz/github.repository.name

Wednesday, March 1, 2017

Resolved: Enable CORS on OWIN the right way

I was having difficulty, probably like you, trying to figure out how to get CORS working on a OWIN self-hosted application.  There were so many answers posted, but seemed like so many of them were based on older versions of Visual Studio / .NET.

Here is what I finally found to work for me; hopefully this will help you as well.  This is as of Visual Studio 2015 in early March 2017.

  1. Add nuget packages to the web api project:
    1. Microsoft.AspNet.WebApi.Cors
    2. Microsoft.Owin.Cors (this will also install Microsoft.AspNet.Cors)
  2. Modify startup.cs, Configuration(IAppBuilder app), add this line:

    app.UseCors(CorsOptions.AllowAll);

    and add it before the line:

    app.UseWebApi(config);
  3. Add the following attribute on my web api controller class:

    [EnableCors("*", "*", "*")]
These three steps got things finally working.

Control Raspberry Pi camera (tilt/pan) with C# / Mono

We updated the GpioWeb repository to include an example of how to control a tilt/pan camera hooked up to the Raspberry Pi (2 servos).  This was done in C# / Mono.

See the ServoPanTiltDemo.html file in the GpioWeb.PluginServoSimple directory.

The GpioWeb repository is located at:

Note: Remember that servos are all a bit different so you will need to slightly adjust the following values in the json "config" file (see instructions in the ServoPanTiltDemo.html file); values tend to run in the range of 100 to 700.

  • pwmMinPulse
  • pwmMaxPulse
If you download the GpioExamples repository, there is a servo example that you can run to determine the min/max pulse values for a specific servo.  When you run the example, it will ask for degrees (0 to 180), but if you prefix your input with "!" then it will be interpreted as a raw pulse value.  For example, "!125".  Very helpful.

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

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