Older blog entries for bkode (starting at number 24)

8 Jul 2007 (updated 21 Aug 2007 at 14:12 UTC) »

Introducing toXmlString : Javascript XML DOM to String Conversion

I was surprised to find no function to convert a javascript xml dom object to a string. I did find an upcoming feature added in Javascript 1.6 by the cool folks at Mozilla, but it really did not cater to xml dom objects already created /accessable by javascript.

I've seen PHP's PEAR ,and XML_Parser classes and often like to take part of the xml to resend/reuse later in my application. So since I could'nt find one , I wrote one 8 ) !

toXmlString(xmlObj) : string

* @author Bhasker V Kode
* @name toXmlString
* @description Functional Style Method to Generate XML String from any xml DOMobject .
* @param s (String ) [optional for usage]
* @language Javascript
* @date 25th May ,2007

  1. function toXmlString(xy,s){
  2. var str = (s==undefined)?'' : s;
  3. if(xy.nodeValue==undefined){
  4. //ur a big moma
  5. var multiStr=[],temp='';
  6. for(var i=0;i
  7. // each repeasted node
  8. if(xy.childNodes[i].nodeName.toString().indexOf('#')
  9. var nodeNameStart ='
  10. var nodeNameEnd ='';
  11. var attsStr=' ',atts = xy.childNodes[i].attributes;
  12. if(atts!=undefined){
  13. for(var j=0;j
  14. attsStr+=atts[j].nodeName+'="'+ atts[j].firstChild.nodeValue+'"';
  15. }
  16. }
  17. temp = nodeNameStart + ((attsStr==' ')?'':attsStr ) +'>'+toXmlString(xy.childNodes[i],str) + nodeNameEnd;
  18. multiStr.push(temp);
  19. str = temp;
  20. }else{
  21. //node Value
  22. str = toXmlString(xy.childNodes[i],str);
  23. multiStr.push(str);
  24. }
  25. }
  26. //end of for loop,time to untangle our results in order of appearance
  27. str = multiStr.join('');
  28. }else{
  29. return xy.nodeValue;
  30. }
  31. return str;
  32. }


var str = toXmlString(xmlDomObj) ;

Demo - http://bhaskervk.com/libraries/reusable/demos/xml.php



Let us assume that you dynamically add an event to an object . Now with Reusable.DeferredEvent , it throws a similiar api , gives you an option to specify your existing addEvent code -.Popular version of which are :
So basically what i have is a plug'n play support for handling idempotent events , using your existing javascript toolkits corresponding dynamic event handling capabilities . In the demo page , I have shown how to integrate with these frameworks by uncommenting the suitable line of code as needed.

Which means for configure listenEvent event for every listenTill seconds , for any listenObj object .

In the demos , you will find two scenarios :
  • Only unique button click's on Button1 in the range of 1 seconds will be recognised !
  • Only unique mouseouts on Button2 in the range of 3 second will be be recognised.

//@param name of instance
//instantName = new Reusable.IdempotentEvent(instantName);
// Step 1 : Instantiation
responsive = new Reusable.IdempotentEvent('responsive');

//@param listenObj - DOM listenTillelement or element id
//@param listenEvent string - Event name (as per your toolkit nomenclature )
//@param listenTill int / string - how frequency to accept event triggers
//@param callBack string - What function to callback eventually

// Step 2 : Exeuction
//responsive.register( listenObj , listenEvent , listenTill , callBack );
responsive.register( btn1, 'click' , btn1.getAttribute('onclickwhen'), 'clicked' );
responsive.register( btn1, 'mouseout' , 1000, 'hovered' );

Demo and Code here .

Technorati Tags: javascript, events, idempotent, code, bhasker, kode, bosky101,

The Returnable Project - Whats your return type ?...Enabling in-text content into your blog

Syndicated 2007-02-15 03:55:00 (Updated 2007-02-21 08:10:01) from Bosky says........the web log of Bhasker V K

8 Jul 2007 (updated 21 Aug 2007 at 14:12 UTC) »

A Profile of TechEnclave

So, I've also always wondered if the portal a handful of '20-something year old' geeks and myself have built over the years totally in our spare time - would figure as being part of the Indian web innovation revolution .

