Monday, December 8, 2014

Couple of quick 'diff' examples

For files list only:

diff -qr Source1 Source2  > ~/diff_files

Actual contents diff; Can be opened with Kompare:

diff -Naur Source1 Source2 > ~/diff_contents

Sunday, December 7, 2014

Adventures in Threading

So after stumbling for a while I managed to crack Qt's moveToThread(). Source at above link. Its has working code for big file copy in thread.
We have only left one small problem, and that is if the function we are calling on thread start has any arguments to pass, then we won't be able to directly connect it to thread's started() signal.
So in this case we should subclass thread and pass the arguments to the custom thread object and then inside it emit an appropriate signal to call the main class's function. It seems like such a complex way to do such a simple task like "run this function on a separate thread!" :D

Wednesday, November 12, 2014

Xiaomi Redmi 1S

So I was itching to get a new cell phone. My three year old Samsung was just not cutting it. And the temporary zte was too slow. So I needed a powerful and at the same time cheap phone.
So after considering a no of smart phones I finally decided that what I'm trying to achieve is difficult and only a Chinese vendor can get me such a handset. Going for Micromax/Karbon/Xolo etc Indian vendors was out of the question because of service woes and poor hardware quality. E.g. I remember the Karbon S1 phone I bought for my sister. Back in 2013 it cost me INR 7.5k. Came with JellyBean and 1GB ram. But the phone had slightly faulty touchscreen. But I didn't want to face Karbonns poor service so I showed my sister how to work around to that. Thankfully the phone has not died and its been a year.
Anyway, finally I decided to take a chance with Xiaomi. The price was right and the hardware quality of xiaomi's handsets has been great. So I registered for the flipkart sale and dutifully bought the phone on the sale day.
Unpacking: The handset comes in a normal looking box made of recycled paper. Its nice little box and holds the handset, battery and a 2A power adapter and a microusb cable. The handset looks neat. It feels heavy but then you are looking at 4.7 inches of screen estate and a 2000 mAh battery plus dragon trail glass protection. The charger and USB cable are good quality. The handset looks like premium quality handset and is solidly put. There are no squeaks or loose spots anywhere. The battery fits snugly and the power/volume rocker keys are well put together. In fact I feel like they are better than my three year old omnia w's keys. The front is clean with those special red capacitive buttons. The HD screen is sharp and bright. You get about 6GB of available storage out of 8GB provided. The handset has clean lines and the design is practical yet appealing. There is a notification LED right below home key which glows with various colours depending on the action going on. The front camera of 1.6MP is in top left corner and the earpiece is cantered and latched to top edge. The grill looks great. On side as I said earlier we have power/lock key and the volume rockers. At bottom there is a micro USB port. On top right we have 3.5mm volume jack. At back we have 8MP secondary camera with LED flash. The flash looks okay as far as I have checked it. The light spread is tight though so you need to practise taking pictures in dark otherwise you may miss things at edge of photo to darkness. There is a speaker grill to right of the camera at back.
MIUI: The handset came with v36 of MiUI and there was already an update available which took it to v45. I went ahead and got the update. Its supposed to fix RAM issues and heating issues. Though I am not as heavy user of a phone, so I don't think I'll even encounter these issues. ( I game on PC and use the phone mostly for calls, chatting on WhatsApp, mails, music and internet.) So after downloading the 511MB zip, I updated the phone. After rebooting I configured my gmail account. Then installed all the apps. Updated the internal apps too. Then spent some time spring cleaning stuff that I don't need anymore. After that I used the handset for last one week as my primary handset with two SIMS. I used an old 512MB SD card as temporary storage. The first thing that you notice about MiUI is that its very smooth and responsive. Apps open quickly and the general feeling is of smooth UI. The MiUI colors are pleasant, wallpaper and theme customisations are good. Plus xiaomi has baked in extra settings as well as toggles that help with stuff. Overall I felt like I could keep MiUI going and won't need to tinker with the phone to make it better in any way than what it already is.
Everyday Usage: My everyday usage is simple. I make a few calls. WhatsApp is on throughout the day. In fact WhatsApp and the browser followed by gmail are the three most used things on my phone. I expect the phone to last more than 24hrs with this use. Preferably 36hours at least. There I found the Redmi 1S to be slightly lacking. I could not get more than 24 hrs on one full charge with moderate use. So I went about and tuned it a bit to handle minimum WiFi by turning it off while sleeping and turning off automatic sync as well as auto updates. These have helped and now I am getting about 30hrs of runtime. That's good enough for me. But there are reports of people getting way more. So I'll need to investigate this further. Going ahead, the camera is snappy and worth a praise. The photos are crisp, and the flash more than adequate although with a tight spread that I mentioned earlier. The front camera is more than enough. The touch response is very good and screen provides very good colours. MiUI provides calibration settings so you can adjust the color temperature and saturation. The UI has been stable with almost no occurrences of apps crashing etc. The multi-color notification LED works fine and is helpful. The camera UI is intuitive and the overall feeling is of a smooth snappy phone.
Conclusion: for INR 6000/- there is no other vendor that is giving such hardware and such phone experience. And for me coming off a Samsung Omnia W, the Xiaomi Redmi 1S truly feels like an upgrade. The screen is not OLED, but is even better. The phone is snappy and a pleasure to use, just like the Omnia has been. For couple of months in between I have been tinkering with a Zte Blade C that I got for a cheap INR 4000/-. But for such an entry level phone it had its fair share of problems and limitations. The internal partition structure, the older android version and absence of updates from Zte. ( not total absence, because there was an update but I couldn't download it off their site 'cause of broken download link). So I had to root it and put a custom ROM on that. And after that use a shady app to change partition structure to make System partition as 2GB. Only after all this it became marginally useful. Its a good phone but it was a middling smartphone. Now its an average smartphone. So comparing all this to Redmi 1S, I know I have gotten a great deal with Redmi 1S. And my smartphone search is over.

