Saturday, January 13, 2018

Migrated!

I have decided to migrate blogging over to jekyll + github-pages. They can be found here.

Saturday, February 18, 2012

Eclipse ADT: 'Unable to open sync connection!'

Sometimes, you get this wierd looking error on eclipse while working/developing on your phone.
[2010-10-12 09:36:48 - myapp] java.io.IOException: Unable to open sync connection!
[2010-10-12 09:36:48 - myapp] Launch canceled!

You have tried the following (but in vain!):
1. Disconnecting/connecting the USB cable.
2. Restarting eclipse.
3. Restarting adb daemon.
4. Restarting your computer!


Even after this if the problem persists. Just disable/enable 'USB debugging' on your phone.
This should most of the times solve this issue.

Wednesday, November 23, 2011

A short perl code to find union of 2 arrays in perl

Using slices on hash variable :)

sub array_union {
    my ($arrRef1, $arrRef2) = @_;
    my %hash;
    @hash{@$arrRef1} = undef;
    @hash{@$arrRef2} = undef;
    return keys %hash;
}

Wednesday, October 12, 2011

Upgrading CM7 on LG O2X

If you are planning to upgrade CM7 on your LG O2X, please make sure you have done the following!
Upgrade clockworkmod to a version >= 5. (You can do this from 'ROM Manager' itself)

Monday, September 5, 2011

ARFF file-reader in C++

Long time ago I had written a C++ library to parse ARFF files for one of my Machine-Learning projects. Today, I'm making the code open-source! Here's the link to the code hosted on github: https://github.com/teju85/ARFF. This also comes with doxygen documentation for the API exposed by this library and also has unit-tests (written using google-test) for CYA.

Sunday, August 28, 2011

Iterator for templated STL containers in C++

I realized this today! The following code almost always will give compilation error.
std::vector::const_iterator itr;

And the compilation error (with g++ version 3.4.6) will be as vague as:
error: expected `;' before "itr"

The solution is to just do the following:
typename std::vector::const_iterator itr;

Sunday, July 31, 2011

Getting (approx?) memory usage information on linux

Here's the code for doing so: (Tested on Ubuntu 10.10)

#include <unistd.h>
#include <stdio.h>
int processMemUsage() {
    int vm = 0;
    FILE* fp = fopen("/proc/self/stat", "r");
    if(fp == NULL) {
        return vm;
    }
    int dummy;
    char cmd[128], state[8];
    fscanf(fp, "%d%s%s%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
           &dummy, cmd, state, &dummy, &dummy, &dummy, &dummy,
           &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
           &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
           &dummy, &dummy, &dummy);
    unsigned long vmSize;
    fscanf(fp, "%lu", &vmSize);
    fclose(fp);
    vm = (int) (vmSize >> 10);
    return vm;
}

Hope this helps!