C# dynamic objects

The best use of dynamic variables in C# I have found in use with deserializing JSON data for which I may not have the schema, or I know is a frequently changing schema.
For everything else I just avoid using it.

What do I use? Well, NewtonSoft’s JSON deserializer and this simple statement:

dynamic apiData = JsonConvert.Deserialize<dynamic>(jsonData);

Simple and neat.
#CSharp #dynamicvariables

Few tips on improving speed of your MongoDB database

Those of you who have done a project with MongoDB will notice that it functions and behaves quite differently than traditional RDBMS systems. From super fast queries to all of a sudden taking forever to return 10 documents is something beginners always face with MongoDB. I am no expert but these are the steps I took and Mongo worked much nicer than it had earlier.

  • Configure “Mongod” to run as a service Many beginners make this mistake and its a very common one. Make sure you run it as a service which allows MongoDB to do better performance management and handle incoming queries a lot better.
  • Indexing This should not even need to be mentioned, but with Mongo don’t do a blind indexing. Think of the fields you group the documents the most in your queries and set the indexes with that in mind. This will do a lot to speed up your MongoDB
  • Start using _id Again this is something people do a lot, i.e. they don’t use the inbuilt _id field. You should using that over your own ids. Since it’s an ObjectID, it indexes better and is truly unique reducing programmer headache of creating unique id fields
  • Create a re-indexer service Like any other database MongoDB needs to be re-indexed occasionally. One of the easiest ways is to create a daemon or service in your favorite language and make it do some maintenance like re-indexing and data cleanups.
  • Implement Paging in your queries This is good to do in most projects. When showing large data sets, try to page your data so that you only show enough to start with, and then fetch more as you go. Mongo has an advantage over other databases in this regard in terms of speed. Please keep in mind the field you page on is a unique index

So these are a few observations I had while designing my project in MongoDB. I will be adding more improvement techniques as I go forward. If you think some of my above points are erroneous do let me know. Also share your tricks with me!

Linux Saga: Fixed the long standing bug of WiFi not connecting after sleep/suspend

Now this was a weird one which I later read on other forums that it was a common problem on most HP laptops. Well finally I got to fix this with a very simple fix!

Added a line in /etc/modprobe.d/iwlwifi.conf
options iwlwifi bt_coex_active=0

Laptop LCD screen brightness in Linux Mint 13 or Ubuntu 12.04

I recently set up a Linux workstation and based on my lookup on best distributions available, two came to fore: Ubuntu 12.04 and Linux Mint 13 (Maya). Ubuntu has always been a fantastic Linux distro, but as I learned Linux Mint is actually based off of Ubuntu and did a better job at being a full featured OS, I decided to get it setup on my desktop. I have been very pleased so far!
One of the issues faced was inability to control brightness of the screen. I could not do say from the keys on the keyboard and neither did system settings work. The fix was easy as I learned about it on other forums. Here is the link to fix the problem:
http://shellboy.com/linux-mint-13-on-dell-xps-15-brightness-keys-not-working.html

Complexity Adaptive User Interface (COMPAD UI)

In a Nutshell

How about a UI that doesn’t present you with all the complex features of the application just at once. Instead, it slowly adapts in that direction based on your usage pattern.

The Need

Applications, as they move up in release versions, start cramming up the UI with features. This is a gradual progression we see in most software applications available today. In a world were simplicity speaks volumes, we might be better off with showing less. Why would I hide features when my application supports it, you would ask. The answer is simple – Users may only need to do certain things with your application, never will they use every single feature from day one (unless they are used to previous versions, of course).

The Solution

Bring about a UI which understands user usage pattern, and then gradually starts enabling/showing features. This would allow the end user to start with a minimalist interface and then as the user gets comfortable with the core functionality, that they can start using more features.

Practical Example

Like all theories, it’s better to put the point across with a practical example.

The best example I have from my own experience is the story of Winamp (from my perspective). Like most fans of music during the late 90s, I too was a Winamp + Napster fan. Winamp had always been my media player of choice ever since I had started listening to MP3s. In spite of my dedicated loyalty towards all the versions up until 2.81, something happened with Winamp 3 that totally threw me off and almost made me regret my decision of upgrading. It had become this bloated piece of software from the original version, that in less than 10 minutes I lost all charm of wanting to use it. My grunt was simple – I had no interest in Music Libraries or tons of those new features that it shoved at me. Plus all of those features made it slower to load. It didn’t take me much time to roll back to Winamp 2.81 which had been my previous version.

One day I got this newsletter bragging about the launch of Winamp 5. Honestly, I was not too excited to give it a try given my past experience with the version 3. What I did notice is that this time it came with a Lite version as well! Instinctively, I downloaded that and fired it up. Expecting to see a worsened avatar of the version 3, what eventually showed up was a surprise – The UI was almost just like 2.81. Wow, what a relief that it does retain the 2.81 simplicity, I was instantly telling my geeky friends! I immediately got to using it and no second thoughts about reverting back to the old version haunted me. What this meant was, I was not the only one complaining about the cramped up Winamp 3 UI and certainly I was sharing a general consensus. In about next few days I unlocked almost all of the features I had seen in Winamp 3 plus a few more. Not necessarily I used all of them, but at least I knew they were there and I will use them when the need (or the urge) arises. An important lesson was learnt that day – make it comfortable for someone to fit in to what is otherwise new.

