Learn Open Source – Free self-taught Computer Science for everyone (and pointers to learn stuff quickly)

Hello World,

(Apologies for the long title, but it is the best I could come up with to capture the essence of what this post is about)

So, the other day a colleague posted a fun fact about how Microsoft is now the leading contributor to open source projects on Github. You can find the data on Octoverse. I encourage the reader to check this page out – it also presents data on what’s trending on Github in terms of most starred projects and one can get a general sense of the next big thing in OSS world.

Reading through, I came across a repo called Computer Science by Open Source Society. Check it out here. What evoked my interest is the following quote under the section “Motivation and preparation”: A motivational video that shows how someone went through the entire curriculum of MIT computer science in 1 year! This is followed by a link to a MOOC that teaches the student techniques to learn to learn.

(MOOC = Massive Open Online Course for those who haven’t heard of the term before. Simply put, a MOOC is a course of study made available free of charge for anyone to enroll and learn at their own pace)

Now, take my word for this, as a professional software developer, I can vouch for the fact the ability to learn and keep learning is the one skill that can help one stay and grow in their career like no other. The inimitable John Sonmez has an excellent course on 10 steps to learn anything quickly. There’s also this great book by Josh Kaufman that talks about how to remove barriers to optimal learning. The book develops the idea presented by Josh in his Ted-Talk

Coming back to the Github repo, it has a wealth of information on computer science and even for those who have been lucky to have learnt this at college, the material is a great refresher to get the cerebral juices flowing.

Happy Learning!

SM

Tagged with: , ,
Posted in Open-source

IIS Express 500.19 Cannot read configuration file – because it’s looking at the wrong path!

Hello World!

Here’s a gotcha! I discovered while working on an ASP.NET MVC 5 solution in VS 2015. While refactoring the code, I needed to debug some code in the Global.asax.cs and thus changed the project properties to run using IIS Express instead of local IIS.

[If you’re wondering why IIS Express for debugging the startup code, check out this excellent post from Rick Strahl that goes over various ways you can debug initialization code HERE]

The Issue

Now, every time I tried running with a debugger attached (F5), I got hit by a 500.19 error code that basically seemed to suggest that by web.config is fried. At first, I tried commenting various sections in web.config to ensure I haven’t messed up any config but couldn’t spot anything that would cause the breakage.

What do programmers do when stuck (and when all attempts to restore sanity fail)? Well, no prizes for guessing, Google for a stackoverflow thread that (fingers crossed) has a solution. Luckily, I didn’t have to strain my fingers much as a gentleman had graciously shared this on StackOverflow

The Solution: Look at thy hidden folders

It turns out, with VS 2015, the visual studio team listened to many developers like Mr. Balassy and added the .vs folder to hold (almost) all of the per-user settings files – the likes of user options (.suo) et al. One of these is the applicationHost.config to control machine level IIS Express settings for the current solution. This file resides at the following place: your solution root (the place where .sln file lives) –> .vs –> config –> applicationhost.config. As visual studio can recreate this file and the entire .vs folder again, the straightforward (and easy ;-)) solution is to

  1. Close the solution
  2. Delete the .vs folder
  3. Reopen the solution again and in the web project settings, re-configure to debug with IIS express.

Unless you’re having a really bad dream, you should have lift-off at this stage.

Further Reading

About applicationhost.config on Technet

 

 

 

Tagged with: , ,
Posted in ASP.NET, IIS-Express, Web-Development

C# 6.0 Features Not Working with MVC 5 / Visual Studio 2015 / Razor

Hello World,

I ran into this problem today while mucking around with the installed Nuget packages and web.config of an MVC 5 project where the Razor views started showing up an error while using the C# 6 String interpolation feature. There was a squiggly line under all string interpolation expressions and when I pointed to it, the error said “Cannot use C# 6 feature with C# 5”. When run, there was the dreaded YSOD (Yellow Screen Of Death for the uninitiated) that said:

CS1525: Invalid expression term ‘$’

Here’s a discussion on Stackoverflow on this topic that helped.

The Issue

I had accidently uninstalled the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget package, so Razor didn’t recognize that C# 6 should be used. The mentioned Nuget package uses Roslyn as the compiler platform.

The Solution

  1. Install the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget package.
  2. (This is required only if you don’t already have the mentioned section in Web.config) Add the following XML fragment in your root web.config
<configuration>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

After adding the DotNetCompilerPlatform package and the system.codedom section, Razor was happy with all C# 6 features being used in the views🙂
Further reading:

Happy Coding!

SM

Tagged with: ,
Posted in .NET, ASP.NET, C#, Web-Development

WCF service startup error “This collection already contains an address with scheme http”

Hello World,

Today, I was trying to setup a simple WCF service on my hosting service smarterasp.net (they are superb! I’ve been using them for about two weeks and it has been a breeze to setup websites and applications using their control panel. I came across them through a thread about hosting options for ASP.NET on Quora)

