Pages

Friday, 28 December 2012

Partial upgrades to core system libraries like libc6 can sometimes lead to "ldconfig not found on PATH" error. To fix this, first try to find if ldconfig is present somewhere in the system.

find / -name ldconfig

The above command returns the path of ldconfig if found. I got the path as /var/cache/ldconfig.
Now copy the ldconfig to /usr/bin or similar directory which are added to the PATH variable.

sudo cp -r /var/cache/ldconfig /usr/bin/

Now we remove (downgrade) the library that caused this problem. In my case it was libc6_2.11.3-4 which caused the problem. So removing the current one will downgrade to the previous installed version, which is libc6_2.5.1-1eglibc27+0m5.

Tuesday, 27 November 2012

My unused Yahoo account got compromised yesterday (Sun, Nov 25, 2012 at 2:22 PM). Someone logged in from Vietnam. Or most likely that someone relayed through a server located in Vietnam with the IP address 123.22.191.25. pfft..
I got notified to my another email account that the Yahoo account's password got changed. Well there was two emails, one at 2:22 PM and the other at 2:23 PM. When I entered the password, Yahoo mail asked the security question, but I opted for verification code to be sent to my another email account.
Anyway, I got hold of the account, but who needs a Yahoo account anyway. I just initialized account termination.Relayed login IP address screenshot | Relayed login Country Info screenshot

Sunday, 18 November 2012

Nokia N900 with Maemo Operating System is one true computer rather than a smartphone or an internet tablet. One of the judging criteria is whether we can develop applications right on the phone. With Nokia N900, we surely can.

Java platform is an amazing environment. We have the JRE with the JVM and the libraries, and of course with Java and a whole bunch of JVM languages like Clojure, Groovy, Scala etc. To develop applications in Java we need the Java Standard Development Kit (JDK) which contains the compiler and the supporting files. The cool thing about Maemo is that we can install JDK compiled for the ARM architecture.

The easiest way is to install the IceTea6 version of the OpenJDK preset at the maemo repository.

To manually install, follow the steps below.
1. Get OpenJDK for ARM. Cambridge Software Labs(link down) provides optimized version of OpenJDK for ARM. Download OpenJDK v1.6.0_0. (Mirror).
2. Copy the archive to /opt directory of the phone. Say you have downloaded or copied the file to MyDocs/tmp, then run the below command to copy it to /opt. We need to be root to preform the following operations. Install rootsh from the maemo-extras repository to get root privilege, if not done already.

Friday, 9 November 2012

BeanShell is a pure Java interpreter. BeanShell uses BeanShell Scripting Language which is a Java syntax compatible scripting language for the Java platform (JSR-274). BeanShell supports dynamic execution of the full Java grammar and semantics with transparent access to Java objects and APIs. It also provides additional scripting features which is a strict superset of the Java language syntax.

Setting up BeanShell
1. Download latest BeanShell jar file. The current one is bsh-2.0b4.jar.
2. Place the jar file in a directory say D:\env\javaLibs\.
3. Set CLASSPATH environment variable pointing to BeanShell jar file. It will look like .;D:\env\javaLibs\bsh-2.0b4.jar; under Windows. The . is to look for classes in the current directory. If the variable is already present, append the path at the end separating the paths with a semi-colon.
4. Open command prompt and run java bsh.Interpreter (assuming that JDK or JRE is present in the path).

Now we have a fully working Java interpreter which we can use to quickly prototype ideas. The interpreter is similar to what we see in other dynamic languages like Python or Groovy.

Friday, 2 November 2012

Click co-ordinates for HTML5 canvas element can be obtained using both layerX, layerY property or offsetX, offsetY of the click event.
Firefox does not support offsetX, offsetY so we have to use layerX, layerY amd opera does not support layerX, layerY, so we have to use offsetX, offsetY.

Tuesday, 30 October 2012

We can scroll to an element which is inside a div which has scrollbar using jQuery.animate() and for scrollTop pass in $(elemId).parent().scrollTop() + $(elemId).offset().top - $(elemId).parent().offset().top