It's called TechEnclave , famed for its forums ... ( http://www.techenclave.com/forums ) Being a moderator for the forum , we're all excited that the member base that Team TechEnclave have been really building the community from 2002-03 onwards with experience gained from a temporary hosted forums ,to other experiements through '04, - 05 and finally fixed on the TechEnclave brand ,and have stuck to it ever since the end of 2005 .

The reason why i 'm talking about it now - is also to highlight the transition we've seen with the web 2.0 revolution hitting the indian plains . Sure , we did implement ajax based forum search options before it became cool , and we do have some forum regulars like a calendar that the 10k displaying birthdays ,user meets ,and so on . We've even had our TE user meets where we get to interact with the members dating to early 2005 . And with over 25- 30 of them across the country over the years - its not really tough to see why the unconferencing theme dint take too long to pick up in India. Today TechEnclave has over 25 forum sections covering hardware overclocking to gaming , portable devices and Tech News from across the world .If TechEnclave as become what it is today , it has been off the strength ,quality and relevence of its Forums - be it for the tech noobie , geek gurus or the persistent troubleshooter .

Some other statistics TechEnclave as of Nov 3 , 2006
Members: 13,500 +
Threads: 27,229
Posts: 292,544,
Most users ever online was 1,363, 28 Nov 05 2005 at 01:18 PM.

So ...coming back to how TechEnclave fits in as a interesting collage of user-feedback inspired product innovation built inhouse...

1 ) TE Spy
an inhouse clone of digg spy ,developed in ajaxian ishtyle , and shows in real time when new posts made at techenclave ... currently for premium members only . But the amount of content we throughout the day ensure that the TE spy functions like a charm . If you are registering at TechEnclave , we'll be happy to upgrade you to a premium membership .Just let me know your user id ,and then you can check out TE Spy for yourself .

2 ) TechEnclave Addons & Initiatives
The TechEnclave ToolBar , A nifty little addon for Firefox helps our users search and naviagate across the site better . We also have an exclusive download manager apart from the recently added hardware benchmarking software located at http://www.techenclave.com/forums/superprime/ as well as numerous other nifty utilities like bookmarklets , feed aggregator widgets ,newletters , rss feeds , and so on .

3 ) TE Rig Gallery
TERig was an idea that we at techenclave had for a long time. We wanted to give , the tech enthusiast a medium to showcase your rig to the world. From our feedback on the forums ,we understood that the true potential of your rig can only be shown when your rig details are presented in a well formatted manner and with the all important pictures of your rig. So our admins Safin and QuickFire , went about hacking just that . Not only will you be able to put your rig specs in a well formatted manner, but also will be able to view where your rig stands vis-a-vis other's. Till date ,we are the first forum to have such a versatile system ...check it out at http://www.techenclave.com/forums/RigGallery.html
transcending the role of a forum .

4 ) TE iTrader ( Market )
A custom built environment that provides a better showcase of the product that users put up for sale .

5 ) TE Price Guide
Based on feedback over the years ,we even felt the need for a comprehensive and updated price guide for hardware ,whatever be the city you are in india. So welcome another custom built app . the TE Price Guide located at http://www.techenclave.com/forums/hardware-prices.html which has now attained a sort of lengendary status of sorts over at the "Build Your Own Rig" followers in India . We even have a seperate Market Section where users can swap their new and old stuff .This initiative has gathered a lot of traction for genuine buyers and sellers especially ,for reaching users in the the non metros .

The TE Family
Apart from helping troubleshooting across 20 odd forum sections ,being part of the Techenclave , has helped bridge distance for the indian techie and transcend geekdom !
TechEnclave 's depth of quality in its reviews and experienced members helped it become a source to present demos at hardware branding and launch expos . Infact ,name any piece of hardware or software ,and you can be sure that theres someone from techenclave whos' got it first or swears by their favourite utility . Also of note is the sister forum that we've created called FunEnclave over at www.funenclave.com

