Getting File Content using GIT Hub API

The GIT Hub itself has a fairly complete tutorial for accessing GIT hub uploaded files.

However, I think it can still use some little extra explanation.

Make sure you get the following steps right for this:

  • Depending upon master/branch, get your URL for the repository ready first.
  • Next, get the correct header inserted into your HTTP request.
  • Make sure you are requesting data in ‘jsonp’ format
  • Extracting the content of your response can also get tricky. make sure to look into ‘data.contents’ value.
  • Finally, decode the encoded content.

Here’s my implementation API call:

var gitURL = '';
var gitAPIServiceOptions = {
url: gitURL + yourGitHubFilePath,
requestType: "GET",
dataType: "JSONP",
httpHeader: 'Accept',
callBack: function(result) {
if (result.success === true) {
var decodedResult = atob( ;


A Knight’s Watch

Recently I came across this interesting problem through Toptal (on Codility) which kept me thinking hard for a few days. Finally, I now have a solution to this problem and would like to share it here.


Basically, the problem deals with a knight piece on an infinite chess board. Assuming the knight is positioned at (0,0) you are asked to calculate and print the shortest path that the knight can take to get to the target location.


My Approach:

So what is given here?

  1. The Knight’s movement is well defined i.e. it can only move in a ‘L’ shape.
  2. The Knight has option to move to any of the 8 different locations from it’s current position.



Now with these key points in mind, we can calculate which move will take the Knight closest to the given target i.e. move the knight in the direction of shortest distance.

For example: Suppose our target is located at (6,7).


Now, from (0,0) the Knight can move to following points: (1,2), (2,1), (-1,2), (-2,1), (-1,-2), (-2,-1), (1,-2) and (2,-1).

But out of these 8 points, the closest one is (1,2). So we move the knight to this position in first move. For each step we can use the same logic to move the Knight.

Hence, the Knight moves to (1,2) in first step, (3,3) in second, (4,5) in third and (6,6) in fourth move.

However, once the Knight reaches a proximity distance of 1 unit, we will have to keep in mind a separate logic to hit the target.

This is because if we stick to our logic of moving the knight towards the shortest distance in all places, what will happen is once the knight reaches a close proximity, the Knight will start going round and round the target but never actually hit the target.

From (6,6), the Knight could jump to (7,8). From (7,8) it could jump to (5,7) and to (7,5) and all but never actually jump to (6,7).

So, we have to create a separate rule for this scenario for our Knight.

Close Proximity Rule:

There are again 8 different close proximity points from the target location’s view point : (7,7), (7,8), (6,8), (5,8), (5,7), (5,6), (6,6) and (7,6).

These eight points can be categorized into 2 types. Either they lie on the axes or they lie on the diagonals from the given target.

Points on Axes: (7,7), (6,8), (5,7) and (6,6)


Points on Diagonals: (7,8), (5,8), (5,6) and (7,6)


Based on these two types, the Knight can hit the target in either 2 or 3 moves.

If the Knight was at a point on the diagonal say (5,6), from there it can jump (7,5) and then to (6,7) in 2 two moves. All diagonal points can access the target in the center in two steps.

Similarly, all points on the x-y axes can hit the target in 3 steps. For example, if the Knight was at (6,6), it can jump to points (8,7), then to (7,9) and finally t (6,7).

Now with this much knowledge we can create a program that can calculate the shortest path that our Knight has to take to hit any target on an infinite chess board!

My Implementation:

I have created a console application in C# to calculate the shortest path for the Knight to reach any stated target point with the above mentioned logic.

The application/project is available in git hub @

Please feel free to like, share and comment.



7 Handy SQL Scripts for SQL Developers

Finally got my article published at Tuts+

I had written this article “7 Handy SQL Scripts for SQL Developers” referencing some of the common scripts that I most frequently use @ work. Some of these scripts were collected from different sites while some were developed by myself.


“A lot of things that we do depend upon the knowledge that we possess. If we are aware of what can be done, only then we can make smarter and more effective decisions. That is why it is always good to have quick tips and tricks handy in your pocket. This principle applies everywhere, including for MS-SQL developers.
Through this article I would like to share a few SQL scripts which have proven to be very useful for my daily job as a SQL developer. I’ll present a brief scenario about where each of these scripts can be used along with the scripts below. ……………………”

Read full article at:–cms-25834—————————————————