October 31, 2009

Interesting case study on innovations in Indian context

http://online.wsj.com/article/SB125598988906795035.html

Coke Studio Songs

Just thought to share this interesting musical fusion that was being aired on some pakistani channel. I loved most of the songs. Here is a link with downloadable mp3s

http://www.koolmuzone.com/2009/08/coke-studio-episode-5-download-audios-videos/

October 12, 2009

Thought of the day...

Stolen from Ghai's fb post, but it was worth it:

"We don’t get a chance to do that many things, and every one should be really excellent. Because this is our life. Life is brief, and then you die, you know? And we’ve all chosen to do this with our lives. So it better be damn good. It better be worth it." - Steve Jobs

Regex Pattern for Validating Email addresses

Interesting post here talks about how complex RFC 822 is, that defines a valid email address. But thankfully the guy found a simpler pattern from msdn and modified it to put more restriction on the regex; here it goes:-

"^([\w]+)(([-\.][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"

However this pattern fails to approve email ids like "mygroup+subscribe@mygroups.com" which is a common pattern used by listserv email lists. There are few more cases when email bots send you emails containing reply to addresses like "mygroup+confirm-23EWEJEW233@mygroups.com" where you reply and using the session id "23EWEJEW233", your a/c is activated or something. Writely (now Google docs) uses a similar pattern allowing you to upload documents through emails; their email ids are of type "xyz+pqr-12345678901234567890-SDWEPO23@prod.writely.com"

To verify if a value is passing through this perl regex filter, i used the following command:
echo [candidate_value]|grep -P [pattern]
and then checking "echo $?", if its 0, the pattern matches, else it failed. Actually if the pattern matches, you will see the [candidate_value] printed as well.

Turns out adding support for '+' as additional symbol was the only thing required. The modified regex looks exactly the same, except one character "+" added in the sequence.

"^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
For ex:
  1. echo "abc.pp@fjdsf.sdsd.dsdsds.com"|grep -P "^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    passes the regex
  2. echo   "abc.@fjdsf.sdsd.dsdsds.com"|grep -P "^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    fails the regex
  3. echo "xyz+pqr-12345678901234567890-SDWEPO23@prod.writely.com"|grep -P "^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    passes the regex

October 03, 2009

selecting from a combobox, populated using JsonStore in extjs

gotcha.. it took me quite sometime in figuring this out. I was populating the combobox from a JsonStore and then wanted to select one of the values by default.

The documentation for
setValue(String v) : Ext.form.Field 
says:
Sets the specified value into the field. If the value finds a match, 
the corresponding record text will be displayed in the field. If the 
value does not match the data value of an existing item, and the 
valueNotFoundText config option is defined, it will be displayed as 
the default field text. Otherwise the field will be blank (although 
the value will still be set).
Parameters:

    * value : String
      The value to match

However it doesn't say what does it mean by "value into the field". Atleast i got confused and was trying with all sorts of permutation/combination (this is what happens when you get stuck with something and don't know a way out). It did mean the value that you want to submit along with the form. So just in case some poor soul is stuck like me, here is the code on how to do it.
var jsonStore = new Ext.data.JsonStore({
        storeId: 'my-json-store',
        // store configs
        autoDestroy: true,
        autoLoad: true,
        proxy: new Ext.data.HttpProxy({
            url: /relative_backend_url, 
            method: 'GET'
        }),
        // reader configs
        root: 'response',
        idProperty: 'elemId',
        fields: [ 'name', 'elemId', 'description' ]
    });

jsonStore.on('load', function(store, data){
    Ext.each(data, function (elem){
            if(elem['name'] == some_value_to_compare) {
                var combo = Ext.getCmp('my-json-combo');
                combo.setValue(elem['elemId']);
            }
 });
     // or if you already know the value of elemId, lets call it xValue for which you 
     // want to show the element, go for combo.setValue(xValue)
});

JSON response from the backend looks something like this:
{
    "response": [{
        "description": "Some long description",
        "name": "Name of the element",
        "elemId": "af02a9d6-a11c-11de-bcd5-b2e876978f0a"
    }],
    "success": true
}