The scrollTop() method sets or returns the vertical position of the scrollbar for the selected elements.
The offset() method allows us to retrieve the current position of an element relative to the document.

The idea is add the current offset of the scrollbar with the current offset of the element, and subtract the top offset of the parent element, i.e., the area which is fixed below which the scroll area beings. Offset on an element relative to the document can be positive or negative, depending on whether the element is yet to be scrolled or the element has passed the scrolling.

When we try to build and run any project under Xcode and if we get an error like "Unable to find Mach task port for process-id 274: (os/kern) failure (0x5)", then it is mainly due to some issues in validating cryptographic certificates. As written in the Building GDB for Darwin article the Darwin kernel refuses to allow GDB to debug another process if the user don't have special rights. Kernel allows a root user to debug. The latest method to allow GDB to control another process is to sign it with any system-trusted code signing authority. I got this error because of wrong system date. If system date is wrong, then verifying cryptographic signature fails.

Monday, 29 October 2012

ncurses is a C API that helps us in creating text based user interfaces in a terminal-independent manner. It is a free software emulation of curses in System V.PDCurses is a public domain implementation of the curses library for DOS, Win32, OS/2, X11 platforms. Installation procedure is given below.
1. Install latest GCC (>=v4.7.2). Download it from equation.com and follow the installation instructions. Let's say GCC is installed into D:\gcc4.7.2 directory.
2. Download pdc34dllw.zip or newer from sourceforge.net. For direct link click here.
3. Extract pdcurses.dll to "D:\gcc4.7.2\libexec\gcc\i686-pc-mingw32\4.7.2" directory.
4. Extract pdcurses.lib to "D:\gcc4.7.2\i686-pc-mingw32\lib" directory.
5. Extract curses.h and panel.h to "D:\gcc4.7.2\i686-pc-mingw32\include" directory.
6. Ensure that proper environment variables and path variables are set. The path must be added to the front of the other path variables so that it takes precedence.

EQ_LIBRARY_PATH
d:\gcc4.7.2\i686-pc-mingw32\lib

PATH
d:\gcc4.7.2\bin;
d:\gcc4.7.2\libexec\gcc\i686-pc-mingw32\4.7.2;

7. Run the sample program to see if it prints "Hello World from PDCurses!" in the command prompt.

8. To run the executable the pdcurses.dll library is required. So if we are to bundle the app, ensure that the pdcurses.dll file is also included along with the executable.
9. Awesome! Now we have a working curses library.

When scanf() is used to get input from stdin and then using getchar() will mostly make the program exit without waiting for the input from stdin. The reason is that scanf() reads the input till new line from stdin which is a buffered stream. So the new line is still present in the buffered input stream. So getchar() sees the buffer as non-empty and reads from it which is the new line and returns. Instead, we can use fgets() to get the input as string and if we are looking for an integer input, then use strtol() to get the integer (long) value from the string.

Monday, 24 September 2012

CherryPy is a minimalist, pythonic, object-oriented HTTP framework.
For Windows,
1. Download and install the latest version of python 3.
2. Download and install the latest version of CherryPy with wsgiserver3 support.
3. Test the installation by running an example program (say hello.py) like below.

Thursday, 20 September 2012

If we have an Android project which does not have a build.xml, then we can generate a build script by running the below command.
1. Navigate the android project root directory
2. Update the project to generate the build file

Sunday, 9 September 2012

The GNU Compiler Collection (GCC) can be installed in Maemo on Nokia N900, which allows on device development! To install them, first add the Maemo SDK repository to the application catalogs. Do *not* run upgrade (apt-get upgrade) after enabling the SDK repository. After the installation of the build tools, disable the SDK repository. Once the repo is disabled we can run apt-get upgrade command safely.

Thursday, 6 September 2012

Bash shell scripts can be used to do a variety of things. It is very easy to schedule the script to run under crontab. It would be helpful if we log the steps with date time and a message. It can be done as follows.

Wednesday, 22 August 2012

