Word Press Syntax Highlighter, Again!

February 23rd, 2012 Bookmark and Share

After struggling with “Google Code Prettify” plug-in for over a year, I decided for a change and this time I went for the WP-Syntax plug-in:
http://wordpress.org/extend/plugins/wp-syntax/other_notes/

Like all other WordPress plug-ins, this was not only easy to install, but is based on open source syntax highlighter GeSHi. My first expression after using this is “Wow! it looks cool”.

If you are a programmer and looking for a simple and elegant syntax highlight option, I will strong recommend this.

Wait, I’m not done yet. Here is the quick sample PHP syntax example:

1
2
3
4
5
6
7
<div id="foo">
<?php
  function foo() {
    echo "Hello World!\\n";
  }
?>
</div>

Unicode Programming In Microsoft Visual C/C++

September 27th, 2010 Bookmark and Share

If you program Unicode applications using Microsoft Visual C/C++ compiler, then you most probably use the TCHAR strings. While using TCHAR strings is very easy, one of the most common problem for me, after a years of ANSI string experience, is to find a correct C/C++ string function to do the same job as I used to do for the ANSI string.

For example, for ANSI string, we use strlen, but for the TCHAR strings, it’s _tcsclen. Though these TCHAR strings functions use a specific naming convention, and one can easily figure out the corresponding function equivalent of ANSI function, but it does require a hit and try. When doing a search today on Google, I found a wonderful reference which I not only bookmarked, but I would like to share with others too. So, here it’s:
http://www.inwa.net/~frog/tcharConversionChart.html

While we are discussing Unicode, here is another wonderful web resource regarding Internationalization and Localization:
http://www.i18nguy.com/

Command Line Arguments Processing in Win32 Application

September 22nd, 2010 Bookmark and Share

It’s common for Windows executable to get and process the additional parameters from the command line. This way you can pass any custom actions when launching an application i.e. open a particular file, print a file, control the application visibility state, etc.

If you are working on C/C++ console application, then you can easily get all the passed command line parameters as the main function arguments. Something like:

1
2
3
4
int main (int argc, char *argv[])
{
    return 0;
}

Here is a nice tutorial for arguments processing for console application:
http://www.crasseux.com/books/ctutorial/argc-and-argv.html

But if you are working in Win32 Windows application, your main entry point may look like this:

1
2
3
4
5
6
7
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
    // Windows initialization code goes here
}

As you can see that in this case, you get a third command line parameter which contains command line string. One straight forward option is to parse all the parameters in lpCmdLine parameter and then use these. This is a bit hassale, but does the job. The good news is that in WinMain function, you can also access two global variables named __argc and __argv which works exactly like argc and argv in console application i.e. __argc contains the count of the parameters passed, and __argv is string array containing those parameters string values.

There is one small catch though (I wasted half an hour to figure this out), and that’s if you are running in Unicode mode, then the __argv will always be NULL, and instead you should use the __wargv for the command lines parameter. Here is the conditional code I used for command line processing:

1
2
3
4
5
6
// Process any command line arguments
#if (UNICODE)
   bool bContinue = ProcessCommandLineArg (__argc, __wargv);
#else
    bool bContinue = ProcessCommandLineArg (__argc, __argv);
#endif

Spent few hours in figuring and making all this works, but in the end it was a fun learning and coding.

Basecamp Extension – Graph your time report

September 18th, 2010 Bookmark and Share

A popular adage is that “A picture is worth a thousand words”. Same is true for the graphs/chart, which is a visualization of your raw data, and gives a bird-eye-view of your thousands of lines of data on a single screen.

Basecamp is pouplar web-based Project Management solution. They have millions of hours of data, and probably you are also one of the users whose company logs thousand of hours per month on the b Basecamp. But if you look at the time report, though it gives you couple of filtering options to filter data by client, project or person, but still all you get as summary is just the totals. If you want to get something more visual then you have to export the data, open in some external application (like MS Excel) and draw a char/graph on that data. It does the job, but isn’t this a hassle?

