Menu

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

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

Close the solution

Delete the .vs folder

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.

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:

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.

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:

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:

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.

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.