Saturday, October 18, 2014

AMD Radeon official driver experience

For the Radeon 8330 GPU inside Lenovo g405 powered by AMD A4-5000 APU, I tried out the official driver on Ubuntu 14.04.
The situation is somewhat obscure. The official driver listed on AMD support page doesn't support Ubuntu 14.04. So I had to drop it.
There is one beta driver that supports Ubuntu 14.04 though. So I downloaded it and thought to try it. Took me some efforts to install it though, it just would not install in GUI Mode, problem shown as missing language packs.
Anyway I went ahead with text mode install. After rebooting though, no desktop. Only background with mouse cursor.
So I reverted to open source driver. Later I had another idea, so I went ahead and tried out the official driver available in jocky (proprietary drivers) tool. And after installing that one, I did get a desktop, but the brightness handles were gone.
After searching for a while and not finding anything anywhere, I again reverted to open source driver.
Thankfully that one works okay with my brightness handling script which ensures proper brightness value from Lenovo backlight class is passed to radeon-bl0 backlight class.

Saturday, October 11, 2014

Script for maintaining brightness on Lenovo G405

I observed that the this AMD A4 powered laptop has two backlight classes names idepad and radeon-bl0. Pressing the brightness keys changes brightness values in idepad class while values in radeon-bl0 needs to be changed.
So I wrote a script which will keep the two files in sync and help me get the brightness working.

# Script to sync brightness from sys/classes/idepad to /sys/classes/radeon-bl0
# Task: run in a loop executed every second,  modify radeon  brightness acccording to ideapad brightness
# ideapad brightness from 1 to 16 in steps of 1;
# Radeon brightness 1 to 255 in steps of 1;
while [ 1 -eq 1 ]
IBRIGHTNESS=`cat /sys/class/backlight/ideapad/brightness`
if [ $IBRIGHTNESS -le 1 ]
echo "Ideapad Brightness: $IBRIGHTNESS"
echo "Radeon Brightness to be set: $RBRIGHTNESS"
echo $RBRIGHTNESS>/sys/class/backlight/radeon_bl0/brightness
sleep 1

Tuesday, October 7, 2014

Enum to String and vice versa - Enum.Parse alternative for C++

Original Article Link:

Update: Link to Source.


While adding Serialization support to my project, I realized that I would require some way to convert a string to an enumerator and vice versa. So I did a Google search for the same, and found a lot of information; different ways in which people implemented this functionality.
However, all the solutions I found suffered from one or more of the following:
  • No support for enumerators with non-contiguous values
  • No support (not even partial support) for enumerators with duplicate values
  • No support for existing enumerations (without modifying their source code)
  • Requires one or more extra files per enumeration
  • Requires source-code to be pre-processed (by a custom binary) before compilation
  • Difficult to use or maintain
  • Highly susceptible to typos
  • Is platform/compiler specific (not portable)
So (the rip-off that I am), I borrowed the good ideas from all the solutions I found, added a few of my own and mixed-and-matched to create the code which accompanies this article. I don't claim this to be the best solution for every case, just that it solved my problem nicely and that it could be of use to someone else as well.

How To Use the Code

Using the code is quite easy. All we need to do is add one file: EnumString.h (see the source code accompanying this article) to our project.
Let's say we wanted to create an enum to represent one of the Furious Five Masters (Kung Fu Panda (2008) anyone?). So we go ahead and declare it as usual:
Collapse | Copy Code
// Furious Five Master  enum Master  {      Tigress = 5,      Viper = 3,      Monkey = 4,      Mantis = 1,      Crane = 2  };
Don't worry about the values assigned, they are simply my rough idea of what the 'mass' of each master is, in some imaginary units. Now to add stringizing support, we need to declare the enum again, but in a different format (uses helper macros):
Collapse | Copy Code
// String support for Furious Five Master  Begin_Enum_String( Master )  {      Enum_String( Tigress );      Enum_String( Viper );      Enum_String( Monkey );      Enum_String( Mantis );      Enum_String( Crane );  }  End_Enum_String;
And we're done! Note that since this second declaration lies in the same header/source file as the actual enum definition (probably declared just below it), it's not that difficult to update it whenever we modify the actual enumeration.
Now we can convert from a string to a Master enumerator and vice versa, quite easily. The following code shows how to do that:
Collapse | Copy Code
// Convert from a Master enumerator to a string  const std::string &masterStr = EnumString<Master>::From( Monkey );  assert( "Monkey" ) == 0 );    // Convert from a string to a Master enumerator  Master master = Tigress;  const bool bResult = EnumString<Master>::To( master, masterStr );  assert( bResult == true );  assert( master == Monkey );

Using the Code with Existing Enumerations

Suppose we want to add stringizing support to an existing enumeration from a library, which is namespaced. Imagine that the enum is declared like this in the library:
Collapse | Copy Code
namespace SomeLibrary  {      enum WeekEnd      {          Sunday = 1,          Saturday = 7      };  }
Say that we can't modify the library files (which is anyway not a good practice). So we create a separate header file in our project, in which we will declare stringizing support for the required library enum. For the declaration, we have 3 options:

Option 1 - Fully Qualify All the Names

Collapse | Copy Code
Begin_Enum_String( SomeLibrary::WeekEnd )  {      Enum_String( SomeLibrary::Sunday );      Enum_String( SomeLibrary::Saturday );  }  End_Enum_String;
The consequence of this is that the stringized enums will also be fully qualified names. So, the statement EnumString<WeekEnd>::From( SomeLibrary::Saturday ) will yield "SomeLibrary::Saturday", and not just "Saturday".

Option 2 - Use the 'using namespace' Directive

Collapse | Copy Code
using namespace SomeLibrary;    Begin_Enum_String( WeekEnd )  {      Enum_String( Sunday );      Enum_String( Saturday );  }  End_Enum_String;

