Thursday, January 20, 2005

Welcome back Raj!

May I add in a low, menacing Agent Smith voice - "we missed you!". Those of you who know Raj would probably know that he has blogged for a brief interval before but just when things were getting nicely warmed up he pulled the plug :-(.. Well, he is back again - here. Hope you'll be around for a while this time Raj!

Saturday, January 15, 2005

Retro...

While playing with different shades of blue I came up with two designs which look very "Austin Poweresesque". Do try setting them as your tiled wallpaper (which is if you are feeling retro too!)






Experimenting with different colors is turning out to be one of my latest hobbies.

Technical Notes: The latest version of Paint Shop Pro has an interesting feature whereby you can mix two colors on a palette like you would when painting in real life. You can always choose colors the normal "computer" way, i.e. by specifying their RGB or HSL values but the ability to blend colors in this way, adds an interesting dimension to the whole experience.

Thursday, January 13, 2005

Checking for presence of Indic support from .NET

The CultureInfo class under the System.Globalization namespace is indispensable when writing applications that require Globalization/Localization support. To create an instance of this class, you simply pass the name of the culture; e.g. to create an instance of hi-IN culture, I will do something like this:


CultureInfo ciHindi = new CultureInfo("hi-IN");


There are other CultureInfo constructors too for example there is one which takes the LCID of the culture you are interested in. So the above snippet could also be written as:


CultureInfo ciHindi = new CultureInfo(1081);


On English version of Windows - one most widespread in India - Indic and Far-Eastern language support needs to be installed separately from Control Panel:



If you do not have Indic support enabled, the user might get issues when displaying Indian language characters (e.g. trying to display CultureInfo.LocalName will simply show you a string of boxes). It might be a good idea to prompt the user to enable Indic support prior to running your application. Here is how you can check for its presence on a client machine:


using System;
using System.Globalization;

public class SamplesCultureInfo
{
    public static void Main()
    {
        bool bIndicInstalled = false;
        // Displays several properties of the neutral cultures.
        foreach ( CultureInfo ci in CultureInfo.GetCultures( CultureTypes.InstalledWin32Cultures ) )
        {
            if(ci.LCID == 1081) //hi-IN - since all Indic cultures are installed en-masse,
                     //presence of one indicates presence of others too
            {
                bIndicInstalled = true;
                break;
            }
        }

        if(bIndicInstalled)
        {
            Console.WriteLine("Indic support is present on this machine");
        }
        else
        {
            Console.WriteLine("Indic support absent from this machine");
        }
    }
}

Wednesday, January 12, 2005

Tooltips Redux

I had spoken a few days ago about tooltips in Web-UIs. They have one small shortcoming – you cannot control the visual appearance of the tooltip. The system default settings apply to your tooltip. There is (there usually always is!) a workaround. IE 5 had introduced a new technology called “behaviors”. In their simplest avatar, a behavior could be just a jscript file with the .htc extension. But there is more to behaviors, and I’d rather have you read about them here.

So why this digression from tooltips to behaviors? Well because there is a sample behavior that you can download from MSDN which gives you total control over appearance of your tooltips - they can contain HTML markup. This can come in especially handy when you are trying to show Indian scripts in a tooltip, which typically require slightly larger font for them to be legible. Here is an example (Thanks Vinod for supplying me with Tamizh translation!). More details about the tooltip behavior can be had from here.

Behaviors are close to 5 years old but can be used creatively with ASP.NET for creating some interesting UIs. (Hint: The IE Webcontrols use them internally). I’ll talk about an interesting use in one of my future posts shortly.

Monday, January 10, 2005

Converting ISCII to Unicode

The usage of computers proliferated into non-English speaking nations much before a unified global standard for representing data (Unicode) took shape. Different countries adopted different approaches to encoding data – most notable of them being the DBCS/MBCS we see for far-eastern languages (such as Simplified/Traditional Chinese, Japanese etc.). The idea was this – two characters of 1 byte each (between 128-255) when interpreted together designated one character – e.g. you combining Ê (0xCA) and ¯ (0xAF) gives you the ideogram for stone: 石 (Unicode 0x77F3) in Simplified Chinese. The system besides being prone to programming errors had some limitations – because the same lead-byte, trail-byte combination, depending on which “codepage” you are looking at ,can represent multiple languages, it is not possible to have documents with more than one far-eastern language (e.g. the same lead-byte (0xCA) trail-byte (0xAF) sequence gives you坒 (Unicode 0x5752) under Traditional Chinese codepage – two totally different characters!).

In India too, we had a similar indigenous encoding schemes, the most widespread of them being ISCII (Indian Script Code for Information Interchange) – the idea is very similar in that you use characters between 128-255 to denote Indian language characters. Depending on the ISCII encoding you chose, the same set of bytes could represent a different language.

The Encoding class in .NET allows you to convert between these encodings and Unicode. Recently while having a discussion with Dr. Pavanaja, it occurred to me that you can use the Encoding class to also do the conversion from ISCII to Unicode.

Let’s see an example (I chose to write it as a web-page and not a console app because the final Unicode result will not show up on console):

<%@Page Language="C#"%>
<%@Import Namespace="System.Text"%>
<%@Import Namespace="System.Globalization"%>

<script runat="server">
void Page_Load(Object o, EventArgs e)
{
    //Response.Write("Hello World");
    Encoding encFrom = Encoding.GetEncoding(1252);
    Encoding encTo = Encoding.GetEncoding(57008);
    String str = "ØÛÆèÄÜ";

    //Get it into a byte array...
    Byte[] b = encFrom.GetBytes(str);
    String strUnicode = encTo.GetString(b);
    Response.Write(strUnicode);

}
</script>

57002 denotes the ISCII Hindi Encoding. Other ISCII Encodings are:









































Codepage NameLanguage
57002 x-iscii-de Devnagri
57003 x-iscii-be Bengali
57004 x-iscii-ta Tamizh
57005 x-iscii-te Telugu
57006 x-iscii-as Assamese
57007 x-iscii-or Oriya
57008 x-iscii-ka Kannada


'ØÛÆèÄÜ' is an Indic String – with the right software/font you should be able to view it. You can also create an HTML document (thanks agin to Dr. Pavanaja for the tip!) with the following Meta tag, to view the contents of the ISCII string without explicitly doing conversion to Unicode (though IE does it internally for you before rendering it using the sytem installed Indic Open-Type fonts):

<meta http-equiv="Content-Type" content="text/html; charset=x-iscii-de">

Friday, January 07, 2005

Tooltips

Tooltips can be a useful element even in Web UIs. For most tags you can specify the title attribute which gets rendered as a tooltip for that tag by IE. For the img tag, the alt attribute acts as its tooltip, but in case you also supply a title attribute, it overrides the value of the alt attribute.

Let’s look at yesterday’s example with tooltips enabled. I have also set the table-layout of our table’s style to fixed , so you no longer need another div inside the td (do a view source – that should clear things up a bit)

Have a great Weekend!

Thursday, January 06, 2005

Ellipsis...

It is common to have user interfaces that clip overflowing text and display ellipsis where the text crops. When you move your cursor over the clipped text, you will typically get a tooltip displaying the complete text. Since it is widely accepted that pictures are worth a thousand words, let me share a screenshot (of my Internet Explorer Bookmark pane – pressing Ctrl + I gets you there) to illustrate my point:



You can implement a similar UI in your web-based applications, by using the CSS text-overflow attribute. This is what you need to do:

  • Ensure that the text you want to clip is encapsulated in <nobr> </nobr> tags or set the white-space style attribute of the tag containing your text to nowrap

  • In the style attribute of your container tag – say div, set the width attribute to your desired width

  • In the style attribute of your container tag, set the text-overflow attribute to “ellipsis” and overflow attribute to hidden.

Let’s see a quick example of this in action.

Unfortunately, cropping text will not give you tooltips automatically. You can set the title attribute of the div to get the tooltips. Tooltips in web UIs is another interesting topic. I’ll take it up tomorrow!

Wednesday, January 05, 2005

When friendly is not friendly

Internet Explorer introduced “Friendly HTTP Error Messages” for certain HTTP errors (400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505). For instance if your ASP page does something bad that results in HTTP 500 error, IE will typically display a friendly message to the user, which looks something like this:



Additionally, the error message might contain other information that was generated by the offending page. If the error message produced by your page is more than 512 bytes (the thresholds are stored in the key HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\ErrorThreshold) then IE does not show the friendly error page but the entire output from the webserver as it is. Which is why you might not get these friendly messages when woking with ASP.NET; given the verbose nature of error messages generated by them.

Friendly or not, as a web developer, IE’s substituted messages might come in the way of debugging your page. They can be disabled from Tools -> Internet Options -> Advanced:



I use the cluster of 3 radio-buttons (Underline Links) as a landmark to quickly locate the right checkbox in this crowd of checkboxes.

Tuesday, January 04, 2005

Automating ftp.exe sessions

ftp.exe is a command line tool that you use to connect to ftp servers. What is not very widely known about this tool is that it allows you to automate an ftp session by supplying a script which has the relevant ftp commands.

Let’s say we need to logon to the host – ftp.yourhost.com and download all the files in the dump directory on the server, we would first create a simple text file – say commands.txt which look something like this:


o ftp.yourhost.com
user username
pass password
cd dump
bin
prompt
mget *.*
close
quit


Then when using ftp.exe from command prompt, we can supply this text file as an argument to it:

ftp –s:commands.txt

that should do it!

Also see: Using FTP Batch Scripts

Monday, January 03, 2005

The customary Hello World!

I started blogging some 18 months ago. There are things about technology in general and computers in particular that I’d love to write about, but given the general nature of posts in the other blog, I decided to keep material of technical nature away from it. There were attempts, half-attempts, failed attempts at starting a technical blog; none materialized into a blog URL I could attest my name to.

My friend Anand – who incidentally was the one who initiated me to Blogging, was kind to extend me an offer to blog with him jointly. I made all but two posts and got entrenched in quagmire of things at work that kept me off from it. My sincerest apologies Anand!

While spending 8 days of vacation where I tried diligently avoiding computers, it became clear to me that I still fundamentally love computers (distance makes hearts grow fonder ;-)) – and more importantly I love sharing all the exciting things that I discover or do (with them, on them, to them ;-)). So here it is - another entry to the technical blogsphere. I hope, especially if you’ve read so far, that you’ll find the stuff I post in future, worth your time!

Now to address a question, which I prognosticate will be certainly asked of me tomorrow – why Blogger. Don’t you work for MS – and so aren’t you supposed to show your allegiance by using spaces.msn.com? Aren’t you being perfidious!?

space.msn.com are great – especially in the light of the fact that they are in v. 1.0. But I find them limiting in the regard that they don’t allow me to edit their HTML templates. I am a DHTML geek at heart and it hurts me to not tweak the defaults. The boxes you see on this blog (on your right), are built using inline jscript generated by an ASP.NET page, residing on anther server, which is querying amzon web-services and is fetching meta-data of my books and CDs in real-time – that kind of stuff just wouldn’t have been possible. Then there is an even more fundamental issue of aesthetics – I just can’t get myself to like either msn’s default font or any of the bundled image-background templates. That should settle it. It is not a downright repudiation of spaces.msn.com, but a conscious choice based on a set of reasons.