RooJSolutions http://roojs.com/index.php/View.html en http://roojs.com/Roojscom/templates/images/roojs_square_logo_150.png RSS: RooJSolutions - /index.php 150 150 Browser rending weirdness OSX and firefox 2011-01-26 00:00:00 http://roojs.com/index.php/View/228/Browser_rending_weirdness_OSX_and_firefox.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> Sometimes rendering bugs can be very annoying, IE has it's share of misbehaving, but usually firefox, chrome are consistant and never need much testing. However on one site, prior to going live someone testing on OSX kept saying that the menu bar was broken in Firefox.<div><br></div><div>Testing on Windows and Linux it looked fine. however on their browser, the horizontal line of buttons for the menu broke into two lines. It was not until I finally did remote control on her PC was I able to see what was going on.</div><div><br></div><div>Basically, on first load it rendered fine, but as soon as you went back to the page, the buttons would break. Inspecting it in firebug indicated that the second time it rendered the DOM tree was actually different to the HTML source.</div><div><br></div><div>The button code looks a bit like this</div><div><br></div><div><pre>&lt;a href="somurl"&gt;&lt;div class="btn"&gt;&lt;div class="btn-right"&gt;&lt;div class="btn-left"&gt;&lt;div&nbsp; &nbsp;class="btn-body"&gt;Title here&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/a&gt;</pre></div><div><br></div><div>The idea is that the div's provide the rounded button edges, and allow nice hover effects all in CSS.</div><div><br></div><div>however inspecting the reloaded page indicated the tree looked like</div><pre>&lt;a href="somurl"&gt;&lt;/a&gt; &lt;div class="btn"&gt;&lt;div class="btn-right"&gt;&lt;div class="btn-left"&gt;&lt;div &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; class="btn-body"&gt;Title here&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</pre><div>Where the a tag had broken away from the div, strangely only on one button.</div><div><br></div><div>It was only after I ran it through the w3 validator and &nbsp;got an error message about block elements inside and inline one, that I had the idea to rewrite that HTML to use span's, rather than div's. Along with adding display:block to all the CSS for the button elements.</div><div><br></div><div>The resulting HTML being</div><pre>&lt;a href="somurl"&gt;&lt;span class="btn"&gt;&lt;span class="btn-right"&gt;&lt;span class="btn-left"&gt;&lt;span&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;class="btn-body"&gt;Title here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</pre><div>And amazingly enough it rendered perfectly on all browser.. strange but true....</div> Leadership lessons, or are MBA courses any good? 2010-10-10 00:00:00 http://roojs.com/index.php/View/221/_Leadership_lessons_or_are_MBA_courses_any_good.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> <div>And now for something different.. I have a friend doing a course at HKU on Leadership, and with the feedback I'm getting, the course might just be missing the plot a bit.</div><div><br></div><div>From my side of the fence, ever since I gave up on my Masters, I have been generally dismissive of post-graduate courses at Universities. There was a serious sense of 'If you can't do it, teach it..' (or now if you really can't do it, blog about it..). My sense is that there is a reasonably large body of acedemia that suffers from the fact that they are kept on board as a result of quantity of research publications. They however they do not appear to understand the principles behind teaching (which teacher training wonderfully encapsulates). I wonder if tutors at university should be required to undertake a teacher training course, rather than slowly migrating from research into tutoring.</div><div><br></div><div>Along with all this, I wonder if the type of students these course attract are the exact opposite to 'self-learners', and are more used to a spoon feed education, especially here in asia.&nbsp;</div><div><br></div><div>Anyway back to the subject at hand. HKU was teaching a course based around a Harvard case study about a climb of mount Everest resulting in a number of deaths. The students are given the course material and are asked to produce a short piece explaining it and illustrating their ability to extract the leadership lessons that caused the failure.</div><div><br></div><div>This is where adult reading (not the picture kind) comes in handy. In Malcom Gladwell's book Outliers, a chapter is dedicated to an interesting study of plane crashes, and pilot assertiveness. If you read the book in the wrong way it appears to sensensionalize the idea that different countries and cultures have different levels of assertiveness which lead to greater crashes with pilot's of different countries. While this inference tends to lead to great press and I presume book sales. It is not really the message that come accross if you read it in detail.</div><div><br></div><div>In essense the book points out that individuals (and perhaps to some degree culturally based) are less assertive, in that they feel unable due to their role in society of workforce to assert their opinions. In the case of the pilot's it was the quiet mention that there might be a small issue with the weather. In the case of the climb it was more a case of Doctor's not asserting the seriousness of health issues, or the sherpa's inability to express that they where concern with various issues about the trip. All these would have likely been non-fatal if both communication had been clear and strong, and the subordinates had felt comfortable in the life threatening situations in overriding the leaders actions.</div><div><br></div><div>From the sense I got, the course was being taught on leadership, but unfortunatly learning that there are problems occuring with these type of situations has very little to do with leadership, and more to do with realizing that assertiveness training is an essential part of senior management, and more essential in situations which may be life threatening.&nbsp;</div><div><br></div><div>What is worse is that the course dynamic's of putting groups into teams and tasking them with these studies looks like it is a perfect example of why failure happens. Rather than using the course to entrench this positive assertiveness it basically leaves the groups to their own devices to produce a result and does not monitor their interaction trying to illustrate the individual's in the groups own abilility to assert their opinions. &nbsp;Would this type of couse not be better taught better with some kind of situation based role playing and instant feedback.&nbsp;</div> Company rename and RooJS sites now online 2010-08-25 00:00:00 http://roojs.com/index.php/View/216/Company_rename_and_RooJS_sites_now_online.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> After what seems like forever in design and migration, I've turned on the roojs.com and roojs.org domains, I'm slowly in the process phasing out my old company name - AK BK Consulting, which is now rooJSolutions<div><br></div><div>Quite a few of the key pages are missing content at present, but the blog and it's features are mostly moved over.</div><div><br></div><div>After I fill out all the missing content, I'll get back to blogging about how most of the Javascript tools and associated backend libraries all work together. Exciting times for a quality platform neutral Javascript Rich User Interface,&nbsp;guaranteed&nbsp;$(wtf) free...<br><div><br></div><div><br></div></div> nested trees in mysql - handy stored procedures. 2009-07-03 14:52:00 http://roojs.com/index.php/View/179/nested_trees_in_mysql__handy_stored_procedures.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> Storing tree data in Mysql databases, is relatively common, however, all the existing documentation about doing this, makes the whole process rather complex.<br /><br />If you google it, you will probably find the quite definitive answer at mysql.com, describing the classic  parent_id method, and the left/right numbering process. Both of these methods involve rather complex SQL to fetch and update the tree. <br /><br />In seeking a better solutions for a tree that was infrequently updated, but frequently queried, I thought I'd try seeing if I could write a few stored procedures to simplify the process.<br /><br />Our basic database structure looks like this:<br /><pre>CREATE TABLE _TREE_ (<br /> id int(11) NOT NULL auto_increment,<br /> parent_id int(11) NOT NULL DEFAULT 0,<br /> seqid int(11) NOT NULL DEFAULT 0,<br /> depth int(11) NOT NULL DEFAULT 0,<br /> leaf int(1) NOT NULL DEFAULT 0,<br /> name varchar(128) default '',<br /> fullpath TEXT default '',<br /> PRIMARY KEY (`id`),<br /> INDEX qlookup( parent_id , seqid , depth)<br />);<br /></pre>our key components are<br /><ul><li>id (the nodes id)<br /></li><li>parent_id (the nodes parent - pretty clasic)</li><li>name (the textual name of the node)</li><li>seqid - the generated order item for the whole tree</li><li>depth - how deep the node is (usefull for indenting)</li><li>leaf - is it a leaf node (eg. has no children) - usefull for icons</li></ul>The trick of the stored procedures is to correctly generate the seqid, this consists of two parts, the top level wrapper and the recursive prodedure to update the table.<br /><br /><br /><pre><br />DROP PROCEDURE IF EXISTS _TREE__resequence;<br /><br />DELIMITER $$<br />CREATE PROCEDURE _TREE__resequence(i_sep VARCHAR(4)) DETERMINISTIC<br /> BEGIN<br /> DECLARE v_p, v_d, v_s INT(11);<br /> DECLARE v_fp TEXT;<br /> SET v_fp = '';<br /> SET v_p =0;<br /> SET v_d =0;<br /> SET v_s =0;<br /> SET max_sp_recursion_depth=255;<br /> CALL _TREE__resequence_sub(v_p, v_d, v_fp, i_sep, v_s);<br /> <br /> <br /> END $$<br />DELIMITER ;<br /><br /> <br /><br /><br /><br />DROP PROCEDURE IF EXISTS _TREE__resequence_sub;<br /><br />DELIMITER $$<br />CREATE PROCEDURE _TREE__resequence_sub(<br /> i_parent INT(11),<br /> i_depth INT(11),<br /> i_fullpath TEXT,<br /> i_sep VARCHAR(4),<br /> INOUT i_seqid INT(11)<br /> ) DETERMINISTIC<br /> BEGIN<br /> DECLARE v_nid, v_ex_seqid INT(11);<br /> DECLARE v_name VARCHAR(128);<br /> DECLARE v_leaf INT(1);<br /> DECLARE v_fullpath TEXT;<br /> DECLARE done INT DEFAULT 0;<br /><br /> DECLARE qry CURSOR FOR SELECT id, seqid, name FROM _TREE_ <br /> WHERE parent_id = i_parent ORDER BY seqid;<br /> DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;<br /> OPEN qry;<br /> <br /> REPEAT<br /> FETCH qry INTO v_nid, v_ex_seqid, v_name;<br /> <br /> IF NOT done THEN<br /> IF v_ex_seqid != i_seqid THEN <br /> UPDATE _TREE_ SET seqid = i_seqid, depth=i_depth WHERE id=v_nid;<br /> END IF;<br /> IF i_depth &gt; 0 THEN <br /> SET v_fullpath = CONCAT(i_fullpath, i_sep, v_name);<br /> ELSE <br /> SET v_fullpath = v_name;<br /> END IF;<br /> SET v_leaf =0;<br /> SELECT COUNT(id) INTO v_leaf FROM _TREE_ where parent_id = v_nid;<br /> <br /> UPDATE _TREE_ SET <br /> fullpath = v_fullpath,<br /> leaf = IF (v_leaf &gt; 0, 0 , 1)<br /> WHERE id=v_nid;<br /> <br /> SET i_seqid = i_seqid +1;<br /> #// do the children..<br /> CALL _TREE__resequence_sub(v_nid, i_depth+1, v_fullpath, i_sep, i_seqid);<br /> END IF;<br /> UNTIL done END REPEAT;<br /> <br /> CLOSE qry;<br /> <br /> END $$<br />DELIMITER ;<br /><br /></pre>This does the hard work of iterating through the tree, and updating the sequence number, depth, leaf field and filling in the fullpath field<br /><br />Now our simple add node code just adds the node in the correct place, bumps the seqid along, so that you can then regenerate the tree.<br /><br /><br /><pre><br />DROP FUNCTION IF EXISTS _TREE__add_node;<br /><br />DELIMITER $$<br />CREATE FUNCTION _TREE__add_node(<br /> i_parent INT(11),<br /> i_after INT(11),<br /> i_name VARCHAR(128)<br /> ) RETURNS INT(11) DETERMINISTIC<br /> BEGIN<br /> <br /> DECLARE v_depth INT(11);<br /> DECLARE v_seqid INT(11);<br /> DECLARE v_ret INT(11);<br /> DECLARE v_tmp INT(11);<br /> <br /> SET v_depth = 0;<br /> SET v_seqid = 0;<br /> SET v_ret = 0;<br /> SET v_tmp = 0;<br /> <br /> <br /> #// grap parent depth.<br /> SELECT depth +1, seqid + 1 INTO v_depth, v_seqid FROM _TREE_ WHERE id= i_parent LIMIT 1;<br /> #// grab previous id..<br /> IF i_after &gt; 0 THEN <br /> SELECT seqid INTO v_tmp FROM _TREE_ WHERE id = i_after AND parent_id = i_parent LIMIT 1;<br /> IF v_tmp &gt; -1 THEN <br /> SET v_seqid = v_tmp+1;<br /> END IF;<br /> END IF;<br /> <br /> <br /> <br /> INSERT INTO _TREE_ SET <br /> depth = v_depth , <br /> seqid = v_seqid , <br /> parent_id = i_parent,<br /> name = i_name;<br /> <br /> <br /> SELECT LAST_INSERT_ID() INTO v_ret;<br /> <br /> #// fix the seqend id <br /> <br /> <br /> UPDATE _TREE_ SET seqid = seqid +1 WHERE seqid &gt;= v_seqid AND id != v_ret;<br /> <br /> RETURN v_ret;<br /> <br /> END $$<br />DELIMITER ;<br /><br /><br /></pre>You can now create a generic tree code by replacing my _TREE_ word with your table name:<br />eg.<br /><pre>#sed -e &quot;s/_TREE_/yourtable/g&quot; tree.js | mysql yourdb -f <br /></pre>Once all that is done the SQL to create tree nodes is very simple:<br /><br /><pre> delete from nametree; alter table nametree AUTO_INCREMENT =1 ;<br /> <br /> select nametree_add_node(0,0, 'one at top'); <br /> call nametree_resequence(':');<br /><br /> select nametree_add_node(1,0, 'two on one'); <br /> call nametree_resequence(':');<br /><br /> select nametree_add_node(1,0, 'three on one (first)'); <br /> call nametree_resequence(':');<br /> <br /> select nametree_add_node(1,2, 'four on one (last)'); <br /> call nametree_resequence(':');<br /> <br /> select nametree_add_node(0,1, 'five on top (last)');<br /> call nametree_resequence(':');<br /> <br /> select nametree_add_node(0,0, 'six is first'); <br /> call nametree_resequence(':');<br /><br /> SELECT * FROM nametree ORDER BY seqid;<br /><br /></pre>Gives you a nice little table<br /><pre><br />+----+-----------+-------+-------+------+----------------------+---------------------------------+<br />| id | parent_id | seqid | depth | leaf | name | fullpath |<br />+----+-----------+-------+-------+------+----------------------+---------------------------------+<br />| 6 | 0 | 0 | 0 | 1 | six is first | six is first | <br />| 1 | 0 | 1 | 0 | 0 | one at top | one at top | <br />| 3 | 1 | 2 | 1 | 1 | three on one (first) | one at top:three on one (first) | <br />| 2 | 1 | 3 | 1 | 1 | two on one | one at top:two on one | <br />| 4 | 1 | 4 | 1 | 1 | four on one (last) | one at top:four on one (last) | <br />| 5 | 0 | 5 | 0 | 1 | five on top (last) | five on top (last) | <br />+----+-----------+-------+-------+------+----------------------+---------------------------------+<br /><br /></pre>Enjoy <a href="http://www.akbkhome.com/svn/akpear/mysql_stored_procs/tree.js">tree.js</a> (I name my mysql stored procs as js, just so my editor works better with them)<br /><br /><br /> 2008 roundup - Recession kicking in? 2008-12-22 13:05:00 http://roojs.com/index.php/View/176/2008_roundup__Recession_kicking_in.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> <p>As my thumbs are twiddling waiting to see if projects start coming in next year, I thought I'd do a roundup of this years projects (open and closed). I was pondering if everyone else was seeing the effects of the recession, so I'd be interested to hear if you've also seen work slacking off.</p> <p>Let's hope next year we see some more life from the Sales and Marketing, as my current reliance on word of mouth, may not keep feeding my mouth at this rate.</p> <p>Anyway Merry Christmas and Happy new year to all.</p> <p>Read on for my Year of Projects</p> Where have all the good mice gone? 2005-12-04 10:30:15 http://roojs.com/index.php/View/110/Where_have_all_the_good_mice_gone.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> On almost every PC I use, I still have a nice reliable ball mouse, usually wireless, and every few months, it get's a small clean and new batteries. But one of them is now at least 4 years old, and is showing it's age a little, so off I went hunting for a replacement.<br /><br />To my horror, nobody is selling mice with balls these days (male mice are extinct!!! - female only versions available?). They only sell the optical crap. I've tried optical mouses quite a few times, you always get really bad feedback and the mouse behaviour is eratic at best of times. I usually end up bining them. But I'm still in shock today, that it's so increadibly difficult to buy them. So if you know of any good on-line resellers who sell real mice.. let me know..<br /><br />On a side line to this, I ended up with a dud piece of hardware from Targus<span style="text-decoration: line-through;"> (Note Mac unfriendly supplier!) -</span> their cute looking wireless presenter mouse, <span style="text-decoration: line-through;">has no drivers for OSX</span>, so looks like that one's going back to the shop.. (even linux had support for this!)<br /><span style="font-weight: bold;">[update]</span> I took the Wireless presenter mouse (Targus ARM01AP) back to the shop, after a bit of wiggling by the sales assistant, and pressing buttons on the USB bit, suddly it came to life on the OSX desktop, so after spending 2hours+ trying to find a solution last night, minutes after I plugged it in today, it worked out the box, without any extra software...agghhhh<br /><br /> Microsoft, always delivers... crap... 2005-11-10 09:26:06 http://roojs.com/index.php/View/109/Microsoft_always_delivers_crap.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> You know it is going to be one of those days when the lift to the office starts going up, even when you pushed the down button in the lobby..<br /><br />The morning started with a heated discussion about proposing a video conferencing system to one of our clients. I had come down to two options, a polycom plug and play (hopefully) system, or using 2 iMac's with iChat. But one of my collegues suggested that we recommend a Windows box, with MSN or similar. I was addement, I will never recommend windows for anything as complex as that, the implications for support, securing it (as it needed to have a fixed IP), and knowing that the thing would be guarenteed to fail a good proportion of the times the end user wanted to do a conference. While I sounded alot like a anti-microsoft zealot, I've been burnt far to many times in recommending and installing Windows to even consider it as a reliable option. And it get's difficult arguing with someone who actually think's that OS X has viruses ;)<br /><br />Anyway, that was just the start of the Microsoft crap for the day. Developers, Developers, Developers I hear them cry, well the day their software actually works as expected, I think they might actually attract enthusiastic developers. <br /><br />The task for the day was to fix some code I had written to export data to excel. I had practically copy and pasted some code from one project to this one, to implement this process. (I think I've blogged about the concept before), basically you render a HTML table with the data you want to export (a preview), then you use a javascript library, to read the table and generate a gnumeric xml file. This get's sent to the server, that then runs ssconvert to output a beautifully formated excel file, (doing all the colour, background, font effects etc.)<br /><br />Of course, this library had only be tested on Firefox (as most of the projects that it was used with where XUL based). So I had just said to the tester, does it work with IE?.. of course the answer came back .. NO!<br /><br />Given the fact that the javascript code in the application followed W3C DOM standards, and did not do anything that amazing, I guess I was a little supprised. So out came vmware, and my nice sandboxed Windows 98. In all it took over 4 hours to solve this, and I guess it's time I regard as a waste of my life (like most times I have to use windows ;)<br /><br /><ul><li>First indication of a problem was a little yellow triangle on the browser, pressing on it, told me error at line 0: download()<br />This it turned out (from what I remember), was that for some reason, IE did not like a href=&quot;javascript:download()&quot; as a link, and only when it was replaced with onclick, did it start working ok.<br /></li><li>Next up was some message about object does not support that operation on line 134 of xyz.html.<br />Well, looking at the HTML file, there was no javascript on that line!, it took me quite a while to realize, that the debugger can not handle included javascript files (and uses the line number from the original file) duh!!!, I had to copy all the javascript from the included files, into the main one just to debug it.<br /></li><li>That bug turned out to be something as simple as this<br /><pre>x = this.createXMLHttpRequest();<br />if (x != false) {</pre>Since x was an object, it could not be checked against a boolean (even though this works perfectly on Firefox)</li><li>After getting those bugs fixed, the next was a unknown method on an object. which was basically<br /><pre>document.getElementsByTagNameNS('*'',&quot;rows&quot;);</pre>used to grab sections of the Gnumeric template file, much to my amazement (well less so by now), I realized that IE doesnt actually implement DOM!!! (or DOM3 AFAIK) properly...<br /></li><li>At this point I gave up thinking that IE would ever work (or was worth supporting) for my nice exporter. So I started thinking just doing a HTML table to CSV importer, using pretty much the same concept. I however ended up spending a good half hour puzzling over a &quot;Can not download&quot; message, as soon as I added the Content-type header to the output. The kludge workaround for which is actually mentioned on the PHP manual comments.</li></ul>All in all not one of my better days....<br /> Mac-mini adventures 2005-06-05 23:58:18 http://roojs.com/index.php/View/91/Macmini_adventures.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> I spent a few hours this weekend setting up a new mac-Mini in the bedroom. In general, the whole experience was pretty smooth, and I have considerably more faith that this computer will not become a maintainence nightmare, like the house's last remaining Windows box. The mini scores a few points on linux, for plugging in camera's and setting up sound etc. (but I expect it looses sorely in ability to compile stuff, given the literny of problems I've seen on mailing lists over the last year.)<br /><br />One thing that did not impress me was Quicktime, while it cutely played movie trailers, It had quite a few problems with avi files.<br /><br />a) came up with a message about unreadable format, and redirected me to a page listing 3rd party add-ons (without specifying which one I might need)<br />b) refused to go fullscreen.. <br /><br />Given the overal quality of the rest of OSX, these where rather disappointing. A quick SMS to a friend indicated that VLC was a better bet for AVI's... - he did suggest MS's media player, but keeping anything from MS, as far away as possible from this box, is the general plan.. <br /><br />A few other things installed very easily <br /><ul><li>NeoOffice/J (Open office for osx)</li><li>Firefox - Safari is cute, but not quite as polished as firefox.</li></ul>The other bit that confused me totally was that it had no root account by default, you have to go through various steps to enable it..  - so now we have apt-get working, although what looks like a rather limited choice of applications..<br /><br />Now to get ssh working so I can do compile tests with some of the php libraries..<br />