Option 3 - Register the Enumerators Yourself

Without using the 'Enum_String' helper macro (see the next section 'How does it actually work?', for an explanation of this):
Collapse | Copy Code
Begin_Enum_String( SomeLibrary::WeekEnd )  {      RegisterEnumerator( SomeLibrary::Sunday, "Sunday" );      RegisterEnumerator( SomeLibrary::Saturday, "Saturday" );  }  End_Enum_String;

How Does It Actually Work?

It's not required to know how it works in order to use it, so those who are not really interested can skip this section. Also, beginners might have to brush up on their C++ before reading this.
If you look at the declarations of the helper macros, you'll see that the definition of the string support for FuriousFiveMaster, works out to the following:
Collapse | Copy Code
template <> struct EnumString<Master> :      public EnumStringBase< EnumString<Master>, Master >  {      static void RegisterEnumerators()      {          RegisterEnumerator( Tigress, "Tigress" );          RegisterEnumerator( Viper,   "Viper" );          RegisterEnumerator( Monkey,  "Monkey" );          RegisterEnumerator( Mantis,  "Mantis" );          RegisterEnumerator( Crane,   "Crane" );      }  }
You might have already realized that the above is a specialization of the EnumString template class. It defines the RegisterEnumerators function which is used by its base class EnumStringBase, via CRTP. Now the workings of the usage become clear. When you use the functions EnumString<Master>::From or EnumString<Master>::To, you're using the version of the EnumString template class which is specialized with the Master enumeration.


As with most things, the code does have some drawbacks. The two most important ones are:
  • Doesn't support conversion of enumerators with duplicate values to strings (although vice versa works just fine). An attempt to convert such an enumerator will yield an empty string (which can be tested for).
  • Conversion performance might be a bottleneck for some applications. A single std::map is used internally for storing the relationship of enumerators to their string representations. So lookups during conversions are not in constant time. A conversion from an enumerator to a string will be in linear time, although a vice versa conversion should be very fast.


Since the code makes extensive use of templates, it may not work with older compilers. The code has been tested with the following compilers:
  • Microsoft Visual C++ 2005/2008 
  • GCC 4.4.0 
There is much potential for improvement of the code. But since the current code is good enough for my needs, I'll leave that for someone else to do. If you make changes to the code, improve it, or simply have an entirely different and better way to solve this, please share it with me also; I might just dump my code and use yours instead! Smile | :)


  5. C___enums_to_strings.aspx

Friday, October 3, 2014

The death of my Laptop

Sometimes things are going as usual and all of a sudden something fails. And as it happens usually the failure is unanticipated. And then starts thee scrambling phase where you start looking for alternatives. And ways to overcome this loss. And maybe if you are like me, you start to analyse the failure and try to understand where you failed.
So to start with, my laptop died last week. It was working fine and as it happens with all electronics, it just stopped. It wouldn't start. So I sent it to a nearby repair guy, who told me that the power circuit is dead. He will try replacing the burnt IC's.
Few days later I rang him up for updates and he said that the main board is dead. The replacement IC's also burned up. And so my laptop was gone to death, since I don't think there's any way to get a replacement board since the system was four year old.
Anyway, coming back to the analysis, I assumed that the system will continue to work. So I never made any plans for failure. Also I assumed the HDD would probably fail. So I had backup of all important data. But I didn't assume that I'll be without a system - ever. Which meant whatever projects I have running parallel to my job, they all are stuck for a fortnight. Thankfully I haven't taken any external work recently which meant I wasn't needed to really scramble.
So now I don't have a computer. I'm making do with my backup android phone. But its limited. And my projects which included learning a new technology and some not-so-critical development have stalled. And worst I don't have a budget allocated for a new computer. So I'm totally caught in a limbo here.
Well, let's see. I'm going to see if I can leave things as they are - means continuing with the android phone as a drop-in replacement and carry on. That sucks a bit. But you got choices and then payments, as they say!!!

Sunday, September 28, 2014

Current ROM on Zte Blade C

Its names Rigor Stock. Its not as fast as SlimDroid ROM. But it works out well. I recently recalibrated the battery too. And have found it to be charging and discharging well.
The app I used for battery calibration is BatteryCalibration available from Play store.

Wednesday, August 20, 2014

MIUI v5.2 ROM for ZTE Blade C (v807C)

The MIUI ROM is heavy. I noticed severe slowing down in places. I did not use it for more than a few days though. So it could be that cleaning up the system a bit, might have helped.
The MIUI looks great, is pleasure to use with great looks, features and a similarity everywhere. But its far too removed from the android experience.
Sadly not my cup of tea right now!
Link on needrom:

Slim Droid ROM on ZTE Blade C (v807c)

This ROM is fastest of the few I tried out. Its really slimmed down, is fast and pleasant to use.

The two main problem I noticed were lack of 3G and broken battery charge monitor. The lack of 3G was not much hindrance for me, but the broken battery monitor meant I could not use this ROM.
Link to ROM on

Flashing TWRP recovery on zte blade c (v807)

Edit: Links to software added
VRoot (ENG)(6.9MB)
TWRP Recovery (IMG)(5.8MB)
Scatter file for ZTE Blade C (V807C) (382B)
SP Flash Tool 3.1304.0.119 (6.7MB)

MTK Droid Tools 2.5.3 (11.9MB)
ZTE Blade C Root and Recovery Folder (34.2MB)
ZTE Blade C TWRP Recovery Flashing Video (Russian) (41.9MB) 
My readme file with experience using the above russian video
STOCK Rom ZTE Blade C (V807C) - Flashable by SP Flash Tool (280.1MB)

Wanted to flash TWRP recovery on my ZTE Blade C (v807c). After looking here n there, I stumbled onto a video by a Russian guy who showed how to do it. I got the idea of it all. And so I proceeded.
Following the video, I got familiar with the process which is as follows:

1. Get the device rooted: using vroot the zte v807c was easily rooted.
2. Then install twrp recovery:
In the video the operator performs following steps:
a. Install the zte usb drivers from ZTE v807\Drivers for ZTE.
b. Install the mtk drivers from ZTE v807\Drivers for SP Flash Tool\USB_serial driver.
c. Next start SP Flash tool.
d. Load scatter file from ZTE v807\Recovery.
e. Select recovery image TWRP.img from v807.
f. Disconnect the phone and switch it off.
g.Click Download button and reconnect the phone to computer USB in switched off state. SP Flash tool should detect MTK Preloader and flash the selected recovery. After that SP Flash tool should display success.

For me, step f was failing with SP Flash tool giving error 8038. This meant that the scatter file we have must not be for my v807c (my phone being for India market). So I looked around on the net for info on how to create a scatter file from own phone.

A few places suggested MTK Droid Tools. So I went ahead and used MTK Droid Tools to create a scatter file.
After it was successfully created, I loaded it in SP Flash tool and followed point f again. And this time it was successfully done.

g. After this I unplugged phone from computer and as shown in video, removed the battery and reinserted it. Later starting the phone with power+Vol Up button shows TWRP logo. So its confirmed that TWRP is successfully installed.

Thursday, August 7, 2014

A tryst with message queues Pt. 4

So far... I have installed RabbitMQ server on my development machine and using it to test my development code. I have STOMP_SEND working fine. Using the management web console for RabbitMQ I can see the messages being queued. Now I have to read the sent messages. And here I stumbled into a situation where libstomp's stomp_read function was failing.
So now going ahead, I integrated the message sending code into the product. The requirement was simple. We had to send a fixed message to a queue with time stamp every two mins. So I put together a thread and put the message sending logic into it.
After testing it, I started work on the read part. The requirement was simple. The product has to read some messages from a queue and display them to user.
Thankfully one of the system guys fixed libstomp ( saving me some efforts :D ), and made the stomp_read working again.
So after putting together a test application to read from the queue, I ended up with a no of problems. First of them was garbage data read into the frame. Second was even more interesting. Even if I had multiple messages queued in, I would receive only one message and rest will be lost. Next there was also a problem with the ack mode.
So I shifted gears into study mode and started going through the protocol specification. There I learned about a few things and so I made following changes. Set body.length field to message length and using it restricted the amount of string read. That fixed the garbage message problem. Next I set prefetch-count to 1 and tried the test application. There was still the problem of unacknowledged messages. To fix this I got hold of message-id header and using it, sent ack frame. That fixed the unacknowledged messages problem.

So I guess that fixed everything. Later I put all this onto test platform for about 12 hrs and thankfully things worked out well and it all didn't tank.
So I guess we are finally good with STOMP.

Monday, July 28, 2014

A tryst with Message Queues Pt. 3

So once I have called it quits on the R&D, I started work on the integration thing. The problem has grown tenfold by now. The powers that be want to do a lot of messaging stuff and its become a list of at least half a dozen changes where messages are to be introduced. Now, there's another angle. I am serving notice period, the recruitment people are having hard time finding a replacement and its my last three weeks here. I should be doing the handover. Shouldn't be working on these new features - especially things as complex and less understood as this STOMP stuff. But what can you do when the powers that be want to push in code without worrying about the future of that code.
So I sat silently on this wet and cold Monday morning, trying to figure out the integration strategy. Yeah, the code is all C code, so better to keep it all together. Means a single function which connects to server, sends the message and disconnects. What can I pass? We need to fetch in settings from a config file. Alright I'll use the common config. And what parameters to this function? Maybe just the message will do? No, I need to pass the queue name too. Since there are going to be multiple queues.
OK. Plus I need to extern "C" all includes. Lets hope it doesn't screw up the already included stuff.
So I dive in the code. Add the libraries. Modify the build script to build these too.
Then I add support for the new config fields in the common config file. From there I add some more code to read the new configs.
From there I pull together the message sending code from other application which I have been using for R&D, put it all in function. Then I add some #ifdef's around all this code and add the linking and includes to the pro file.
So after messing with this for some time I finally have some messed up code ready to be compiled. Its going to be a nightmare to get this sauce working. But thankfully I have been many such nightmares already. Will be back soon with next part if I manage to get this spaghetti working.

Friday, July 25, 2014

A tryst with Message Queues Pt. 2

So far...
I'm sending data to a RabbitMQ broker as messages. These messages get queued up in a user configurable queue. Supposedly a consumer is going to process these. But the consumer is out of my view.
Doesn't matter.
Now there came a feature of receiving notifications from the consumer or some other system. So after some discussion, the powers to be decided that we are going to have a notification queue which the client has to read. And from it we get the notifications to be read. Now the shady part of business was I had no idea what the hell is going on the inside of libStomp. So I ask politely that I don't have any read code. And I get handed over a single stomp_read code snippet. (In whiny voice) They said it works!!! But it doesn't!!! I tried so hard!!! Damn!!!
So I looked into the protocol to understand why the hell I am no getting anything. After reading the protocol, I came to know that the implementation is fucked up in ways more than a few. First STOMP is a message send and receive protocol. Which means when we prepare a CONNECT frame, we are supposed to get a reply as CONNECTED along with server connection settings.
Now the original code sample which I was using for sending the data had all stomp_read calls commented out. And after I tried to run that sample with the read calls uncommented. And there I also ran into the same problem. That meant there could be either a server problem or a client problem.
I didn't have any other verified STOMP server, So I decided to check if RabbitMQ is the culprit. Thankfully at the stomp_ plugin page on RabbitMQ website, they have clearly given this procedure. After trying out the telnet routine I ran into an interesting problem.
At first CONNECT, I got invalid error command. Next any CONNECT worked out. After scratching my head for a while I remembered that putty does active negotiation for telnet connection. So I went into putty settings and tried out passive negotiation. That worked. And it also meant that RabbitMQ server is operating fine.
So the culprit must be libStomp. But even after extended search on the net I didn't get any occurrence of my problem.
Later after going through all the protocol stuff I tried out SUBSCRIBE command and even though RabbitMQ logs suggested that the operation has succeed, there was no response read.
That's the current state of things. I have given up on reading up stuff and instead I am going to integrate the working bits into our product. Later I'll see if the reading is working. Else I am thinking of writing my own STOMP message since its all text anyway.
Let's see!!!