To load external script files or to make calls to external hosts in a PhoneGap (Cordova) web application running on iOS devices, add a new property say Item 0 to the ExternalHosts with value * in the Phonegap.plist file.

To develop native applications using C/C++ and GTK+ for Maemo, we need to install the Maemo 5 SDK and the development environment which include scratchbox, which is used for cross-compilation. The host environment here is Ubuntu 12.04 LTS 64bit. Scratchbox now supports 64bit platform.
1. First, we need to install scratchbox. For that add the scratchbox apt source url

deb http://scratchbox.org/debian/ hathor main

to /etc/apt/sources.list. We can use vim to do it or the following command.

9. The SDK installation is not complete yet. After the successful completion of the above steps, we need to install Nokia-closed binaries for the target platform. To install Nokia binaries, we need to accept the EULA at the Nokia website.
10. Once we accept the EULA, we will get a token code and a source url with the token code to access the closed components of the SDK. The website says to not distribute or share the token code we get, and it is for personal use only.
The url will be of the format

Friday, 17 August 2012

In android mobile browser, compiling a dust.js template caused the error "p.substr [undefined]". It worked fine in desktop browsers. The reason for the error was the closing of <input class="xyz" /> tag elements. Same in the case of img tag as well.
So writing the element like

Thursday, 9 August 2012

jQuery Mobile has many events associated with a page. Here we will discuss about the difference between 'pageinit' and 'pagechange' events. When a page is displayed for the first time 'pageinit' event will be fired. 'pagechange' event also fires here and for every page change. When we move from say page1 to page2 where page2 was not displayed before, 'pageinit' event will be fired. 'pagechange' event will also get fired since we changed the page from page1 to page2.

When we move from page2 to page1, where page1 was displayed previously, only 'pagechange' will be fired.

Tuesday, 17 July 2012

Android 2.3 browser is buggy when it comes to CSS3 properties. Recently we got this
weird bug when user types something in a textarea component. The page jumps around with
each character we typed.
We can fix that by not using any CSS3 3D properties like -webkit-transform: translate3d(0, 0, 0);.
Also, in the AndroidManifest.xml file add windowSoftInputMode="adjustPan" in the activity tag.
Modified activity tag will look like:

Sunday, 24 June 2012

Recently I got the error message, "No network connection available, operation cancelled", when I try to add a facebook sharing account. The problem is with the curl library. We need to update it the to latest version. Add extras-devel, extras-testing repository if you cannot find the library in the stable channel.
Open terminal (Ctrl + Shift + X) and give the following commands:

Thursday, 14 June 2012

Suppose you are adding select menu to the page dynamically using JavaScript, jQuery mobile will not style the select menu. So have to refresh the select menu.

$('.mySelectMenu').selectmenu('refresh', true);

Sometime we might get an error like: "Uncaught cannot call methods on selectmenu prior to initialization; attempted to call method 'refresh'". To resolve it by first initialize the select menu and then refreshing it.

20 Nov 2012: Update with JQM 1.2.0 code explanation given below.
Make sure that the selector returns items which are all select nodes. Otherwise JQM will throw the above mentioned error. See the below JQM code.

You can add host entries in the android emulator using the following commands.
1. You need to mount the android emulator's file system in read write mode.
2. Then upload the modified host entry to /system/etc/

Monday, 21 May 2012

The recommended way to change the plus and minus icons of the collapsible sets (accordian) in jQuery Mobile is to specify data-expanded-icon and data-collapsed-icon attribute to the div. But sometimes it does not change the icons. In such cases we can change it manually by overriding the .ui-icon-plus and .ui-icon-minus classes giving the background-position for the down and up arrows. Add a class eg-accordion to the div with data-role="collapsible-set" and see the below CSS overrides.
eg:

Sunday, 13 May 2012

To show or hide an element when use click on a button, you can use jQuery's .toggle() method. It toggles the display of that node. It adds a style display: none; and display: block alternatively, with each click.

Say that you are in an event handler function and you want to get the closest element that matches certain conditions from the current event's target node. You can use .closest() method provided by jQuery.

