Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Monday, January 30, 2012

Ultimate PDF Converter (on Cloud)

Introduction

I wrote an android app and related server scripts for converting documents to pdf for viewing on the phone. The app can be downloaded here.
I wrote this for a few reasons including experimenting with AdMob, so caution: the app is an adware.

I have cleaned up the sources and uploaded it to google code.
The server scripts can be found here
and the android application can be found here

Some Technical Details
The flow is normally like the following:
  1. Android Application sends the file to the server using the upload.php script
  2. upload.php generates a unique key for this file and passes on the information to the app as well as updates the database
  3. The python converter polls this database and calls the converters (libreoffice/openoffice) and updates the database with success/failure
  4. The app now queries the getfile.php to get the file or the queue number it is in.
  5. The file (converted pdf file) is then downloaded to /sdcard
TODOs
  1. Change the irritating 'open with' to may be 'share with' rather
  2. Conversion of pdfs into maybe images for directly viewing from the app rather than opening it with another pdf viewer.
  3. Conversion of other files: e.g. audio files into wave screenshots or something (?)
  4. Robustness of the scripts and app needs improvement
Any contributors, please?

Monday, June 1, 2009

Logical AND & OR confusions

I have seen many people getting confused with logical AND and logical OR - especially when writing programs. This used to happen to me during my initial learning days with C programming.

Debug this:
if(string!=NULL || string != empty)
{
/* Use the string to do some work, say */
print(string);
}

The above condition will always execute - beware it might also cause an application crash.

What most programmers expect to do is:
if(string==NULL || string == empty)
{
/* Skip the operations */
}
else
{
/* Use the string to do some work, say */
print(string);
}

Which actually should have translated to:
if(!(string == NULL || string == empty))
{
/* Use the string to do some work, say */
print(string);
}

Which can be coded as:
if(string != NULL && string != empty)
{
/* Use the string to do some work, say */
print(string);
}

Note the logical AND.

If you think you get confused with AND/OR, don't worry you are not alone.

PS: This is similar to the rule ~(p or q) == (~p and ~q)