Thursday, July 24, 2014

A tryst with Message Queues Pt. 1

I need to give some background for this situation.
Its like this: we have a client server product. The server is written in .net and performs analysis on raw data collected from a number of clients and prepares various reports. The client software is written in c++/Qt and it interacts with various hardware controllers/ sensors to get the raw data.
There is a sync program written in .net that runs on the server and it pulls data from all the clients. The data is saved in servers PostgreSQL database for later processing.
Now, the powers to be decided that we need to remove this syncing program ( because it sunk the data into oblivion sometimes! :D ). So what's the replacement? Well, they decided on RabbitMQ as the queuing solution and decided that the clients would sync their own data to the queue and from there it will be fetched by the server.
So we as clients needed to have this functionality in our application. But after looking at the complexity of our own client, we decided to create a simple up sync application which will be completely separate from our client. Its sole responsibility will be to ensure that all data in the database is sent to the message Queue.
The powers that be decided to use RabbitMQ as messageQueuing server platform. Let me tell you, this is one software whose configuration is a headache. The horrible syntax required for the config file gets to you.
But I somehow survived to tell the tale. Anyway, since my domain knowledge about this was absolutely zero, I spent some time reason up the stuff and getting familiar wight the trade lingo.
Then I used the .net client to check out my clueless config and needed few more days to get it to my taste. After that I went on to compile libApr, and libStomp, and then use it all in my own application.
This would have turned out nightmarish but thankfully I got hold of the compilation commands on internet. Then I spent next couple of days writing the database interfacing stuff. Once I furnished that, I went on to integrate libStomp code.
That took few more days and finally I was sending some stuff to RabbitMQ. I didn't know how to check if correct data is going in. Looking around I found info about management plugin. So enabling it let me confirm the data. Some bugfixes later I was pushing thousands of rows successfully.
Mind you though I still didn't know exactly what the hell was happening inside LibStomp. I came to know that.
In next part.

Monday, July 21, 2014

Custom ROMs for ZTE Blade C (v807/889) and caution for flashers

www.needrom.comhas a collection of ROMs for this phone.
The things to remember are:
1. Always backup the existing stuff!
2. Ensure that phone battery is more than 70% and the computer laptop you are trying out the procedure from has sufficient backup power.
3. Ensure that whatever ROM files you get from the net are from reputed sources and are tested previously by multiple person. Flashing incompatible ROM will brick your phone. So big word of caution here.
4. Also don't forget to check MD5SUM/SHASUM of the file to ensure that your downloaded file is fine and not corrupted.

Flashing a custom ROM is dangerous if you are not careful!

Thursday, July 17, 2014

Rooting zte blade c

Zte Blade c (v807/v889) can be rooted by using vroot application. This is a windows program, so you need a windows PC for this.
You can follow this process:
Enable USB debugging mode on phone and connect to PC.
You need to install USB drivers. You can get these from the phone itself. When you connect the phone to PC, you get an option in notifications about connection type. Here if you select CD-Rom, then a mounted CD-Rom appears in your computer which contains the drivers.
Otherwise you have to search on the internet to get the debug drivers. Once the drivers are installed, you will see a MT6513 device in system tray.
Now start vroot, and wait for it to detect the phone. Once phone is detected, clicking on 'root' button will start the rooting procedure. After files are copied to the phone, it will restart the phone and rooting will continue.
Afterwards phone will restart again and load android. You will see a Superuser app in app drawer. If you open root checker, you will get a prompt about root permissions. Once you have given the permissions, root checker will start and show that the phone is rooted.

Saturday, July 12, 2014

Upgraded a Lenovo A1000-T tablet

This tablet belonged to one of my relatives and I took it with me for updating the apps on my home WiFi. Once it was connected, I started updating the apps one by one. Then in between the updates, a notification popped. This was about a system update availability. I was frankly intrigued. Seeing an android update. So i stopped app updating and instead went for the update. It was ~92MB and took some time to download. Then another dialog popped up asking me if i wanted to update now or after some time like 30mins, 90mins. I selected to update now. The tablet rebooted and updated. After it was done, it rebooted. Once we were connected to WiFi, another update popped up. This one saying it was memory related and it will wipe out all user data. So I went through and checked the partitioning. So it had a 512 MB system partition and 2GB internal partition. Ok. So I went through that update.
Now after some time in getting the user account set up, I'm running through so many apps install, but it has raised the system partition size to 1.4GB and shrunk the internal partition to 1.4GB. I guess that means those pesky 'out of storage' errors will vanish now.
Kudos to Lenovo!!!!

Thoughts on ZTE Blade C after a fortnight

So I am using the ZTE Blade C as my daily driver now. It's almost a fortnight since I started using it. The main point for me to go for this one instead the latest crop of cheap chinese kitkat phones from Micromax/Karbonn/Xolo etc or Moto E was the price it was offered. The price was INR4000 i.e. ~$68. Thats dirt cheap. And whatever features it provided are more than enough for me.
When compared to my previous android phone - Karbonn S1 Titanium - INR7600 /~$127, the blade c actually shines. The Karbonn handset had following shortcomings:
1. It's touch response was sub par. The capacitive keys were terrible. Plus it's touchscreen used to go crazy when it was charging. Also there was a bad touch spot which made typing slightly painful.
2. The 5MP/720p camera was average, even though it was touted as a main feature.
3. It's chipset is Qualcomm S4 play - not the best when it comes to power consumption. And it's couple generations old by the time I got the phone.
4. The display is bright and colourful but its viewing angles are not much. So watching videos on the 4.5" screen is not even an average experience.
On the plus side, it has 1GB of RAM and that was it's only saving grace.