The people behind TechEnclave ( http://www.techenclave.com/forums/staff.html ) are dedicated enthusiasts who came together because of their expertise and being identified as uber geeks and experts by their peers ,combined with a blend of effective management , marketing and creative abilities - to make things happen . We take pride in building one of India's Biggest Technology Forums from scratch without any commercial backing or investment by putting back all ad generate revenue back into getting better servers , bandwidth and so on .( You can see a brief history and evolution of techenclave over at http://www.techenclave.com/forums/techenclave-history-and-evolution-720.html ) And we hope to keep the quality and members right up there ,to take TechEnclave to greater heights ! 8 )

If TechEnclave does not fit into the realm of indian innovations - we will understand . But If you think that this community has evolved ,then do let us know ,and drop in at the forums and find out for yourself . See you there...

Keep Clicking,
Bhasker V Kode ,

PS : If you do want to explore advertising options ,feel free to go through the page at http://www.techenclave.com/forums/advertisewithus.html .

This is a post meant to act as Profile of TechEnclave . So while it very well would be in the public domain,i'd appreciate the linkback .

Technorati Tags: techenclave, bosky101, india, tech, geeks, forums, portal

The Returnable Project - Whats your return type ?...Enabling in-text content into your blog

Syndicated 2007-01-29 05:30:00 (Updated 2007-02-02 04:39:58) from Bosky says........the web log of Bhasker V K

8 Jul 2007 (updated 21 Aug 2007 at 14:12 UTC) »

Good to be back in Chennai

Me in chennai for a few days...after a long break ,and the weekends been gr8 so far.

Attended the alumni meet and committed to helping out in the alumni site setting up as well .those guys are really stepping on the networking ,and the urgency is more so to gear up fto celebrate SVCE's 25th year of graduation to be in 2010 .

Showed off my new black dual-core 120 gb sata with dvd writer hp laptop to everyone at home here . its damn mobile and very sleek . am absolutely in love with it,and still think it was a better option that going for a mac ! (incidenly we just got another acbook ,bring the total to two now in our -10 odd strong develoepr & testing army at tutorvista's only office ( stpi ,electronic city,bangalore )

good news continues with my bro getting into Georgia tech, TAMU ,and Duke for his industrial engineering as well . Hes still waiting for stanford ,yale and darthmouth . All the best Bhargav !

Wrote a nice piece that i think a lot of my juniors at SVCE could use , and i think spend some time thinking about ,especially if your in a CS / IT department and contemplating a career in web based development.

Speaking of TE, the member base at TechEnclave has passed 13,500 geeks and looking good , We just completed a deal with Reliance Webworld for a banner display,and completed a small announcement deal with Rashmi Bansal - Editor, Jammag as well .

on the work front ,tutorvista just celebrated its first year anniversay at HINT, in bangalore central .a disc /pub that we booked all for ourselves and EVERYthing on the house !!! : ) . that was a freaking awesome party ! Getting into some new projects in office as well with the newsletter, feed syndication,apart from the now deployed googlish Calendar utility released live to our 2500+ paid customers. We're expanding on the hiring front as well - tutors,operations , developers ... conducted my first phone interview myself ;) ,plus its exciting that after our secodn round of funding of 10mln ,we're now going from the incubated unit at stpi to a full fledged 33 story byulding of our in the heart of Bangalore's corporate zone off the airport road.

went for a nice long move - salame ishq ,entertaining , india Vs west indies cricket match happening live here in chennai . and so is the cult fest saarang here at iit-madras campus.met up with my old buddies from school , called a few more . had a nice day out with my family and nrought my gf to my house for the first time to my mom and grand mom. spoke to my dad who's sailing after a long time . Madhu will continue to be in Biocon,bangalore till she leaves for her MS. And i think its time i thought about my plans for the near and distant future as well -education wise, health wise , personal life, wise in all respects ... Salsa classes have been doing me good as well....

Cheers to a rocking start to 2007 ....life is beautiful .... 8 )

Keep Clicking,
Bhasker V Kode

Technorati Tags: india, chennai, bangalore, tutorvista, techenclave, bhasker, kode, bosky101, svce, life

The Returnable Project - Whats your return type ?...Enabling in-text content into your blog

Syndicated 2007-01-27 17:59:00 (Updated 2007-01-27 18:00:22) from Bosky says........the web log of Bhasker V K