So, while setting up the service with basic HTTP binding, everything ran fine on my dev machine (it always does right?!) but when I deployed to the hosting site using VS Deploy, I ran into a YSOD (yellow screen of death for the uninitiated) that complained

“This collection already contains an address with scheme http”.

To be fair, the error screen described the fix as well, but to be a 100% sure, I looked up the error and found this stackoverflow thread:

Source: WCF service startup error “This collection already contains an address with scheme http”

I followed the configuration based solution described in the accepted answer and was able to get the service running absolutely fine.

In summary, I added this in the Web.config:

<system.serviceModel>
    <serviceHostingEnvironment>
        <baseAddressPrefixFilters>
            <add prefix="http://mydomain"/>
        </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
</system.serviceModel>
Hope this helps.

Happy Coding! 
Posted in Uncategorized

makecert and creating ssl or signing certificates | brockallen

This makecert script works perfectly to generate a token signing certificate usable with IdentityServer3. For some reason that I’m yet to uncover, the newer Powershell way on Windows 10 generates a cert that the signing piece in IdentityServer does not like. The powershell cert causes an exception like so:

IDX10614: AsymmetricSecurityKey.GetSignatureFormater( ‘http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&#8217; )
threw an exception.
Key: ‘System.IdentityModel.Tokens.X509AsymmetricSecurityKey’\nSignatureAlgorithm: ‘http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&#8217;,
check to make sure the SignatureAlgorithm is supported.
Exception:’System.Security.Cryptography.CryptographicException:
Invalid provider type specified.

The original post follows:

I’ve been asked to post my makecert scripts for creating self-signed certificates (one for SSL and the other for signing). I use both of these scripts as .bat files. These scripts accept one …

Source: makecert and creating ssl or signing certificates | brockallen

Posted in Uncategorized

10 tips for better Pull Requests

Source: 10 tips for better Pull Requests

Posted in Uncategorized

Avoiding an Identity Crisis (in your apps)

Summary

This post introduces the NewId library created by the awesome guys behind MassTransit service bus. The content may look similar to the readme of the NewId lib – because that was contributed by yours truly🙂

What is this about?

Right, so why are we here again? Good question! Here’s why: say in your code, an entity requires a unique ID – A Customer ID, Order ID, Message ID … you get the point, I believe. A number of applications use unique identifiers to identify a data record. A common way for apps that use a relational database (RDBMS) is to delegate the generation of these IDs to the database – by means of a Identity column (MS-SQL) or similar. This approach is fine for a small app, but quickly becomes a bottleneck at web-scale. See this post from the blokes at twitter: https://blog.twitter.com/2010/announcing-snowflake.  An apps based on microservices architecture may require sequential unique IDs for messages.

The Options (trivial ones)

A trivial approach is to use GUIDs/UUIDs generated in applications. While that works, in most frameworks GUIDs are not sequential. This takes away the ability to sort records based on their unique ids.

The Solution

The Erlang library flake (https://github.com/boundary/flake) adopted an approach of generating 128-bit, k-ordered ids (read time-ordered lexically) using the machines MAC, timestamp and a per thread sequence number. These IDs are sequential and wouldn’t collide in a cluster of nodes running applicaitons that use these as UUIDs.

The NewId library can be used as an embedded unique ID generator that produces 128 bit (16 bytes) sequential IDs. It is inspired from snowflake and flake. Read on to learn more.

Getting the Library

The easiest (and recommended) way to get it is NuGet:

Install-Package NewId

Sample Code

NewId id = NewId.Next(); //produces an id like {11790000-cf25-b808-dc58-08d367322210} // Supports operations similar to GUID NewId id = NewId.Next().ToString(D).ToUpperInvariant(); // Produces 11790000-CF25-B808-2365-08D36732603A // Start from an id NewId id = new NewId(11790000-cf25-b808-dc58-08d367322210); // Start with a byte-array var bytes = new byte[] { 16, 23, 54, 74, 21, 14, 75, 32, 44, 41, 31, 10, 11, 12, 86, 42 }; NewId theId = new NewId(bytes);

Caveat Emptor aka Do not use if

(Adapted from the flake readme) The generated ids are predictable by design. They should not be used in scenarios where unpredictability is a desired feature. These IDs should NOT be used for:

  • Generating passwords
  • Security tokens
  • Anything else you wouldn’t want someone to be able to guess.

NewId generated ids expose the identity of the machine which generated the id (by way of its MAC address) and the time at which it did so. This could be a problem for some security-sensitive applications.

Don’t do modulo 2 arithmetic on flake ids with the expectation of random distribution.

Happy Coding!

SM

Posted in Uncategorized
  • Comic for September 29, 2016
    Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.