That’s where the Basecamp Extension comes to help. This extension works under Google Chrome, and gives you instant and on the fly charting tool to display a summary of your time report. Here is a sample chart showing last 7 days working hours of all the company persons:

And here is another sample chart, showing all the company clients hours grouped by the date (multi-series chart):

You also get support for different charts type like Area, Bar, Line, Pie, etc to help you visualize the data in the best way. Go ahead, give it a try (if you are a basecamp user) and share you feedback on:
Basecamp Extension Page

Basecamp Extension – Speed up Time Entry !

September 18th, 2010 Bookmark and Share

Basecamp extension helps speed up the time entry for the previous dates. Thus if you are active guy who likes to post you time entries daily, and post them directly on the Basecamp, then this extension is of no use for you. There are plenty of other interesting Chrome extensions for you to try, or you can browse the web, or you can read the book, or watch some movie, or whatever, do something useful than just continue reading this description.

Okay, so if you are still reading this, it means either you don’t have anything else to do, or you are lazy one like me, the developer of this extension, who logs his hours in notepad, and then posts the hours to Basecamp in one go after a week or some time after a month. If you do this, you know how tiring it is. When adding the back date entries, you have to change the date every time, calculate the time spent on each tasks and then post and verify after ever entry insert, that you got it right. If you share these feelings, then this extension is just the one you are looking far.

With this extension, you can set a default date which appears in all time entries, set the default person for whom you are adding these entries (your seniors or boss?), or auto calculate the time spent on the task from the pasted description (I love this one).

Tip: For this extension to parse and display the spent time from the task, you have to paste a description like this (usually from you text log file):
[Start-Time] [End-Time] Description
Here is a quick example:
11:30 11:55 Reading About Chrome Extensions
12:10 13:55 Developing Basecamp Chrome Extension

Your feedback is highly appreciated and is of great value. You can add you comments and feedback here.

Warning: This extension is highly addictive, and there are good chances that it will make you even more lazy. I have warned you, so if you still use it, I’m not liable for any damage or claims, whether in an action of contract, tort or otherwise, arising from, out of or in connection with this extension or use of it.

Dynamic Subtitle Translator

August 20th, 2010 Bookmark and Share

If you frequently watch movies with the sub-titles, but have problem finding the sub-titles in your native language, then you can easily translate the existing/available sub-titles file to language of your choice.

Dynamic Subtitle Translator is a web-application which translate the Subtitle from one language to other language. On the back end, it uses the powerful Google Translation service to do the actual translation. Once the automatic translation is done, you can also manually edit/refine the translation and then export the translated subtitle back to the original format.

Though the translated text is not 100% accurate (as it is only machine translation), but at least 70% of the translated text is correct, plus if you have courage and patience, you can manually edit the translated text and make a perfect translation and share it with others.

One of the nice, and my main inspiration behind this tool, is the sub-title translation to the Urdu. It’s not perfect, but using the language transliteration feature, you can easily tweak sub-titles in minutes. Just imagine watching foreign movie with Urdu sub-titles.

Go, give it a try and share you feedback and comments. The service link is:
http://www.syedgakbar.com/products/dst/

CodeIgniter and File Upload Library

August 15th, 2010 Bookmark and Share

CodeIgniter is a compact and amazing framework for developing neat and clear PHP projects. The more I work in this, the more I’m falling in love with it. Though it’s very well documented, but you can’t expect to find all what you need in the help file.

I was working on a project where I do need to support the subtitle file upload (of type SRT and SUB). According to the documentation all I need to do to support this is add the following line:

$config['allowed_types'] = 'sub|srt';

But when I add this line, the CodeIgniter was reject the SRT and SUB files with error that file type upload is not supported. As the framework is open source, thank God, so I looked at the corresponding code, and found that during upload, the code also checks for the file mime types and reject the file if the corresponding mime type is not defined in the “/application/config/mimes.php”. Once I know this, fixing this was just a matter of minutes. All I did was added the following two lines to the $mimes array in the file and it worked flawless:

'srt' => array('text/plain', 'application/octet-stream'),
'sub' => array('text/plain', 'application/octet-stream'),

The reason I added both the “text/plain” and “application/octet-stream” is because, when uploading the file, I sends the mime type as “text/plain”, while chrome and other browsers send “application/octet-stream”. Browsers! Browsers! Browsers!

I'm back!

May 29th, 2010 Bookmark and Share

Sorry to all of those who have been trying to access this site since last week. I had some problems with my previous hosting service and have to shutdown that account.

I have to wait for the next weekend to get all the stuff moved back to the new hosting service and configure it. It was tiring job, but all is done now.  So far everything seems to be running fine and life is back to normal.

“All is well, if end is well”

WordPress Blank Permalink Options Page

May 29th, 2010 Bookmark and Share

When I migrated my website to the new hosting service, on the blog end, all was working fine except the Permalink Options page in the WordPress admin was not displaying any content.

After trying multiple things and wasting time here and there, I found the solution as discussed in the following thread:
http://wordpress.org/support/topic/356829

Basically, my problem was two folded. And here are the two thing which worked for me:

  1. Remove the “.htaccess” file from the blog home directory. After I did this, it started showing the Permalink heading and brief description, but there was still no option to view and set the Permalinks options.
  2. Next, I followed the instruction as posted by “zeniph” user and it worked well for me. Basically, looks like the new hosting service I’m using was using some configuration so that “apache_mod_loaded(‘mod_rewrite’, true);” call was always returning false. So I have to force set the value true here (as I know mod_rewrite is supported by current hosting service).

I hope this helps.

Hindi to English and Hindi to Urdu Transliteration

May 29th, 2010 Bookmark and Share

Urdu and Hindi are two of the most popular languages of sub-continent. The speaker of these two languages combined are more than a billion. However the one major difference between these two languages is how these are written. The Hindi language is written using Devanagari script, while Urdu language is written in Urdu script (oriented from Persian and Arabic).

As a native speaker and reader of Urdu, the Hindi written in Devanagari script would appear to me as alien language even though I would recognize 70 to 80 percent of it when some one actually read that for me. One day tired of this complexity, I started exploring the automatic transliteration options. As always, some very good work is already done on this and here are some of the interesting sites I found for transliteration:
http://www.crulp.org/software/langproc/h2utransliterator.html
http://www.puran.info/HUMT/index.html
http://translate.malerkotla.co.in/

Though these are great, but there are some problems with these transliterations services like:
1. As there is not direct mapping of some characters between these two languages so most of the time transliteration of such characters is not correct e.g. devanagari character ? (za) in Urdu could be mapped to to ?(zay), ?(zoad), ?(zal) and ?(zoin) characters depending on context
2. Some of these transliteration services, just provide a limited text box for transliteration and may be too limiting depending on what you want to convert. Plus you also have to visit their site and copy and paste your content to get the transliteration done.
3. Third and most important, these are slow. I think this is due to the reason that they are actually doing word look-up in the database/dictionary for the mapping. This brings excellent results, but response is slow.

To overcome some of these problems, I have written my own Hindi to English transliteration engine. This transliteration engine follows mixture of ITRANS and IAST Hindi transliteration schemes (to produce more human readable text).

For the Hindi to Urdu transliteration, I decided to use Google Indic Transliteration API. So for this mapping, I first convert the Hindi to Roman and then pass this to Google Transliteration API for Roman to Urdu transliteration. The final results are amazing. You get almost ready to use transliteration. The other plus points are that it’s very fast (that’s why I’m fan of Google), and you can do this transliteration on any page using the Dynamic Language Tools bookmarklet. You can read more about this here:
http://www.syedgakbar.com/products/web/

Here is a quick demo of this service in action:
Hindi to English Transliteration