Coming to the ZTE, I noticed following points:
1. The display is kind of dim. So sunlight legibility is low. But indoors it works fine.
2. The touch response is superb. I don't mind holding home button to get recent app list here. And the vibration is perfectly synced with the OS response.
3. 512MB RAM hurts the phone. it's just not enough. You start some game or demanding app and have mp3's playing in background, expect to have the music player killed automatically. Also when you quit the game, then the homescreen will take 3-4 seconds to load. Thats because of less amount of RAM.
4. The interface is smooth. There is no unnecessary lag anywhere except where intense memory operations are happening like App loading/ resume etc. The various effects and transitions are smooth and the interface feels very responsive. This could be due to better touch response too.
5. Battery life is good. The phone lasts about 12Hrs. My typical use includes about half an hour of calls, couple of hours of web browsing (mostly while I am in transit), coulpe of hours of Whats app, and an hour of gaming (It's candy crush saga these days :D)

I guess looking at all these points, I got a good deal. Happy customer ZTE. 

Friday, July 4, 2014

[Android] Finally shifting to Android from WP7.8

I have been a WP user for last two and half years. The samsung omnia was my first smartphone and it has been wonderful hardware so far. Even after so many years of rough use the phone still feels solid in hands. And the software has been great too.
But all software ages. And so has the old WP7. Mind you, its still has the performance. The UI smoothness is there, the OS is responsive as ever. The hardware is solid, the phone has not rebooted of its own accord. And whatever features it provides it excels at them. For me though the first blow was losing gmail support after upgrading to WP7.8. And recently Whatsapp outage was something else I could say was most significant for me to start considering something else. But the problem was I had sunk almost INR16,000 in this one back then. Thats about $320 back then.
And right now I am weary of sinking so much hard earned dough into a smartphone. But thankfully the smartphone prices have also come down dramatically. I was looking for a killer deal and I knew what my requirements are. So when I came across this ZTE Blade C - going for just INR4000, thats about $67, I jumped on to the opportunity. The phone is one full generation old and is very entry level with a 1GHz cortex-a9 dual core processor and 512MB Ram. So when Antutu produced a score of 8000+ that was a startling thing for me. Because I had a Karbonn Titanium S1 which had a 1.2 GHz Qualcomm S4 play quad core chipset and 1GB Ram. But it managed to score only about 10000 points.
Anyway lets get back to the point of shifting to Android. I had to make following preparations for the actual shift.
1. Contacts: Create hotmail contacts export as csv and import them in gmail.
2. Apps: List down the required apps and hunt their equivalents in Android. Thankfully I dont use the phone for anything else than calls, email, little bit of web surfing, and slight gaming. Oh and the Whatsapp. I got hold of most of the stuff right away. Some like skype I had to drop, because Blade C doesnt have front cam. No problem. I am not a heavy skype user.
3. Performance: The phone has been zippy and has been able to handle almost everything I could throw at it. The battery performance is not consistent though. It drops once in a while very fast. And then it will sit quiet. Must be some issue with battery calibration. I dont mind as long as I get decent battery backup. If the phone can make 8 hrs without dying, thats good enough for me.
So lets see how things go. Ill be posting stuff about the ZTE here as things happen around.

Friday, June 13, 2014

[Apache] Setting up virtual hosts on Apache for Linux

Doing this by following official documentation is more confusing. 
I looked up many places and tried many combinations and finally foll. worked for me. 

Task: Keep your current apache localhost server alive and add a new site1.local server that has DocumentRoot at /home/vaibhav/mysite

1. Edit /etc/apache2/httpd.conf and add foll lines: 


   DocumentRoot "/var/www"
   ServerName localhost

   DocumentRoot "/home/vaibhav/mysite"
   ServerName site1.local

2. Next edit /etc/hosts file and add foll line:    site1.local

3. Now restart apache server as : 
sudo /etc/init.d/apache2 restart

4. Check out your virtual site as : 

[Qt] Random background color palette


[Remembrance] Samsung Omnia W Battery model no

samsung omnia battery model

EB484659VU 1500mAh

- Gives about eight hour backup for average use scenario.

Wednesday, May 7, 2014

Qt app porting to Android

Part 1
development environment
1. Get MinGW gcc, android SDK, android NDK, jdk, ant, Qt android 5.2(latest at the time of writing this)
Add paths to android sdk/bin, sdk/tools, ndk/bin, jdk/bin, ant main dir to PATH. Also define JAVA_HOME to jdk dir.
2. Run android SDK manager, get revision 16, with arm image.
3.  Install Qt android,
4. Create AVD's, check if abi is shown as default/something. This default/ was added in latest revision of sdk, this causes built apps to not run in created AVD. on the net there are tools v22.3 available which will let us create AVD with plain armeabi without default/ prefix.
There was a patch for Qt creator which should be available in qt-andrroid 5.3 onwards.
5. Start porting. Open pro file. And go to projects. Disable shadow build. Use correct kit. Try to build/ run it.
6. If your project links against any external lib, you are needed to do following steps. A. Build that lib using Qt-android's provided toolchain for arm. Next use Add library option in project's right click menu. Select external and provide paths to the include files and the so file.
Also go to run in projects, and add external lib and here select the so file we just built for android. This will make the packager to build the package(apk) and include  the so file within.
Also if there are some external dependencies that that so depends on, then you need to include them too using the run settings extra libs option.
7. At present many features are not well supported so there's going to be a lot of code fragmentation between windows/unix branch of code and android, so for present consider android a new product with legacy requirements rather than full fledged port. And proceed accordingly fixing small stuff at a time.

Monday, April 21, 2014

[Windows][Drivers] Install unsigned device drivers on Windows 8

Win8 enforces driver signatures by default. If you have a Win7 driver that worked OK, I suggest the following to disable driver signature enforcement:

From the Metro or Desktop

Bring up Charms by mouseing over to the right of the screen

Go to Settings

More PC Settings


Advanced Startup > Restart Now

Trouble shoot

Advanced options

Windows startup options


Click on 'Disable driver signature enforcement


Install the relevant driver, allowing the non signed driver to install.

This has worked OK for me installing various old printer drivers. Just make sure you know the provenance of the driver being installed, as always.

[Qt][Android] In my wildest dreams...(Qt Application on Android)

Yeah! I never thought I would professionally develop for Android! But the powers that pay me, have decided to port our product on to Android and so being the sole person available as of this moment I have been tasked with this enormous task!
Hell, I have even got a time line for this! 15 Days!

Now, I did visited the washroom afterwards and laughed my arse off!!! Some statistics for the task:
Approx 17000 LoC C++ STL/Qt
4-5 shared libraries being used by the project
Cross-platform code (Written for Win/Lin as main platforms)
PostgreSQL database being used
To top it all, the code has never been reviewed, forget about a proper audit. I have worked on parts and I have done my best to clean up about 4000LoC but remaining all is three-four year old crap that would give me nightmares if I dipped my toes in it...
Suddenly life has become a war for survival...:D

Tuesday, April 15, 2014

[Qt] Compiling Qt5.2.1 on Windows 8/VS 2013

Qt5. It's a miasma. It's a beast for me. It's something mysterious. I don't know if I should love Qt5 or hate it.
And I think that summarizes my thoughts about Qt5.

I first stumbled across the fifth iteration when some functionality in the product I was working on couldn't be done in existing Qt version (4.5.3 btw). So after looking around for the Oracle, I came to know that the functionality can be achieved by moving to Qt5.

Now our development platform (WinXP/CentOS 5.3/ Qt 4.5.3) was getting a bit too old. And it was all quite buggy to boot. So we decided to embark on the adventure of upgrading the base. Took us two months to upgrade the Linux side to CentOS6.3/ Qt5.0.1 and port the product to new Qt. But after that other high priority work kept us busy and we never got to get the Windows side up to speed.

But then came the fateful day two weeks ago when our IT Manager announced the upgradation of all our faithful old XP systems into Windows 8. And then as it happens, people go ahead and nobody asks the actual user, our PC's were upgraded to Win 8.

Saturday, April 12, 2014

[Thoughts] Senn HD 439 vs Panasonic ht515

Songs tested against on Samsung Omnia W
Bezuban from abcd
gangnam style
Sun raha hain - female  from Aashiqui 2
Saajna from I, me aur main
Teri jhuki nazar - murder 3

Let me call Panasonic p and sennheiser s.
P sounds good, but not excellent. It had reasonable amount of bass and the soundstage is good. The sound is on the warmer side. And if you haven't heard s then you might think p is great. Yeah its that good.
Now when you plug in s, the first thing you notice id that the highs are much more perfected on s. The bells and thrums of guitar sound fuller. The bass gets punchier. The sound experience becomes better by about 35%.
And that's that straight forward difference you hear. P are not bad headphones. In fact these used to retail at about 30% price of s's. And so these are excellent value for money. The pair I have is about five years old and even though it looks totally plasticky it has held through rough use. The cable is strong and doesn't have slightest cable noise. S's cable is thin and has slight cable noise.

Update: After more than 50 hrs of burning in, the soundstage has opened much more. The frequency response also seems slight different - consistent with the opened soundstage.

Thursday, April 10, 2014

[Qt] Compiling ICU with MSVC (Microsoft Visual Studio)

Text highlighted and notes added

Compiling ICU with MSVC (Microsoft Visual Studio)

Qt 5 / QtWebkit requires ICU.

Pre-built packages

The ICU Project site [] provides pre-built packages for MSVC 2010, which should work with compilers too. Anyhow, you have to compile your own version if you want to avoid the MSVC 2010 runtime dependency (because you’re using another MSVC version), or want to tailor the ICU configuration. [] also hosts packages for MSVC 2012 .

Tuesday, April 8, 2014

[PostgreSQL] Server fails to start on Windows 8

Recently stumbled on this problem. We have just upgraded all systems to Windows 8 in my office. The newly installed PostgreSQL was not starting. In PGAdminIII it would ask for password. But fail to proceed further.

On going through logs I came to see this error:

2014-04-08 15:00:10 IST FATAL:  no pg_hba.conf entry for host "::1", user "postgres", database "postgres", SSL off

So after un-commenting the line for IPv6 in pg_hba.conf, and restarting the server, it all started working fine.

The line is :
host     all     all     ::1/128     md5

Interesting point is it used to work fine on Win XP. Maybe Windows 8 has some special handling for IPv6. Don't know.

Tuesday, March 25, 2014

Using QML with C++

Source code here

Recently I stumbled onto an example where the front end of a small application was written in QML and the backend was done in C++. That was the exact thing I was searching for and it provided a great example of how to get QML and C++ working together.

Lets start with the qml: 

// SSH key generator UI

import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
import com.ics.demo 1.0

Tuesday, March 18, 2014

A tale of specificity

I try to be perfect. And I don't feel right till I have finished something completely. So this following tale relates to the relation of specificity and perfection. 

The current project I am working on has a list of lineEdits that I have put into a scrollarea. 

This image shows what I was out to achieve. 
First task was to get the scrollarea right. There I encountered first hurdle. See, the thing is the scrolled widget has a fixed size but here the size changes depending on the no of lineEdits added to the scroll Area. At first I settled on a fixed size and put in a spacer. But it wasn't perfect. There were some edge cases where that failed.
So after a lot of thinking I settled on a minimum size, and set size constraint to SetMinimumSize. Later when I added one widget I would increase minimum size and this proved to be a good solution.

Next step was to increase scrollbar width for use on touch screen. I hunted some CSS on net that let me increase the scrollbar width and style it to be usable on a touch screen. 

The one mistake I did was, I applied the style to scroll area. And this above screen was the result. After going through the code and much more thinking, I understood that I have to be specific. I needed to apply the style only to scrollbar. That meant I have to hunt for the scrollbar object. Some more internetz provided me with verticalScrollBar() function. So I applied the style to it and voila!!! 
I achieved my perfect scrollarea implementation!!!

Thursday, March 13, 2014

Another QScrollBar style

Stumbled onto this nice QScrollBar style:

QString styleString="QScrollBar:vertical {"
    "    border: 1px solid #999999;"
    "    background:white;"
    "    width:30px;    "
    "    margin: 0px 0px 0px 0px;"
    "QScrollBar::handle:vertical {"
    "    background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
    "    stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));"
    "    min-height: 0px;"
    "QScrollBar::add-line:vertical {"
    "    background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
    "    stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));"
    "    height: 0px;"
    "    subcontrol-position: bottom;"
    "    subcontrol-origin: margin;"
    "QScrollBar::sub-line:vertical {"
    "    background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
    "    stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));"
    "    height: 0px;"
    "    subcontrol-position: top;"
    "    subcontrol-origin: margin;"

Gives us following scrollbar: 

Friday, March 7, 2014

Building Qt5 on CentOS 6.3

I am using following method to build Qt5 on CentOS6.3.
Make two dir's. Extract Qt source in source dir. Keep following script in home dir. Execute it from there.

Also go through configure, make and make install phases one-by-one.

export QTBUILD=/home/user/qtsource/qt-everywhere-opensource-build-5.0.2
export QTSOURCE=/home/user/qtsource/qt-everywhere-opensource-src-5.0.2
$QTSOURCE/configure -opensource -confirm-license -qt-sql-psql -platform linux-g++ -prefix /opt/Qt-5.0.2 -nomake examples -nomake tests -no-gtkstyle
#make -j4 all
#make install
cd -

Friday, February 21, 2014

A tangle with shared memory

Recently I was thinking about inter-process communication and especially how to pass/ share data/ information between two running applications. The thing was, I wanted to check out inter-process communication interfaces and see if there was anything Qt provided that I could use. 

My requirement is not finalized or anything. The rough idea is to have a channel of communication between two apps. Here my thoughts diverge a bit in that, I am yet not sure of the method of communication. There are two approaches: 
1. The message system should be a message board where many processes post messages for each other and periodically access the boards to check out their messages.
2. The message system should be P2P. One process sends a message to another and that message (preferably named) makes other process do something like maybe send an acknowledgement. 

Now after digging through the various approaches, I have found out that for scenario 1, I could use shared memory. For scenario 2 I could use socket communication. 

So just to check out the shared memory stuff I went ahead and dug up Qt's provided example. 
The source has one class that contains that example as class SharedMemoryEx. It works as advised. I came across a limitation though. E.g. If first process runs, posts a message, and quits, then in this case the memory is released (at least in Windows case, where I tested the said code), and the message gets lost. 
Well, I think we can engineer around this. Or maybe just use files for this purpose. 
Although while looking around I found an interesting suggestion by someone about making a single instance application using shared memory. 

That's the second class SingleClass.  

Monday, February 10, 2014

Working on Some Qwt Graphs

Link to previous Article though it doesn't have any code. 
This is Link to Code

I am back with some more code. Recently I found working on some QWT graphs and as I dug deeper into Qwt I found that it's quite easy to work out something quite functional. 

So I developed a small utility to display Qwt's graphs and a small logic that would detect spikes in a data stream. 

Here's a screen shot of the actual thing in action. The left graph shows a curve and the right graph shows the detected spikes in that curve. I am showing both up and down-ward spikes. 

The time is shown as units and there are some tutorials on how to get correct time to shoe on X-Axis. But here it doesn't matter as this is just a Proof of concept. 

I have used a c_sinewave header to get the sinewave and I am introducing spikes using a simple randomizing logic. 

On detection part, I have following comments above the block: 

// tmp is current point; listOfSinePoints is super set;
// we will have a window as a subset of listOfSinePoints
// Spike detection logic here
// 1. find goodPoint window
// 2. See if current Point is in that window;
// if it is then it's a valid point else it's a spike

This is quite simple logic and works well for selected cases. A more complex and esoteric logic like prediction-based spike detection can be introduced if such cases are observed where this simple logic fails.

This serves as a good intro to Qwt's plots and curves.

Tuesday, February 4, 2014

flappy bird - this is a bad game!!!

Simple yet very difficult to play game!

Classes for Logging messages to a file and Truncate that file at routine intervals

Code at:

I often used to think that what a simple logging interface would look like. So I went ahead and wrote couple of classes that would do just that. 

The classes are simple. First class LogService has two constructors that set the logFileName. This class also has a function logMessageToFile that writes the provided string to the logFile.

void logMessageToFile(QString);

Now the second class LogTruncateService has similar constructors. But this class implements a QThread. So we have run function as well.

LogTruncateService(QString );
void run();

The run function contains an infinite while loop which keeps checking the time stamps stored in logFile and resets the file after certain no of days are past. Here I have set that time to 10 days.

The limitation is that we need to provide log messages in given format. Else this parser fails. But that is feasible when we are only logging critical activities, errors etc. And that's what is most suitable area for use of this service.  

Friday, January 31, 2014

Messing with QML

Just started learning QML and yeah, it's totally new age! It's going to take me some time to get in gear and know the various internals. 
So I am just messing around and trying to learn the trade lang for Qt 5.