8 Jul 2007 (updated 21 Aug 2007 at 14:12 UTC) »

Live Blogging a Javascript hackers first dive into Erlang

There comes a time in every developers life ,when you want to find out for himself ,what ,how and why the hell people swear by their languages .Especially when its not one that youve ever worked with . For me ,it started off with Paul Graham godfathering Lisp . No i havnt Lisp/scheme land yet .But i have instead gone into another one , inspired by the one paradigm that has got everyone from languages all over the place going gaga.

Functional Programming . And the language im talking about ........is Erlang.

Now being a javascript 'n DOM hacker myself, Ive always wanted to take on any claim that other framework combinations (read django,ruby on rails , pylon ,and the rest) have to well...claim as far as im concerned by quoting improved performance , rapid prototyping , and ease .

Do i think a well informed programmer javascript /DOM hacker is any less equipped to implement ANYTHING that a ruby on rails coder can ?

my answer is No. not yet anyway . Either that or i havent seen anything so exclusive to a ruby on rails that cannot be implemented otherwise .( Let the rants begin ..he he ... 8 P )

Coming back to Erlang .What im going to attempt to do is :

  • show the erlang example from the nice folks at erlang.org
  • rewrite the same in javascript ,
  • rewrite the same in javascript ,attempting a FP style.
erlang code for factorial

fac(1) ->
fac(N) ->
N * fac(N - 1).