Learning off of that experience, came a thought to my mind – what if the software understood that when a user was ready to be presented with more stuff that they might want! If that would happen, then even a non-geeky user could be eventually roped in to use some of the more advanced features.

Alright, we are sold, how do we implement Complexity Adaptive UI (COMPAD UI)?

What I plan to suggest in series of successive posts, is a set of  configuration XML markup structures, terms and design patterns to enable successful implementation of this feature in programming language and technology of your choice. I am also in process of setting up a Wiki page so that more of us can collaborate on the idea.

Why Web Installers are great

Are you one of those who is wondering why all of a sudden every software has a Web Installer (a small executable that downloads rest of the stuff) instead of a traditional setup.exe which used to the sole file you needed to install a software? The reason is, a web installer is a smart tool that assess how many components are already installed, and based on that downloads only the stuff that you actually need. This reduces download size from say 500 MB to just 100 MB if you already have most of the dependencies installed.

(I knew this for a while but recently happened to program one such installer and was admiring the beauty of this simple idea)

Fax services on Vista home premium

All the Windows Vista Home Premium users by now must have figured out that they don’t have the basic Windows Fax and Scan services. Too bad Microsoft decided to remove something that basic from an already crappy operating system. The only solution is to look for an alternate and I seem to have found a good alternate – Classic Phone Tools by Avanquest Software

You can get the full version for free if you follow the right links on the page. So far it seems to work great for me! Let me know if anyone of you knows other better Windows Fax software.

Wiki Article Reliability Algorithm/Software

Let me start by saying that I am a supporter of Wikipedia, I contribute articles and information wherever I think I have sufficient knowledge. I also contribute annually a certain amount to Wikipedia donations. Having said that, it does hurt me sometimes when people rubbish you if you quote them something from wikipedia or you give them a wikipedia link in an attempt to prove your point. People who don’t know how wikipedia works or have very little surface knowledge seem to disregard it with much ease. I read somewhere about an article that how teachers in most school discredit any wikipedia sources of research. Yes they dislike it because in many cases it contradicts their text books. In reality, Wikipedia is a mighty flattener of the world by providing free access and authoring capability of information to general public. Let me quote an example, have you heard of the famous saying, “History is written by conquerors”? Not anymore. With rising popularity of Wikipedia, every piece of historical article is being subjected to views from all directions. One such example would be the role of “Aryan Invasion Theory” in Indian history. For more than one century we have heard the Aryan Invasion theory and taken it as practical history, of course until now. Without going into the details, you will notice Wikipedia article on the subject seems to stay neutral by presenting both sides of the argument.

Now coming to the original intention of writing this article, I propose to write first an algorithm and then a practical implementation of the algorithm as a web service/site that other applications can use. Yes, everything will be open source and free. The purpose of the algorithm would be to present the reader with a version of the wikipedia page (or for that matter any wiki page) that the algorithm thinks is the most stable/reliable version. How the algorithm will work is a set of steps that I will be detailing next.

  • Access the History page of the article
  • Fetch a list of all the authors
  • Loop through all edits made by non-registered-users i.e. random edits
  • Check if these edits against article lifecycle, i.e. how far in the stable life of the article was the edit made
  • If the edit was made and no registered user edit was made after it, remove it
  • Mark every other random edit as “Candidate for Removal”
  • Fetch a list of newly registered users who have recently modified the page
  • Check if the author has made edits to other pages, if yes, look at the activity interval. If there are rapid edits, the author could be spammer. If the edit made was very recent, mark it as “Recent Edits” and “Candidate for Removal”.
  • Every content line that has a [citation needed] marking, mark them as “candidate for removal”
  • Find trustworth authors, by finding every author that has been editing on wikipedia for quite a long time
  • Promote their edits to “Trustworthy Info”
  • Find any “Candidates for Removal” in the “Trustworthy Info” and let “Trustworthy Info” suppress Candidate for Removals
  • Based on the stringency of user settings, curate the “Candidates for Removal” in the final rendering of the article

This could just turn out to be the quick moderator you need while browsing the excellent and superb Wikipedia! And this doesnt just apply to wikipedia, it also applies to Technical wikis we use at work. There are many people writing and modifying wiki pages. If its a big organization, I bet there are many new joinees and interns who are not necessarily the most trusted people to edit wikis. However, the best use of it is on public wiki sites where trust worthiness of an article becomes a big question for few.

Moved server

You might have noticed that my blog was down for a few weeks. Yes my last host had crashed. Not wanting to rely on them further, I have shifted my website server over to ByetHost. So far I am enjoying their very generous hosting offer. Nothing better for hosting a wordpress blog.

Zinio – Magazines right on your iPad

Of all my experiences with the iPad, the best have been surfing web, reading books, and magazines. The Zinio app has totally redefined the way I get my favorite magazines! Imagine not having to wait weeks to get your PCWorld magazine delivered to your home. Having all your favorite magazines available with you and readable with almost the same or more convenience as the print media has been a dream so far – at least for me. My laptop can’t go everywhere with me but the iPad surely can. My laptop needs a wall socket after 2 hours of use so its not the best for use on airplanes, trains and airports. Its too bulky to handle as well. All of these are not a problem for the iPad.

With Zinio, I got virtually a news stand on my iPad! I can browse and purchase from a HUGE selection of magazines, not just the ones you would otherwise find on stalls. Even the prices appeared relatively cheaper than print media prices. Tell me what kind of Magazine applications are you using? Would love to know!