.closest() returns only one element matching your selection criteria where as .parents() returns all the matched elements. Also there is significant difference in the way that both these methods work. .parents() travels all the way up to the DOM's root element and then filters the collection. .closest() travels the hierarchy until it finds the matched element and then returns. So if you want to get only one element, then .closest() is more efficient.

Subversive plugin for STS is much better than subclipse svn plugin. Install subversive, and then uninstall subclipse by going to STS Help->'About SpringSource Tool Suite'->'Installation Details'->'Installed Software' and remove the ones with 'id' containing org.tigris.
Next navigate to STS plugin directory from the command line and run the following commands:

$ ls |grep org.tigris.subversion|xargs rm -rf

01 May 2012 Update: After working with this plugin for around three weeks, I find it difficult to make directory changes. I find it difficult to use STS with subversive plugin. I agree that it has got more options than subclipse, but when it comes to daily operations like commit, rename, delete directories, branching, it is a big mess (at least for me). So I am back to subclipse.

In the 'locales to be generated' dialog box, choose "ja_JP.UTF-8 UTF-8". If you use English, choose "en_GB.UTF-8 UTF-8" or "en_US.UTF-8 UTF-8", which ever is appropriate and click Ok. Next choose you default locale.
3. Reboot (or logout session, which ever works).

Tuesday, 7 February 2012

'ImportError: No module named config' error occurs due to the naming conflict. If you named your test file as pyramid.py, then you are most like to get this error when you try out the pyramid web framework examples. Simply use a different name for your file.

Monday, 30 January 2012

When trying to configure the latest binary of ghc (7.0.4) under Kubuntu 11.10, you might most probably get an error like: "libgmp.so.3: cannot open shared object file". You need libgmp3c2 installed before trying to configure ghc.

Monday, 23 January 2012

BigInt is an awesome library that allow us to write C/C++ programs that use arbitrary precision arithmetic. Here we'll go through on how to setup the library as a shared object under GNU/Linux (Kubuntu).

Sunday, 22 January 2012

I got this weird bug that tells that the Kubuntu installer has crashed. I tried to install three times and the same thing happened. Later I changed the file format for the root partition and everthing got sorted out. The problem was that I was using btrfs as the file format for the root partition, which lead to the error. Now that I have changed to ext4 for root, Kubuntu installs fine. You can use btrfs for other partitions like /home and not for root at the moment.

Sunday, 8 January 2012

Sometimes, after editing your post, the URL for the blog post might end up like _02.html. So to edit the url, there are two ways. If you don't have any comments, then you can create another post with the desired title, so that the url follows the title, and paste the contents of the post. Then you can schedule the post to be somewhere near the original post's date and time, and then publish the new post. After that you can delete the old post.
If you seriously messed up the urls, then export the blog & it's template. Then rename the current blog to a random address, and create a new blog with the original blog's address. Import the posts and template to the newly created blog and delete the old blog.

Saturday, 7 January 2012

We can use CSS alone to display tooltip when we hover on links. The idea is that we'll add a span tag to the anchor text and hide them initially using display: none; for the span tag. Only when we hover, we'll display the span tag by changing display to block.
Say I need to show tooltip "..lost in silence" when I hover on a link with text 'kadaj'. Then the anchor tag will be

The only thing that changes is the top and left value depending on where the tooltip should appear when you hover on the link. However, there is a drawback when using this method. It will work only if the position of the link is fixed. Here we are using absolute position for the tooltip, so if the position of the link changes, the position of the tooltip won't change, unless you use javascript and change it accordingly. It is good for pages with fixed layout. Not ideal for blog posts, where the position of the post changes when new posts appear.Demo

Html5 History API provides a way to maintain history of the current session. This information can be used for page navigations. It will really come handy when you are using AJAX to load pages and want to have browser navigation (back/forward) active. Using Html5 History API, we will maintain the history and use it for navigating back and forth using browser's navigation button. We will use 'hashchange' event and hashtags for urls.
To navigate using the browser's default navigation buttons, i.e, by using the back and forward buttons, there must be a change in the URL. The navigation buttons get active only if the URL of the current window (page) changes. When we use AJAX (JSON), the URL of the current window doesn't change. So we won't have any active navigation, which implies, no history as well.
To add hash to the URL without causing the page navigation, we'll usewindow.history.pushState(null, "", "#hashtag") method. We need to be concerned mainly about the third parameter, which is the hashtag string. After that we'll trigger a 'hashchange' event $(this).trigger("hashchange");.

