Skip to main content

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.

jqGrid: Handling array data !!!

This post is primarily a personal reference. I also consider this a tribute to Oleg , who was fundamental 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. If you are working with local array data as the source for jqGrid, meaning you will get the data from the server but want the jqGrid not to talk to the server anymore, and want to have custom handling of the edit functionality/form and delete functionality, it is not going to be straightforward - you need to have a decent understanding of how jqGrid works, and you should be aware of the bug Oleg pointed in our discussion. I repeat this is all about using jqGrid to manage array data locally, no posting to server when you edit or delete, which is where the bug is. $('#grid').jqGrid('navGrid', '#pager', { recreateForm: true, add: false, search: false, refresh: false, ...

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." Although it sounds to make sense, I don't completely agree with that. Maybe the topic of the discussion was ambiguous. It wasn't the programmer but the code. I am not willing to spend my energy to demotivate somebody by branding him a bad programmer. But I will in reviewing anybody's code, not just brand it bad code but ultimately clean it up. I believe programming isn't restricted to language. Although the language used to program has its impact on the way a problem is solved, it doesn't limit the programmer from losing the basics. In other words, a...

The Windows Phone Epic !!!

Dear Reader, Do not be overwhelmed at 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. Oscar Wilde said, " If you want to tell people the truth, make them laugh, otherwise they’ll kill you ". 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 programmer  2 , 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 be...

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. Most people who are programmers are just people who write code for a living. Nothing wrong but forget the passion part of it. So the quality of the code that is generated is questionable. True programmers are different. They first build those intangible constructs in mind of how the code should be, and then they write code that reflects to the reader the intent of the task being achieved. Hence such code is readable, modu...

Linked List Quiz - Part II !!!

In the last part , 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. Reverse the list recursively Reverse the list iteratively Find if a list is cyclic 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 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; 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 !...

Offering __FILE__ and __LINE__ for C# !!!

THIS POST USES SYNTAXHIGHLIGHTER AND HAS ISSUES RENDERING CODE ONLY IN CHROME 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. For instance, suppose you wish to write a verbose Log method with an idea to print rich diagnostic details, it would look something like this. void LogException(const std::string& logText, const std::string& fileName...

Linked List Quiz - Part I

A short while back, Azhagu 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. Here are some of the problems that Azhagu asked me to solve:- Reverse the list recursively Reverse the list iteratively Find if the list is cyclic Find the node that causes the cycle (and break the cycle) Reverse every K nodes in the list I will be solving reversing the list (both iteratively and recursively) and finding if the list is cyclic problems in this episode. #pragma once #include <iostream> #include <vector> using namespace std; template<typename T> clas...

Sms FireWall Update !!!

I gave SMS FireWall a refresh with a couple of features requested by users:- An option 'Allow and Move' in the settings screen, which when checked moves the messages from the quarantine vault when opted to be added to the allowed list. Although it might be clear to you, let me explain it in a few words how it works. When you long press a sender in the quarantine vault, a menu with two options appear - Allow, Delete. When 'Allow' is clicked, the sender is added to the allowed list. And when the 'Allow and Move' setting is checked, the messages from this sender are moved to the inbox. A confirmation dialog prompt when attempted to empty the quarantine vault A few minor (internal) improvements Hope they are useful to others too. And let me know if you need any other features to be in the application.

OrderedThreadPool - Bug Fix !!!

Hugh pointed out a bug in the OrderedThreadPool . I think there is a small window for error in the OrderedThreadPool class. Bascially, 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... Here is the fixed version of the same. using System; using System.Collections.Generic; using System.Diagnostics; namespace System.Threading { public class OrderedThreadPool { private Queue workItemQ = new Queue(); private bool loopWorkRunning = false; public void QueueUserWorkItem(WaitCallback wcbDelegate, object state) { lock (workItemQ) { workItemQ.Enqueue(new ThreadPoolTaskInfo(wcbDelegate, state)); if (workItemQ.Count == 1 && !lo...

Unique Id Generation !!!

A short while I was engaged in a little project where I had to interact with a third party service provider who required a (30 length) unique id as part of the transaction. I am little dumb and am used to GUIDs for a long time when it comes to unique ids. But GUIDs are more than 30 in length. I was trying out some stupid ways like stripping out the trail part of the GUID to make 30 length unique but my intuition wasn't convinced about the tricks I was working out. Finally, Sriram helped me with it. I am sharing his code for the benefit of others. string GenerateUniqueId(int length) { string asciiChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; char[] chars = asciiChars.ToCharArray(); byte[] randombytes = new byte[length]; RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider(); crypto.GetNonZeroBytes(randombytes); StringBuilder result = new StringBuilder(length); foreach (byte b in randombytes) { res...

Sms Firewall !!!

Tired of prank SMSes. Need a simple way to block them, and keep your inbox clean? Don't worry. You got it! SMS Firewall is a simple and cute (hope you like it!) Android application to block and quarantine unwanted SMS from reaching your inbox. Unwanted are those who are neither in your contacts list nor in the allowed list, which is provided by the application. Phone numbers or sender names such as your bank or mobile service provider can be added to the allowed list. You got an option to either notify you of the blocked SMS or ignore it, in which case you will have check the quarantine vault by yourself. Besides, you have a 'Just Monitor' mode, which is primarily used for debugging purposes or when you don't want to block SMS from unknown sender(s) (for a while). When this mode is switched on, SMS from unknown senders will reach the inbox and also a copy of it is saved in the quarantine vault. Here are a few screen shots to get you attracted... ...

To Ritche !!!

Dennis Ritchie , whom we all know as the creator of the C programming language passed away on Oct 12, 2011. We have lost one of the brilliant minds of mankind. I owe him this post for he has been one of the greatest inspirations in my life and the very reason that I am into programming. Dennis Ritchie (1941-2011) The first time I saw Ritchie's picture, I felt him like Jesus. I would say that the divinity that his face reflected pulled into the world of programming. It was during my college days that I lay hands on his book - The C Programming Language . It is one of the most influential computer books I have read. I had read it at least a couple of times and referred it a thousand times. I felt it like a lecture by Ritchie. And so I had marked a lot of pages with comments and questions as if they are addressed directly to Ritchie himself.  I had the book with me almost all the time. I even hide myself in the last row during other lectures to read the book. I felt excit...