ASP.NET Core web API

Some nice links.

Return Status Codes:


Factory Pattern in Python

I recently used the factory Pattern in Python.

It was a little surprising to me comparing typical usage of this pattern in C# v/s Python.

In particular, in C# you’s typically have an Interface defining the methods and then provide an implementation of these methods in the concrete classes.

In Python, there is no interface – In the example above I embed a static  method in the base  to select the appropriate derived class.

Handling Exceptions.

Some simple examples for exception handling:



x = 10
y = 20
    if x > y:
        print "abcd"
#        dividing by 0
        print 2 / 0

except Exception as e:
    print "hit an exception : {0} : {1}".format(e, e.message)

#hit an exception : integer division or modulo by zero : integer division or modulo by zero

In Python there are two keywords related to exceptions:

  • pass.
    • Think of this as same as continue.
  • raise
    • If we want to bubble up the exception, then ‘raise’ it . Else the exception is suppressed.

Shuffling and Splitting Operations

Shuffling is a pretty interesting operation in several scenarios. And different languages / platforms have  interesting features using the shuffling  operation.


  • Shuffle the contents of a C# List
  • Select random lines from file  (using ‘shuf’ command in Linux)




JSON DateTime

“DateTimes in JSON are hard.

The problem comes from the JSON spec itself: there is no literal syntax for dates in JSON. The spec has objects, arrays, strings, integers, and floats, but it defines no standard for what a date looks like.”







Multi-dimensional arrays in Python and C#

While solving a problem which requires representation in matrix form, one requires close understanding of how to represent multi-dimensional arrays.

I was trying to explore how to go about having a matrix representation in C# and Python.


  • In Python, use the numpy library.







Understanding the SynchronizationContext and Best Practices in Asynchronous Programming.

For doing asynchronous programming in C#, one needs to understand the concept of SynchronizationContext.

I came across this nice set of posts by Stephen Cleary, where he explains some of the fundamental design choices and best practices.

The primary reason for this line of exploration for me was because of a deadlock I hit when working on a web app using the async pattern. This problem is described here.