<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">

<channel>
	<title>Javascript Kata</title>
	
	<link>http://www.javascriptkata.com</link>
	<description>Advanced katas for javascripters</description>
	<pubDate>Tue, 12 May 2009 15:52:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/javascriptkata/no_echo_chamber" type="application/rss+xml" /><item>
		<title>Easy loop for every element of an array</title>
		<link>http://www.javascriptkata.com/2009/05/12/easy-loop-for-every-element-of-an-array/</link>
		<comments>http://www.javascriptkata.com/2009/05/12/easy-loop-for-every-element-of-an-array/#comments</comments>
		<pubDate>Tue, 12 May 2009 15:24:21 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[white belt]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=85</guid>
		<description><![CDATA[There's something bugging me with javascript <em>for</em> loop : the extra work to loop though all elements of an array. Suppose I want to <em>alert</em> each element of an array, there are three ways of doing it.]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s something bugging me with javascript <em>for</em> loop : the extra work to loop though all elements of an array. Suppose I want to <em>alert</em> each element of an array, there are three ways of doing it.</p>
<p>First, you loop with an index and assign the element to a variable.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> items = <span class="br0">&#91;</span><span class="st0">&quot;a&quot;</span>, <span class="st0">&quot;b&quot;</span>, <span class="st0">&quot;c&quot;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i = <span class="nu0">0</span>; i &lt; items.<span class="me1">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> <span class="kw1">item</span> = items<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">item</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>You always have to have that extra assignment at the beginning of the loop.</p>
<p>Second, you loop with a <em>for each</em>.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> items = <span class="br0">&#91;</span><span class="st0">&quot;a&quot;</span>, <span class="st0">&quot;b&quot;</span>, <span class="st0">&quot;c&quot;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> items<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> <span class="kw1">item</span> = items<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">item</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>In javascript, the <em>for each</em> <strong>loops though the index</strong> of the array instead of looping though the elements, like in most other languages. Thus, you also have to make the extra assignment at the beginning of the loop.</p>
<p><strong>The easiest way</strong> of doing it is the third one.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> items = <span class="br0">&#91;</span><span class="st0">&quot;a&quot;</span>, <span class="st0">&quot;b&quot;</span>, <span class="st0">&quot;c&quot;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i = <span class="nu0">0</span>, <span class="kw1">item</span>; <span class="kw1">item</span> = items<span class="br0">&#91;</span>i<span class="br0">&#93;</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">item</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><strong>How does it work?</strong> First it uses multi-assignment on one line. In javascript, you could write <em>var i = 0, j = 1;</em> and it would create two variables, <em>i</em> and <em>j</em>.</p>
<p>The second part of the <em>for</em> is confusing : it assigns the item but it never check if <em>i</em> it is out of bounds of the array (using <em>i < items.length</em>). It works because when javascript tries to assign an item after the end of the array (in our case <em>items[3]</em>), it returns <em>null</em> which is considered by javascript as <em>false</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2009/05/12/easy-loop-for-every-element-of-an-array/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Be ahead of the trend, try CouchDB</title>
		<link>http://www.javascriptkata.com/2009/01/12/be-ahead-of-the-trend-try-couchdb/</link>
		<comments>http://www.javascriptkata.com/2009/01/12/be-ahead-of-the-trend-try-couchdb/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 15:49:28 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[couchdb]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=79</guid>
		<description><![CDATA[I always loved and hated databases. When I was a younger programmer, I asked to switch to DB administrator and, thank God, they didn&#8217;t agree to let me mutate in a DBA. I ended up fired like 80% of the company (except the DBA). In fact, I wanted to be DBA because I thought I [...]]]></description>
			<content:encoded><![CDATA[<p>I always loved and hated databases. When I was a younger programmer, I asked to switch to DB administrator and, thank God, they didn&#8217;t agree to let me mutate in a DBA. I ended up fired like 80% of the company (except the DBA). In fact, I wanted to be DBA because I thought I knew how to work with a DB better than them. The rest of my life proved me wrong. Nobody knows what they&#8217;re doing because relational databases are a mess.</p>
<p>Then came the non-relational database. <a href="http://aws.amazon.com/simpledb/" target="_blank">Amazon&#8217;s SimpleDB</a> was the first NRDBMS (as opposed to RDBMS) that got a public attention. When I read the specs, I really thought it was cool but I wondered &#8220;Is it scalable?&#8221;. Then I remembered that <strong>there is no such thing as a scalable database</strong>. Databases need to be smashed and hurt in order to be as scalable as we want them to. I wanted to give it a try but I wasn&#8217;t ready to <a href="http://aws.amazon.com/simpledb/#pricing" target="_blank">pay</a> for it yet.</p>
<p>Working with xmpp/jabber, I saw <a href="http://metajack.im/2008/11/14/relax-databases-are-fun-again/" target="_blank">a post by the well-known metajack</a> (his blog is mainly about xmpp) about couchdb and I knew the time as come for me to be different. I had to try it so I opened a terminal and wrote <em>sudo apt-get install couchdb</em>. This was the beginning of a great adventure for me&#8230;</p>
<p>What&#8217;s the link between CouchDB and Javascript? <strong>CouchDB is completly JSON</strong>. You can write <a href="http://jchris.mfdz.com/posts/129" target="_blank">an application that is completly JSON/Ajax</a> without a single line of PHP/Ruby/Python/whatever.</p>
<p>I&#8217;m currently writing a simple app for CouchDB and this is the first of some posts about writing an app with CouchDB. I currently use version 0.8.0 and I ran through a lot of problems and I wish these posts will <strong>help you succeeding in building an application supported by CouchDB without all the hassle I went through</strong>.</p>
<p>Because my main project is <a href="http://www.timmyontime.com/" target="_self">TimmyOnTime</a> (and don&#8217;t forget to check out our new blog <a href="http://behindtheclock.timmyontime.com/" target="_blank">behind the clock</a>), I will work partial-time on this project so it might not go as fast as I (and you) want. But don&#8217;t despair, you will still be ahead of the trend when NRBDMS will go mainstream.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2009/01/12/be-ahead-of-the-trend-try-couchdb/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cleanest way of executing javascript code on page load</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/</link>
		<comments>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 15:01:08 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[white belt]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69</guid>
		<description><![CDATA[Everytime that I work on a new project, I'm always unsure about which way to execute javascript on page load.]]></description>
			<content:encoded><![CDATA[<p>Everytime that I work on a new project, I&#8217;m always unsure about which way to execute javascript on page load. These are the different techniques :</p>
<h3>Your old buddy body.onload()</h3>
<p>The safest way to execute javascript when a page loads is to use the body.onLoad method.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;body onload=&quot;doSomething();&quot;&gt;&lt;/body&gt;</div>
</li>
</ol>
</div>
<h3>The document.ready function with jquery</h3>
<p>This technique requires jquery and is similar to the <strong>body.onLoad technique</strong> (see above).</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;body&gt;&lt;script&gt;$(document).ready()&lt;/script&gt;&lt;/body&gt;</div>
</li>
</ol>
</div>
<p>The problem is that I don&#8217;t like that the javascript code is too close to the HTML code. There&#8217;s really something that I don&#8217;t like.</p>
<h3>The #ID.ready</h3>
<p><strong>DO NOT USE!</strong> It doesn&#8217;t work. At first, I tought that this technique worked but in fact, even if the element corresponding to the ID doesn&#8217;t exists, the function is called. To understand it better, I&#8217;ll give you an example. Suppose that I want to load a user list with ajax after the page load and that list correspond to <strong>ul#users</strong>, I&#8217;d write the following code</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&quot;ul#users&quot;</span><span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; loadUsersWithAjax<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Unfortunately, it doesn&#8217;t work.</p>
<h3>The document.ready + #ID.each</h3>
<p>After the failure of the #ID.ready technique (see above), I tried a similar thing that is working but ugly looking. Suppose I want to do the same as above, I&#8217;d write this :</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span><span class="st0">&quot;ul#users&quot;</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; loadUsersWithAjax<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>That way, it would execute the loadUsersWithAjax() method for each <strong>ul#users</strong> and because element IDs are unique to a page, the method would be called only once. It looks bad but it&#8217;s the &#8220;prettiest&#8221; way I found of executing javascript code on page load.</p>
<p>Now, I want to know <strong>what would you suggest? Which technique is your?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavascriptKata now ad free</title>
		<link>http://www.javascriptkata.com/2008/11/28/javascriptkata-now-ad-free/</link>
		<comments>http://www.javascriptkata.com/2008/11/28/javascriptkata-now-ad-free/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 17:11:41 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[white belt]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=68</guid>
		<description><![CDATA[JavascriptKata was created in the blog bubble. In a time when all you had to do was to create a blog, put ads on it and you were rich. It never was true. The ads on this blog gave me about 100$ in a year so I finally felt discouraged and left it for dead. [...]]]></description>
			<content:encoded><![CDATA[<p>JavascriptKata was created in the blog bubble. In a time when <cite>all you had to do was to create a blog, put ads on it and you were rich</cite>. It never was true. The ads on this blog gave me about 100$ in a year so I finally felt discouraged and left it for dead. Nevertheless, this blog as a good share of traffic and more subscribers in the feed than any blog that I&#8217;ve owned/I own/will own. In fact, I call it a blog but it&#8217;s not really a blog. I used wordpress and that&#8217;s the main reason why I&#8217;m calling it a blog.</p>
<p>I tried several things to keep my interest in writing about javascript but they all failed because there was the devil saying &#8220;anyways, you don&#8217;t make any money out of it&#8221;. But there was the angel saying &#8220;maybe you don&#8217;t make money but you like javascript and should continue to write about it&#8221;. As usual, the devil won.</p>
<p>I won&#8217;t try to make another revival of this blog but I&#8217;ll try to write more about little things that happens between me and javascript, about the daily problems that I encounter. I&#8217;ll write a lot about <a href="http://www.jquery.com" target="_blank">jquery</a> too since for me, there can be no javascript without jquery.</p>
<p>Thanks to all of you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2008/11/28/javascriptkata-now-ad-free/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Load a page with javascript</title>
		<link>http://www.javascriptkata.com/2008/02/12/load-a-page-with-javascript/</link>
		<comments>http://www.javascriptkata.com/2008/02/12/load-a-page-with-javascript/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 14:31:20 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[Ask Dan a javascript question]]></category>

		<category><![CDATA[white belt]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/2008/02/12/load-a-page-with-javascript/</guid>
		<description><![CDATA[Someone asked me : "I would like this site to automatically load a certain page (1-31) depending on what day of the month it is (1-31)"]]></description>
			<content:encoded><![CDATA[<p>I receive javascript-related questions in my inbox from time to time and here&#8217;s the last one.</p>
<blockquote><p> I am ok with HTML but awfully new to JavaScript and I know very little at this point. My question is for this web site I&#8217;m building. I need to know the exact JavaScript code and placement of the code in an HTML document for this goal. I would like this site to <strong>automatically load a certain page (1-31) depending on what day of the month it is (1-31)</strong>. I don&#8217;t need to worry about what month or year it is, just the date in the month. For instance when it is the eleventh day in the month, page11.html will automatically load when you click on to the site. I would like it to take the time(Date) from the client side not the server. This way no mater what time zone your in the right HTML page will pop up at midnight.</p></blockquote>
<p>Most people can&#8217;t give the <em>exact javascript code placement of the code in an HTML document</em> because it would always be buggy. They can give hints and/or snippets of code but rarely a complete working piece. Sorry&#8230;</p>
<p>Secondly, relying on javascript to do all this work would be a mistake because <strong>if javascript is disabled, the site will not work</strong>. Most users have javascript enabled but you should always think about web-crawlers (google, yahoo!, etc) that will try to index your page but will hit an empty page.</p>
<p>It&#8217;s always hard to guess all the reasons why someone would want a different page everyday of the month and I don&#8217;t know more about the project than what is written above. Considering this, maybe there are just parts of the page that are changing everyday and you could load them on the server-side thus having a single page loading including other pages depending on the day. The problem is that you would have to ask the timezone of the user and keep it in a cookie.</p>
<p>Just remember, <strong>javascript should not be a requirement to navigate in a site</strong>.</p>
<p>Finally, if I would really want to load a complete new page in javascript, I would do the following.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> dayOfTheMonth = <span class="br0">&#40;</span><span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">getDate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">location.<span class="me1">href</span>=<span class="st0">&quot;page&quot;</span> + dayOfTheMonth.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span> + <span class="st0">&quot;.html&quot;</span>;</div>
</li>
</ol>
</div>
<p style="margin-bottom: 2em">&nbsp;</p>
<p>This is the way I would do it, <strong>do you have any other suggestions?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2008/02/12/load-a-page-with-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to have jQuery and prototype.js in the same project</title>
		<link>http://www.javascriptkata.com/2008/01/28/how-to-have-jquery-and-prototypejs-in-the-same-project/</link>
		<comments>http://www.javascriptkata.com/2008/01/28/how-to-have-jquery-and-prototypejs-in-the-same-project/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 11:02:41 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[black belt]]></category>

		<category><![CDATA[how to]]></category>

		<category><![CDATA[librairies]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/2008/01/28/how-to-have-jquery-and-prototypejs-in-the-same-project/</guid>
		<description><![CDATA[I&#8217;m a big fan of jQuery. This librarie is just the best and simplest one around. I really noticed it when I wanted to get rid of jQuery in TimmyOnTime and try to use prototype.js instead, just to be more &#8220;rails-oriented&#8221; (that&#8217;s a pretty lame excuse don&#8217;t you think?)
Why I didn&#8217;t like prototype.js
There was not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of <a href="http://jquery.com/" target="_blank">jQuery</a>. This librarie is just the <strong>best</strong> and <strong>simplest</strong> one around. I really noticed it when I wanted to get rid of jQuery in <a href="http://timmyontime.com/" target="_blank">TimmyOnTime</a> and try to use <a href="http://www.prototypejs.org/" target="_blank">prototype.js</a> instead, just to be more &#8220;rails-oriented&#8221; (that&#8217;s a pretty lame excuse don&#8217;t you think?)</p>
<h3>Why I didn&#8217;t like prototype.js</h3>
<p>There was not a lot of javascript written for the project so I thought that getting rid of jQuery and using prototype.js would be easy. It turned out to be hell on earth. <strong>Prototype.js made me feel like I was back in the 90s writing C++</strong>. A simple click event turns out to be a awful lot of ugly code with ugly function names.</p>
<p>Example, <strong>if I wanted to show the content of a DIV I clicked</strong> in prototype.js, I would use things like <a href="http://www.prototypejs.org/api/event/observe" target="_blank">Event.observe</a>, <a href="http://www.prototypejs.org/api/function/bindAsEventListener" target="_blank">bindAsEventListener</a>, a mix of native DOM element and prototype.js element, and worst of all, an <a href="http://www.prototypejs.org/api">unintelligible documentation</a>.</p>
<p>jQuery as a complete different way of doing it in a single easy-to-understand line :<br />
<em>$(&#8221;#a_div&#8221;).click(function() { alert($(this).text()); });</em>.<br />
As simple as that!</p>
<h3>The problem</h3>
<p>I wanted to use some interface element in Rails that requires prototype.js so I had to have both librairies. The problem is that there&#8217;s a conflict between them. Prototype.js doesn&#8217;t seem to give a damn about it but jQuery is nicer with you. It offers a <a href="http://docs.jquery.com/Core/jQuery.noConflict" target="_blank">noConflict</a> method.</p>
<p><strong>With Rails</strong>, prototype.js is the default librairie so to override this, you could do</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;%= javascript_include_tag &quot;prototype&quot;, &quot;jquery&quot; %&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;script&gt;$j = jQuery.noConflict();&lt;/script&gt;</div>
</li>
</ol>
</div>
<p>This way, you will have to use <strong>$j</strong> instead of <strong>$</strong> to call jQuery.<strong>$</strong> would still call prototype.</p>
<p>Another thing you could do is to use <a href="http://ennerchi.com/projects/jrails" target="_blank">jQuery on Rails</a> and don&#8217;t give a damn about scriptaculous. I personally prefer to use librairies that are fully tested instead of using a &#8220;by-pass&#8221; that could break my code. It&#8217;s your choice&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2008/01/28/how-to-have-jquery-and-prototypejs-in-the-same-project/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New on Javascript Kata : the echo chamber</title>
		<link>http://www.javascriptkata.com/2008/01/08/new-on-javascript-kata-the-echo-chamber/</link>
		<comments>http://www.javascriptkata.com/2008/01/08/new-on-javascript-kata-the-echo-chamber/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 22:55:55 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[white belt]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/2008/01/08/new-on-javascript-kata-the-echo-chamber/</guid>
		<description><![CDATA[Since the beginning of the new year, I&#8217;m offering to javascripters the echo chamber. What is it? It&#8217;s a category where I will post news about what happens in the javascript world. I will try to avoid ajax related news because Ajaxian already does the job really well.
You can subscribe to the RSS feed with [...]]]></description>
			<content:encoded><![CDATA[<p>Since the beginning of the new year, I&#8217;m offering to javascripters the <a href="http://www.javascriptkata.com/category/echo-chamber/">echo chamber</a>. What is it? It&#8217;s <strong>a category where I will post news about what happens in the javascript world</strong>. I will try to avoid ajax related news because <a href="http://ajaxian.com/" target="_blank">Ajaxian</a> already does the job really well.</p>
<p>You can subscribe to the RSS feed with <a href="http://feeds.feedburner.com/JavascriptKata">all the articles</a> or to the RSS feed<a href="http://feeds.feedburner.com/javascriptkata/no_echo_chamber"> without the articles from the echo chamber</a>.</p>
<p>Some may have noticed that I redesigned the site. The <a href='http://www.javascriptkata.com/wp-content/uploads/2008/01/js_old.jpg' title='Javascript Kata - old design'>old design</a> was long overdue and it was a pleasure for my eyes to have a new one.</p>
<p>I would also like to have your <strong>feedback on what you think of the new echo chamber and design</strong>?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2008/01/08/new-on-javascript-kata-the-echo-chamber/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ask Dan : More on javascript threading</title>
		<link>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/</link>
		<comments>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 14:05:20 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[Ask Dan a javascript question]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[black belt]]></category>

		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=31</guid>
		<description><![CDATA[From time to time, I receive emails from desperate people who want help with their javascript problem. I also receive a lot of emails of people wanting to help me with my &#8220;manly problems&#8221;. It&#8217;s very nice from them to care about me and I take time to reply to each of them but I [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time, I receive emails from desperate people who want help with their javascript problem. I also receive a lot of emails of people wanting to help me with my &#8220;manly problems&#8221;. It&#8217;s very nice from them to care about me and I take time to reply to each of them but I don&#8217;t have that kind of problem for the moment.</p>
<p><strong>Stuart Cooper</strong> recently sent me a mail about threading in javascript and I turn to you, javascripters, to find the a solution for his problem. I <a href="http://refactormycode.com/codes/172-javascript-threading" target="_blank">sent the code on RefactorMyCode for refactorisation</a> and they will automatically show up in the comments of this post (the site is an idea of <a href="http://macournoyer.wordpress.com/" target="_blank">Marc-AndrÃ© Cournoyer</a> who is a very active developer from Montreal). <strong>Don&#8217;t be afraid to think outside the box</strong>. The solution may be completly different from what is already written.</p>
<hr /><em> I am experience trying to create a &#8220;cover page&#8221; that runs a ping to remote servers.In my code I am using setInterval() to run repeating pings (artificially quickly at the moment, ie 10 seconds rather than 1 min) and display the results to browser.  I have built my own XMLHttpRequest module (mainly as a learning exercise) and I don&#8217;t believe it to be the source of my ills.</em><em> </em><em>I have read through your article and the behaviour of alert() and confirm() fits exactly with what I am seeing when I run the following code :</em><em>[snippet]</em></p>
<p><em>function startup(){</em></p>
<p><em>setInterval(&#8221;pinger(&#8217;live&#8217;,0)&#8221;,10000);<br />
setInterval(&#8221;pinger(&#8217;standby&#8217;,1)&#8221;,10000);<br />
setInterval(&#8221;pinger(&#8217;dev&#8217;,2)&#8221;,10000);<br />
setInterval(&#8221;pinger(&#8217;test1&#8242;,3)&#8221;,10000);<br />
setInterval(&#8221;pinger(&#8217;test2&#8242;,4)&#8221;,10000);<br />
setInterval(&#8221;pinger(&#8217;test3&#8242;,5)&#8221;,10000);<br />
setInterval(&#8221;pinger(&#8217;test4&#8242;,6)&#8221;,10000);</em></p>
<p><em>}</em></p>
<p><em>function pinger(server,divit){</em></p>
<p><em>console=document.getElementById(&#8217;ping_div&#8217; + divit);<br />
console.innerHTML=&#8221;;<br />
sendRequest(&#8221;../php/ping_sys2.php?target=&#8221; + server);</em></p>
<p><em>}</em></p>
<p><em>[/snippet]</em></p>
<p><em>(each server has its own named div to return to)</em></p>
<p><em>What I am seeing when I run this is the final pinger response from the callback and nothing else.  I since added debugging into my XMLHttpRequest code so that it split out the server response progress.</em></p>
<p><em>[snippet]</em></p>
<p><em>readyXML=xmlReq.readyState;</em></p>
<p><em>[/snippet]</em></p>
<p><em>[snippet]</em></p>
<p><em>if(readyXML == 3){</em></p>
<p><em>data=&#8221;Serving &#8230;&#8221;;</em></p>
<p><em>}</em></p>
<p><em>if(readyXML == 2){</em></p>
<p><em>data=&#8221;Sent &#8230;&#8221;;</em></p>
<p><em>}</em></p>
<p><em>if(readyXML == 1){</em></p>
<p><em>data=&#8221;Opening &#8230;&#8221;;</em></p>
<p><em>}</em></p>
<p><em>[/snippet]</em></p>
<p><em>What I have observed is that when running the setInterval commands as above, all except the final request are &#8220;jammed&#8221; on readyState = 1 and appropriately responds with &#8220;Sending â€¦&#8221;</em></p>
<p><em>however,</em></p>
<p><em>when I do the following (which is messy)</em></p>
<p><em>[snippet]</em></p>
<p><em>function startup(){</em></p>
<p><em>setInterval(&#8221;pinger(&#8217;live&#8217;,0)&#8221;,1000);<br />
alert(&#8221;something&#8221;);<br />
setInterval(&#8221;pinger(&#8217;standby&#8217;,1)&#8221;,10000);<br />
alert(&#8221;something&#8221;);<br />
setInterval(&#8221;pinger(&#8217;dev&#8217;,2)&#8221;,10000);<br />
alert(&#8221;something&#8221;);<br />
setInterval(&#8221;pinger(&#8217;test1&#8242;,3)&#8221;,10000);<br />
alert(&#8221;something&#8221;);<br />
setInterval(&#8221;pinger(&#8217;test2&#8242;,4)&#8221;,10000);<br />
alert(&#8221;something&#8221;);<br />
setInterval(&#8221;pinger(&#8217;test3&#8242;,5)&#8221;,10000);<br />
alert(&#8221;something&#8221;);<br />
setInterval(&#8221;pinger(&#8217;test4&#8242;,6)&#8221;,10000);</em></p>
<p><em>}</em></p>
<p><em>[/snippet]</em></p>
<p><em>Each response is absolutely spot on and will continue to generate pings correctly.  So in this case the script alert interrupts are forcing the callback request to trigger, whereas without the alerts its only the last request that triggers a callback.  I have also tried using artificial timeout loops instead of alerts (which generate the odd browser &#8220;script running slowly&#8221; message) but to no avail.</em></p>
<p><em>At the moment I am almost resigned to having to create individual events (like rollovers, though I would much prefer the ping initialisation to occur window.onLoad()) that trigger the setInterval() â€¦ which also seems to work fine.</em></p>
<p><em>I am hoping that you may have come across a way of forcing the XMLHttpRequest to respond without forcing alerts or confirms on the user, in the time since the last update to the article.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2007/12/06/ask-dan-more-on-javascript-threading/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A new project - I hate PHP</title>
		<link>http://www.javascriptkata.com/2007/12/05/a-new-project-i-hate-php/</link>
		<comments>http://www.javascriptkata.com/2007/12/05/a-new-project-i-hate-php/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 15:55:20 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[white belt]]></category>

		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=55</guid>
		<description><![CDATA[If you are  javascripter, chances are that you must work with some back-end languages like ASP.NET, ColdFusion, Ruby On Rails or PHP. If you work with a back-end language, chances are that you become frustrated against it sometimes. That&#8217;s why I created I hate PHP.
What is it?
I hate PHP helps you to evacuate your [...]]]></description>
			<content:encoded><![CDATA[<p>If you are  javascripter, chances are that you must work with some back-end languages like ASP.NET, ColdFusion, Ruby On Rails or <strong>PHP</strong>. If you work with a back-end language, chances are that <strong>you become frustrated against it</strong> sometimes. That&#8217;s why I created <a href="http://www.ihatephp.net/" target="_blank">I hate PHP</a>.</p>
<h3>What is it?</h3>
<p><a href="http://www.ihatephp.net/" target="_blank">I hate PHP</a> helps you to evacuate your daily frustrations against the PHP language via <a href="http://www.twitter.com" target="_blank">Twitter</a>. It&#8217;s simple. You must tell your <em>twitter username</em> to <em>I hate PHP</em> (on the website) and then, send a direct message to the <a href="http://twitter.com/ihatephp" target="_blank">ihatephp twitter user</a> in the following format : <strong>d ihatephp <em>a thing that frustrates you in PHP</em></strong>.</p>
<h3>Why against PHP?</h3>
<p>I could have done it against a lot of languages because <strong>they all suck in their own special way</strong>. But the moment I was thinking about the project, I was working with PHP and I just kept sending IM messages to Frank (of <a href="http://www.rubyfleebie.com/" target="_blank">Ruby Fleebie</a>) to tell him about things that frustrated me in PHP. I just made it more &#8220;official&#8221; and now I tell it to the world via <a href="http://www.ihatephp.net" target="_blank">I hate PHP</a>.</p>
<p>Subscribe to the <a href="http://feeds.feedburner.com/ihatephp" target="_blank">RSS</a> of I hate PHP!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2007/12/05/a-new-project-i-hate-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Barcamp Montreal 3 and this site</title>
		<link>http://www.javascriptkata.com/2007/11/05/barcamp-montreal-3-and-this-site/</link>
		<comments>http://www.javascriptkata.com/2007/11/05/barcamp-montreal-3-and-this-site/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 23:52:55 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
		
		<category><![CDATA[black belt]]></category>

		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=54</guid>
		<description><![CDATA[Like most of you already knew, I&#8217;m working with Frank Lamontagne of Ruby Fleebie on a project called TimmyOnTime. We had the chance to present it at the last Barcamp Montreal and it went&#8230; really bad! If you want to know more about the whole adventure (and have a good laugh), click here to read [...]]]></description>
			<content:encoded><![CDATA[<p>Like most of you already knew, I&#8217;m working with Frank Lamontagne of <a href="http://www.rubyfleebie.com/" target="_blank">Ruby Fleebie</a> on a project called <a href="http://timmyontime.com/" target="_blank">TimmyOnTime</a>. We had the chance to present it at the last <a href="http://barcampmontreal.org/wiki/English:BarCampMontreal3">Barcamp Montreal</a> and it went&#8230; really bad! If you want to know more about the whole adventure (and have a good laugh), <a href="http://www.rubyfleebie.com/barcampmontreal3-and-acts-of-god/" target="_blank">click here</a> to read the story written by Frank. (By the way, I used a good ol&#8217; click here link just for the fun of it&#8230; I never did it before and frankly, I like it&#8230; almost&#8230;).</p>
<h3>What happens with Javascript Kata?</h3>
<p>I know, I  have been negligent with site. It&#8217;s really shameful to let a great site die and there&#8217;s no one to blame but me. Why I did that? I could give hundreds of reasons but they would all be lies. I really don&#8217;t know what happened.</p>
<p>I want to give another twist to JavascriptKata. I want to get back to a more tradional reference site because I don&#8217;t like the concept of a technical blog after all. I want the articles to be more persistent, not just a post that everyone forget about after a while.</p>
<p>But, there would be a RSS feed too. I would announce new articles on the site. I would also use it to debate on tricky things about javascript and then make an article out of it.</p>
<p>I really would like to hear you about this idea, please comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2007/11/05/barcamp-montreal-3-and-this-site/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