a modest javascript equivalent of erlang code
* @author Bhasker V Kode
* @description a modest javascript equivalend of the erlang factorial example.
* @date Jan3 ,2007
function fac1(number){
var total = 1;
for(var N=0 ; N

javascript equivalent of erlang code with a modest Functional Programming Style
* @author Bhasker V Kode
* @description a modest javascript equivalend of the erlang factorial example.
* @note : oh erlang gods ! please let me know if this could have been more erlangish.
* @date Jan3 ,2007
function fac(total,number){
if(number >1 ){
return total;


Now as the nice documentation said - what ive atttempted to do with this erlang program OR rather the highlight of functional style would be the limited need/scope of variables and instead the fact that the argument to a function can be the result of another function. Pretty wicked huh!

Now i know ive gone wrong somewhere . So if any erlanger / FP guru happened to see this ,they might know ?
  • if you cud make the js above with just one argument ?
  • if you should rather keep increasing the arguments being sent instead of increasing the sum
Lets move on to a more cryptic example of embedding functional style of programming into predominantly OOPs based javascript.

XmlWriter : a Javascritpt Class that uses minimalistic Functional Programming Styles

* @author Bhasker V Kode
* @date Jan 4 ,2006
* @description Uused to create xml structures as a string ,and get a string form at any node level ,easily add nodes ,attributes and values.

function XmlWriter(root){
this.totalNodes=new Number(0) ;

this.addNode = function(parent,nodeName,value){
this.totalNodes++ ;
var len = this.index.length - 1 ;
this.index[this.totalNodes] = new Object() ;
this.index[this.totalNodes][nodeName] = new Node(nodeName,this.getDepth(parent)+1,value,this.totalNodes) ;
this.index[this.totalNodes][nodeName] = new Node(nodeName,this.getDepth(parent)+1,this.totalNodes) ;
this.index[this.getIndex(parent)][parent].array.push(nodeName) ;

this.getRoot = function(){
return this.root ;

this.getNode = function(parent){
var len = this.index.length ;
return this.index[len - 1 ][parent] ;
this.getIndexElem = function(id,assoc){
if(id id=0 ;
return this.index[id][assoc] ;

this.printXML = function (node,str){
var str = new String('') ;
var tempArrElem = this.getIndexElem(this.tempIndex,node) , tempArr = tempArrElem.array ;
// this.jsAlert('going to call start tag for this.index['+this.tempIndex +'having name '+ tempArrElem.name+' and attribs '+ tempArrElem.attribs) ;
str+= this.startTag(node,tempArrElem.attribs) + tempArrElem.value ;

if(tempArr.length > 0 ){
for(var j=0 ; j //this.jsAlert('j='+j+',node :'+node+',this.tempIdex is '+this.tempIndex+'so tempArr is : this.index['+this.tempIndex+']['+node+'] = '+tempArr[j]) ;
this.tempIndex++ ;
// this.jsAlert('going to call printXML with node:'+tempArr[j]+',cuurent str is '+str) ;
str = this.printXML(tempArr[j],str) ;
// this.jsAlert('done with filled'+ node+'this.printed = ' + str) ;
str+= this.endTag(node) ;
return str ;
// this.jsAlert('done with empty'+ node+'this.printed = ' + str + this.endTag(node)) ;
str+= this.endTag(node) ;
return str ;



this.startTag = function(nodeName,attribs){
if(attribs==undefined){var attribs='' ; }
return ' '
this.endTag = function(nodeName){
return ' '

this.getDepth = function(nodeName){
for(var i =0 ; i for(var node in this.index[i]){
if( this.index[i][node].name==nodeName){
return this.index[i][node].depth ;

this.getIndex = function(nodeName){
var tempRet=0 ;
for(var i =0 ; i for(var node in this.index[i]){
if( this.index[i][node].name==nodeName){
tempRet = i ;
return tempRet ;

this.getXML = function(nodeName){
var nodeName = this.root ;
this.tempIndex=0 ;
return(this.printXML(nodeName)) ;
//adding root node
this.printed = new String() ;
this.index = new Array() ;
this.index[0] = new Object() ;
this.index[0][root] = new Node(root,0) ;
this.root = root ;


function Node(nodeName,depth,params,index){
this.array = new Array() ;
this.depth = depth ;
this.name = nodeName ;
this.index = index ;
if(params.value!=undefined){this.value=new String(params.value) ; }else{this.value=new String('') ; }
this.attribs=new String(' '+params.attribs) ;
this.value=new String('') ;
this.attribs=new String('') ;
return this ;

        var x = new XmlWriter('channels');
x.addNode('shows','show',{attribs:'date="05:01:2006" title="waynes world"',value:'21:00:00'});
x.addNode('shows','show',{attribs:'date="05:01:2006" title="cnn news"',value:'22:00:00'});
alert ( x.getXML('channels') );
As you can see with the above example . This class can generate a consistent xml file from any particular node, handle attributes (although i need to add better error checking / escape character into the system) .The interesting part comes in the printXML function where ive implemented a minimalistic function style of programming where . Now ofcourse ive put in plenty of Object oriented javascript as evident with the use of the this keyword generously . But what ive also done is make the final printing of xml darn simple !

In essence my recursive function printXML does the following:

(XmlWriter.printXML in pseudoCode)

  1. write the start tag of this node .
  2. add the attributes
  3. if this node has a child node ? goto 1 , else goto 4
  4. write the end tag of this node

So now ....im convinced that javascript has done a good job in imbibing some tips from the erlang examples. The beauty of javascript is that since its pretty native as far as the browser is concerned ,you can write anything or implement any paradigm that isnt native to the langauge yourself . But as many wise ones have echoed over the years that the very fact that you code in a functional programming language style, could change the way you think about programming .

Cheers to my erlang and like my first experiment with functional programming ,the javascript hacker in me is up to the challenge as well 8 ) .

Keep Clicking,
Bhasker V Kode

PS : special thanks to Ricky Clarkson for hinting me to check the code again . i was coding the sum of N numbers although i started out wanting to do the factorial of N numbers ! d 'oH ! : P .... thanks ! I hate bloggers code formatting as well !

Technorati Tags: javascript, erlang, functional, programming, FP, bhasker, kode, bosky101, factorial, programming

The Returnable Project - Whats your return type ?...Enabling in-text content into your blog

Syndicated 2007-01-03 14:30:00 (Updated 2007-01-04 11:38:50) from Bosky says........the web log of Bhasker V K

8 Jul 2007 (updated 21 Aug 2007 at 14:12 UTC) »

Presenting - Proto.in Widget

I hacked this scriptlet today for proto.in ...

To add the following widget into your blog or webpage ,simply add the following line scriptlet into your html code , to get your own proto.in widget...

<script id="protoWidget" src="http://proto.in/protoWidget/protoWidget.js" type="text/javascript" language="'javascript"></script>

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!