Posts

Getting reminded of the reminder !!!

I have been using Android for quite some time now, and only recently I noticed that Android pops up a notification reminding you of a reminder. It says “Upcoming alarm – Buy Milk”, where Buy Milk is the reminder I had set.

Is it smart enough to help a lazy volatile minded guy like me or is it trying to be my wife who would not rest until I buy milk? Don’t know.

More ...

jqGrid: Handling array data !!!

This post is primarily a personal reference. I also consider this a tribute to Oleg, who played a big role in improving my understanding of the jqGrid internals – the way it handles source data types, which, if I may say, led him in discovering a bug in jqGrid. More ...

Clean Code

I received quite a lot of criticism for Dealing with Bad Code. The criticism was mostly along these lines – There is no good or bad programmer. The good programmer thing is more of an illusion. When you place a programmer in a domain in which he has little or no experience (like a PHP web programmer writing C++ code), he will soon be seen as a bad programmer. What is branded good or bad is subjective. More ...

The Windows Phone Epic !!!

Dear Reader,

Do not be overwhelmed by the length of the article. I have tried my best to keep the length of the article NOT directly proportional to the time required to read it.

If you want to tell people the truth, make them laugh, otherwise they’ll kill you - Oscar Wilde

There are times when truth tends to be subjective, such as this article. However, I have definitely added the fun component to keep up earlier promise. Consider the time you spent reading this article as a break from your work or routine. I am sure you will enjoy it; doesn’t matter if you are using a Windows Phone 1. Perhaps you will read it again.

I am programmer1 gadget savvy, an avid fan of Microsoft products (especially Visual Studio and associated suite of development tools), and an honest critic of any product I use. I have an Android Phone, an iPhone, and for a few months now, a Windows Phone. And this is my experience with the Windows Phone – good, bad and grey.

To begin with, the Windows Phone landscape (app and feature set) is dry and unpromising. There are a few good things here and there to console ourselves for the money we spent on the phone, and for the love of Microsoft!

More ...

Dealing with Bad Code

Read this fine article by Joel Spolsky: Things You Should Never Do

It is a great article, one that invokes mixed feelings. The article talks against rewriting (large scale) software…..from scratch. Joel was kind enough to consider all those who write software as true programmers; people who give enough thought and not just code up something that works. However, it is far different in the real world. That said, I am neither completely in disagreement with Joel nor am I advocating to rewrite large scale software once the code is identified as a mess.

More ...

Linked List Quiz – Part II !!!

In the previous post, we saw the academic (not general purpose) version of a linked list used to solve the puzzles, and solved the following puzzles on linked list.

In this part, I will be solving the remaining two puzzles that I listed in the last part.

Finding the cyclic node in a cyclic linked list

  1. According to my solution, the node which is actually supposed to be the end of the linked list is the cyclic node. Let us call Cn. Taking node Cn as the cyclic one has an advantage wherein you can break the cycle; assign Cn->next = nullptr;
  2. But some people take the node after Cn as the cyclic node. The node after Cn is the node somewhere back in the list. This way it is not possible to break the cycle as we would traversed past Cn.
LinkedList::Node* LinkedList::FindCyclicNode() const
{
   int iterCount = 0;

   auto jmpBy1Ptr = root;
   auto jmpBy2Ptr = root;

   while (jmpBy1Ptr != nullptr && jmpBy2Ptr != nullptr && jmpBy2Ptr->Next() != nullptr)
   {
      jmpBy1Ptr = jmpBy1Ptr->Next();
      jmpBy2Ptr = jmpBy2Ptr->Next()->Next();

      if (jmpBy1Ptr == jmpBy2Ptr)
      {
         const int noOfNodesInLoop = CountNoOfNodesInLoop(jmpBy1Ptr);

         cout << "No of nodes in loop: " << noOfNodesInLoop << std::endl;

         auto p1= root;
         auto p2 = GetNthNode(noOfNodesInLoop - 1); // zero based index

         cout << "Node at index " << noOfNodesInLoop << ": " << p2->Item() << std::endl;

         // Pointers meet at eye of the loop (this node is as per point #2 above)

         while (p1 != p2)
         {
            p1 = p1->Next();
            p2 = p2->Next();
         }

         // This piece of code takes you to the loop starting node (this node is as per #1 above)
         p2 = p2->Next();

         while(p2->Next() != p1)
         {
            p2 = p2->Next();
         }

         return p2;
      }

      ++iterCount;
   }

   return nullptr;
}

int LinkedList::CountNoOfNodesInLoop(Node* stopNode) const
{
   int count = 1;
   auto p1 = stopNode;
   auto p2 = stopNode;

   while (p1->Next() != p2)
   {
      p1 = p1->Next();
      ++count;
   }

   return count;
}

The code above is the result of several iterations of discussions with Azhagu. It wasn’t written that way the first time. The first version was much complex and naive. I think it looks better now. What do you say?

More ...

Offering __FILE__ and __LINE__ for C# !!!

Not the same way but we could say better.

Visual Studio 2012, another power packed release of Visual Studio, among a lot of other powerful fancy language features, offers the ability to deduce the method caller details at compile time.

C++ offered the compiler defined macros FILE and LINE (and DATE and TIME), which are primarily intended for diagnostic purposes in a program, whereby the caller information is captured and logged. For instance, using LINE would be replaced with the exact line number in the file where this macro has been used. That sometimes beats the purpose and doesn’t gives us what we actually expect. Let’s see.

More ...

Linked List Quiz – Part I !!!

A short while back, Sammy quizzed me on linked list based problems; singly linked list.

I am recording those problems, solutions and my experience as a two part series. In the first part, I am introducing the linked list class, which I wrote for packaging the implementation of the solutions. This class pertains to the context of the problem(s) and cannot be used as a general purpose linked list. A std::list might more pertinent in the context of the general purpose implementation of a list.

More ...

Sms FireWall Update

I gave SMS FireWall a refresh with a couple of features requested by users:-

Hope they are useful to others too. And let me know if you need any other features to be in the application.

More ...

OrderedThreadPool – Bug Fix !!!

Hugh pointed out a bug in the OrderedThreadPool.

I think there is a small window for error in the OrderedThreadPool class. Basically, if an item of work is queued, then a worker thread runs, takes the item off the queue and is about to call wcb(state) – but at that instant is (say) context switched. Then another item gets queued and another worker thread runs and dequeues the item and then again is about to call wcb(state). There is scope here for the two operations to run concurrently or even out of order…

More ...