These are some of the notable functions in the history API.

window.history.pushState(data, title, url)@param data
data is generally something that is specific to the context of the particular page.
Say in the first page you retreive data in JSON format. Say our data is:

{
page: '1',
title: "Tutorial",
category: "Html5",
desc: "intro"
}

So when we want to navigate to another page we can save that data so that, the next time when we revisit, popstate will fire and you can retreive the data through event.originalEvent.state object.

@param title
The second parameter can be any string.

@param url
Can be hashtag or a string. Note that you can't change the baseURI,
or it will throw SECURITY_ERR exception. Otherwise it will be easy for URL spoofing. This value will be appended to the baseURI without loading the appended URL. This will activate the browser history, so that we'll have active back and forward button.

The 'popstate' event
When you navigate in history, popstate will be fired, and the data corresponding to the state will be popped. Theses data objects are kept in a stack using the pushState function explained above.

window.location.hash
This variable will contain the current hashtag of the window

The 'hashchange' event
'hashchange' event is will be fired whenever there is a change in navigation, i.e if you travel back and forth in history, each time the hashchange event will be fired. So we can listen for the hashchange event and depending on the hash, which we can obtain from window.location.hash, we can take the necessary action. Since we already listen for the hashchange event, we'll trigger the event when the user clicks the page's anchor link to go to that particular page. Otherwise, we can write a separate way to deal with clicking anchor links as opposed to clicking back/forward buttons, which isn't really necessary. So that's the reason we trigger 'hashchange' event manually.

window.history.replaceState(data, title, url)
This function is same as that of push state. But instead of pushing a new state to the stack, it will replace the top state (from the stack) with the one specified in this function.

We use the native DOM API instead of jQuery for this particular case because of the way jQuery treats <script> tags. jQuery inserts script to DOM, then evaluates the script separately and then it removes the tag from the DOM. So you won't see the script tag, but the script will get executed.

Windows Live Mail client looks better than Thunderbird. If you want to migrate to Windows Live Mail client from Thunderbird, then do as follows:
1. First, you need to backup the Thunderbird folder under the C:\Documents and Settings\<your-user-name>\Application Data folder and any local folders if any.
2. Install ImportExportTools add-on and restart thunderbird.
3. Right-click on the folder which contain the mails you want to export. Say Inbox, Sent Mail etc, and choose Import/Export -> Export all messages in the folder to EML Format from the context menu. Choose a location to save the exports, say C:\mails\eml-format\Inbox for inbox and C:\mails\eml-format\Sent Mails for sent mails.
4. Open Windows Live Mail client and from the File menu choose Import -> Messages -> Live Mail. Choose the directory from the previous step where we saved the mails. So at first we will import mails from Inbox folder, so we'll choose C:\mails\eml-format\Inbox folder. Click Next and choose All folders, and complete the import wizard. Similarly for the other folders.
5. If you have successfully imported the emails, then it will be shown under the Storage Folders -> Imported Folders section on the left pane. Now you can select all the emails under that folder and drag-and-drop to Inbox or any other folder, and organize them accordingly.
5. Voila! Enjoy new Windows Live Mail client.

If you are using IDEs like Eclipse with SVN plugins, then to generate a diff file, right-click on the file and choose Team -> Create Patch -> Save in File System (browse to the directory of your choice and give the file a name, say patch.diff) and click next. Choose Selection and click Finish.

Monday, 2 January 2012

HDBC-sqlite3 is a package that provides support for sqlite db interaction for Haskell. To install it in Windows you need to have sqlite source.
1. Download the sqlite source code and extract to any directory, let's say 'C:\sqlite'.
2. Run