<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ajax Bestiary &#187; Misc Toolkits</title>
	<atom:link href="http://www.ajaxbestiary.com/category/misc-toolkits/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ajaxbestiary.com</link>
	<description>AJAX Development, News, Techniques &#38; More</description>
	<lastBuildDate>Wed, 01 Feb 2012 12:46:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Enyo released</title>
		<link>http://www.ajaxbestiary.com/2012/01/26/enyo-released/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/26/enyo-released/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 13:03:56 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Javascript Frameworks]]></category>
		<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[enyo]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[hp]]></category>
		<category><![CDATA[js framework]]></category>
		<category><![CDATA[webos]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=681</guid>
		<description><![CDATA[HP is slowly open sourcing webOS. Yesterday, they released the Enyo framework with cross-browser support. The heart of Enyo is the enyo.kind() method which dynamically generates a reusable page component which can be referenced in the global namespace like so: enyo.kind&#40;&#123; name: &#34;Hello&#34;, kind: enyo.Control, components: &#91; &#123;name: &#34;hello&#34;, content: &#34;Hello From Enyo&#34;, ontap: &#34;helloTap&#34;&#125;, [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>HP is <a href="http://www.slashgear.com/open-webos-announced-as-hps-open-source-mobile-os-power-move-25210755/">slowly open sourcing webOS</a>. Yesterday, they released the <a href="http://enyojs.com/">Enyo framework</a> with cross-browser support.</p>
<p>The heart of Enyo is the <code>enyo.kind()</code> method which dynamically generates a reusable page component which can be referenced in the global namespace like so:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">enyo.<span style="color: #660066;">kind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Hello&quot;</span><span style="color: #339933;">,</span>
    kind<span style="color: #339933;">:</span> enyo.<span style="color: #660066;">Control</span><span style="color: #339933;">,</span>
    components<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;hello&quot;</span><span style="color: #339933;">,</span> content<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Hello From Enyo&quot;</span><span style="color: #339933;">,</span> ontap<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;helloTap&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>tag<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;hr&quot;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    helloTap<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.$.<span style="color: #660066;">hello</span>.<span style="color: #660066;">addStyles</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color: red&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// make two, they're small</span>
<span style="color: #003366; font-weight: bold;">new</span> Hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">new</span> Hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>At first glance, this seems like a lot of extra code to create a bit of color-changing text with a horizontal rule. However, you can also define custom properties, events and methods, which suddenly makes this an elegant way to create what jQuery calls plugins. Since you can also encapsulate other generated kinds, this could also be an interesting way of creating entire actors within a game.</p>
<p>While it&#8217;s not so performant as to empower, say, a first-person shooter, they do provide a simple <a href="http://enyojs.com/samples/piratepig/">demo of a game</a>.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/26/enyo-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Interactive Maps for Both Mobile and Desktop</title>
		<link>http://www.ajaxbestiary.com/2012/01/23/html5-interactive-maps-for-both-mobile-and-desktop/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/23/html5-interactive-maps-for-both-mobile-and-desktop/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 16:39:29 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[leaflet]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=666</guid>
		<description><![CDATA[When you think maps, you probably think Google or MapQuest, both of which have interactive maps that are really only optimized for desktop browsers. You have to jump out to a separate app for geo-interactivity (yes, that is an invented word). That is perhaps why CloudMade released Leaflet, putting it under the BSD license. As [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>When you think maps, you probably think Google or MapQuest, both of which have interactive maps that are really only optimized for desktop browsers. You have to jump out to a separate app for geo-interactivity (yes, that is an invented word).</p>
<p>That is perhaps why <a href="http://cloudmade.com/">CloudMade</a> released <a href="http://leaflet.cloudmade.com/index.html">Leaflet</a>, putting it under the BSD license.</p>
<p>As you would expect, it supports tile layers, polylines, markers, popups and image layers. However, it also has native support for panning and zooming on mobile browsers. It also uses CSS3, so you can stylize pins, popups and controls. It&#8217;s also fast &#8211; noticeably faster than Google Maps &#8211; though that is partially because its source data, <a href="http://www.openstreetmap.org/">OpenStreetMap</a>, doesn&#8217;t contain quite as much data.</p>
<p>At this time, supports most desktop browsers well, but on mobile environments, it requires iOS 3+ or Android 2.2+.</p>
<p>Implementing a map is very straightforward:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create a CloudMade tile layer</span>
<span style="color: #003366; font-weight: bold;">var</span> cloudmadeUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://{s}.tile.cloudmade.com/YOUR-API-KEY/997/256/{z}/{x}/{y}.png'</span><span style="color: #339933;">,</span>
    cloudmadeAttribution <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Map data &amp;copy; 2011 OpenStreetMap contributors, Imagery &amp;copy; 2011 CloudMade'</span><span style="color: #339933;">,</span>
    cloudmade <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> L.<span style="color: #660066;">TileLayer</span><span style="color: #009900;">&#40;</span>cloudmadeUrl<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>maxZoom<span style="color: #339933;">:</span> <span style="color: #CC0000;">18</span><span style="color: #339933;">,</span> attribution<span style="color: #339933;">:</span> cloudmadeAttribution<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// initialize the map on the &quot;map&quot; div</span>
<span style="color: #003366; font-weight: bold;">var</span> map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> L.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'map'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// set the map view to a given center and zoom and add the CloudMade layer</span>
map.<span style="color: #660066;">setView</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> L.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">51.505</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">0.09</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>cloudmade<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create a marker in the given location and add it to the map</span>
<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> L.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> L.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">51.5</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">0.09</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// attach a given HTML content to the marker and immediately open it</span>
marker.<span style="color: #660066;">bindPopup</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A pretty CSS3 popup.&lt;br /&gt;Easily customizable.&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">openPopup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.ajaxbestiary.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-23-at-10.13.02-AM.png" alt="Leaflet generated map" title="Leaflet generated map" border="0" width="600" height="234" /></p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/23/html5-interactive-maps-for-both-mobile-and-desktop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote console for mobile web diagnosis</title>
		<link>http://www.ajaxbestiary.com/2012/01/20/remote-console-for-mobile-web-diagnosis/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/20/remote-console-for-mobile-web-diagnosis/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 12:00:45 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=655</guid>
		<description><![CDATA[Remy Sharp has developed a tool for remotely debugging web pages. This works using code injection, so be very sure to keep it out of production environments. However, when you need to diagnosis issues remotely, say, because it&#8217;s on a mobile device, with limited console support, or because a client is reporting problems that you [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p><a href="http://twitter.com/rem">Remy Sharp</a> has developed a tool for <a href="http://jsconsole.com/">remotely debugging</a> web pages. This works using code injection, so be very sure to keep it out of production environments. However, when you need to diagnosis issues remotely, say, because it&#8217;s on a mobile device, with limited console support, or because a client is reporting problems that you can&#8217;t repeat locally.</p>
<p>Implementing this is a snap!</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">:</span>listen</pre></div></div>

<p></code></p>
<p>This returns an UUID which you will need to insert into the page markup:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="html4script" style="font-family:monospace;">&lt;script src=&quot;http://jsconsole.com/remote.js?FAE031CD-74A0-46D3-AE36-757BAB262BEA&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p></code></p>
<p>From then on, calls to <code>console.log()</code> will return their output to your listening machine.</p>
<p>The really handy library has one more trick up its sleeve. You can specify the UUID to which you will listen.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">:</span>listen FAE031CD<span style="color: #339933;">-</span>74A0<span style="color: #339933;">-</span>46D3<span style="color: #339933;">-</span>AE36<span style="color: #339933;">-</span>757BAB262BEA</pre></div></div>

<p></code></p>
<p>When the remote device loads the debugging module, you&#8217;ll see something like this in your console:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">:</span>listen FAE031CD<span style="color: #339933;">-</span>74A0<span style="color: #339933;">-</span>46D3<span style="color: #339933;">-</span>AE36<span style="color: #339933;">-</span>757BAB262BEA
Creating connection...
<span style="color: #660066;">Connected</span> to <span style="color: #3366CC;">&quot;FAE031CD-74A0-46D3-AE36-757BAB262BEA&quot;</span>
Connection established <span style="color: #000066; font-weight: bold;">with</span> Mozilla<span style="color: #339933;">/</span><span style="color: #CC0000;">5.0</span> <span style="color: #009900;">&#40;</span>Macintosh<span style="color: #339933;">;</span> U<span style="color: #339933;">;</span> Intel Mac OS X <span style="color: #CC0000;">10.6</span><span style="color: #339933;">;</span> en<span style="color: #339933;">-</span>GB<span style="color: #339933;">;</span> rv<span style="color: #339933;">:</span>1.9.2.8<span style="color: #009900;">&#41;</span> Gecko<span style="color: #339933;">/</span><span style="color: #CC0000;">20100722</span> Firefox<span style="color: #339933;">/</span>3.6.8</pre></div></div>

<p></code></p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/20/remote-console-for-mobile-web-diagnosis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Incremental MD5 with AMD support</title>
		<link>http://www.ajaxbestiary.com/2012/01/19/incremental-md5-with-amd-support/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/19/incremental-md5-with-amd-support/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 12:07:23 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Misc Toolkits]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=649</guid>
		<description><![CDATA[As we all know, MD5 is a fast hashing algorithm. While its numerous security holes make it undesirable for encryption, it is pervasive and convenient for quickly generating quasi-unique ID&#8217;s. While JavaScript has no built-in support for hashing algorithms, this wheel has been re-invented a lot. So why discuss it here? Most implementations to date [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>As we all know, <a href="http://en.wikipedia.org/wiki/MD5">MD5</a> is a fast hashing algorithm. While its numerous security holes make it undesirable for encryption, it is pervasive and convenient for quickly generating quasi-unique ID&#8217;s.</p>
<p>While JavaScript has no built-in support for hashing algorithms, this wheel has been re-invented a lot. So why discuss it here? Most implementations to date have littered the namespace with variables or offered poorer performance than their rivals.</p>
<p><a href="https://github.com/satazor/SparkMD5#readme">SparkMD5</a> attempts to remedy this situation. Based on the <a href="http://www.myersdaily.org/joseph/javascript/md5-text.html">JKM md5</a> implementation, it is <a href="http://jsperf.com/md5-shootout/6">fast</a>. However, it also keeps namespace pollution to a minimum, with its use of closures and OOP.</p>
<p>In addition, it has two neat tricks up its sleeve.</p>
<p>First, you can incrementally hash strings:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> spark <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> SparkMD5<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
spark.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hi'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
spark.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' there'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> hexHash <span style="color: #339933;">=</span> spark.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                    <span style="color: #006600; font-style: italic;">// hex hash</span>
<span style="color: #003366; font-weight: bold;">var</span> rawHash <span style="color: #339933;">=</span> spark.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                <span style="color: #006600; font-style: italic;">// OR raw hash</span></pre></div></div>

<p></code></p>
<p>This is particularly handy for large strings, like what you might get using the <a href="http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files">FileReader API</a>. Conveniently, Andre Cruz, the developer of SparkMD5, has included the code to do this in the GitHub README.</p>
<p>Second, it optionally supports <a href="https://github.com/amdjs/amdjs-api/wiki/AMD">Asynchronous Module Definition</a>, which can reduce the initial load-time of pages and helps isolate your code from your markup. While AMD is certainly <a href="http://tomdale.net/2012/01/amd-is-not-the-answer/">controversial</a>, asynchronous loading of code does seem to be a <a href="http://ajaxpatterns.org/On-Demand_Javascript#Dojo_Package_System">prevailing trend</a>.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/19/incremental-md5-with-amd-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TWSS: Naive Bayes Classifier and k-Nearest Neighbor library for NodeJS</title>
		<link>http://www.ajaxbestiary.com/2012/01/18/twss-naive-bayes-classifier-and-k-nearest-neighbor-library-for-nodejs/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/18/twss-naive-bayes-classifier-and-k-nearest-neighbor-library-for-nodejs/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 12:00:18 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[NodeJS]]></category>
		<category><![CDATA[bayesian]]></category>
		<category><![CDATA[knn]]></category>
		<category><![CDATA[machine learning]]></category>
		<category><![CDATA[nbc]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=645</guid>
		<description><![CDATA[TWSS is an acronym that stands for That&#8217;s What She Said, a joke frequently abused by the character Michael Scott on the US version of The Office. Why would anyone write a library that tells you whether or not &#34;That&#8217;s what she said!&#34; is an &#34;appropriate&#34; response to a given sentence? Frankly, I don&#8217;t know. [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p><a href="https://github.com/DanielRapp/twss.js">TWSS</a> is an acronym that stands for That&#8217;s What She Said, a joke frequently abused by the character <a href="http://www.nbc.com/the-office/video/thats-what-she-said/1323315">Michael Scott</a> on the US version of The Office. Why would anyone write a library that tells you whether or not &quot;That&#8217;s what she said!&quot; is an &quot;appropriate&quot; response to a given sentence? Frankly, I don&#8217;t know. However, during  implementation, he created a generalized document <a href="http://en.wikipedia.org/wiki/Naive_Bayes_classifier">NBC</a> and <a href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm">k-NN</a> tool that runs cleanly inside <a href="http://www.ajaxbestiary.com/category/nodejs">NodeJS</a>.</p>
<p>In effect, with different training material, this is a powerful tool with an <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. Its also potentially very expandable.</p>
<p>So let&#8217;s see it in action.</p>
<p>Set the algorithm:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">twss.<span style="color: #660066;">algo</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'nbc'</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>Set the tolerance threshold:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">twss.<span style="color: #660066;">threshold</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.5</span><span style="color: #339933;">;</span>
twss.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;You're hardly my first.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// false</span>
&nbsp;
twss.<span style="color: #660066;">threshold</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.3</span><span style="color: #339933;">;</span>
twss.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;You're hardly my first.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// true</span></pre></div></div>

<p></code></p>
<p>Or, for your customized tool, return the probability:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">twss.<span style="color: #660066;">prob</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The juice keeps coming out of the wrong hole!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 0.9961630818418142</span></pre></div></div>

<p></code></p>
<p>How do we expand our algorithm selection? Look in /lib/twss.js:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> classify <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  nbc<span style="color: #339933;">:</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./classifier/nbc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  knn<span style="color: #339933;">:</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./classifier/knn'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>As you can see, adding algorithms is primarily a matter of a new file in the classifier subdirectory and adding a member element to the classify object. The new classifier must implement getTwssProbability() and isTwss().</p>
<p>However, you will have to lightly edit exports.probability() and exports.is() to recognize your custom algorithm.</p>
<p><strong>UPDATE</strong> My apologies for the links to Wikipedia on the day of the SOPA blackout.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/18/twss-naive-bayes-classifier-and-k-nearest-neighbor-library-for-nodejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The sound of music is silence and sometimes a click</title>
		<link>http://www.ajaxbestiary.com/2012/01/09/the-sound-of-music-is-silence-and-sometimes-a-click/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/09/the-sound-of-music-is-silence-and-sometimes-a-click/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 12:00:08 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[audio data]]></category>
		<category><![CDATA[audio data api]]></category>
		<category><![CDATA[audiolet]]></category>
		<category><![CDATA[audiolib]]></category>
		<category><![CDATA[multimedia]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[soundmanager]]></category>
		<category><![CDATA[soundmanager2]]></category>
		<category><![CDATA[w3c]]></category>
		<category><![CDATA[web audio]]></category>
		<category><![CDATA[webaudio api]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=598</guid>
		<description><![CDATA[HTML5 begat the AUDIO tag. Now that we have it, what do we do with it? And how do we accommodate older browsers? Unfortunately, there are two incompatible standards and the W3C Audio Working Group &#34;has not decided upon a specification&#34;. The Web Audio API works on recent builds of Chrome and Safari. The API [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>HTML5 begat the AUDIO tag. Now that we have it, what do we do with it? And how do we accommodate older browsers?</p>
<p>Unfortunately, there are two incompatible standards and the W3C Audio Working Group &quot;<a href="http://www.w3.org/2011/audio/wiki/PubStatus">has not decided upon a specification</a>&quot;.</p>
<p>The <a href="http://www.html5rocks.com/en/tutorials/webaudio/intro/">Web Audio API</a> works on recent builds of Chrome and Safari. The API includes complex filters and allows developers to roll <a href="http://chromium.googlecode.com/svn/trunk/samples/audio/index.html">drum machines and visualizations</a>. It&#8217;s active by default on Chrome 16, but not on Safari 5. Worse, Safari 5 reports that it is supported, but won&#8217;t run the samples to which I have linked. Adding insult to injury, it&#8217;s also slow and can randomly introduce skips and clicks.</p>
<p>Mozilla introduced the <a href="https://wiki.mozilla.org/Audio_Data_API">Audio Data API</a>, but it only works in Firefox 4 and above. It&#8217;s also a very low level API and requires <a href="https://wiki.mozilla.org/Audio_Data_API#JavaScript_Audio_Libraries">intermediate libraries</a> to be truly useful for non-developer apps, of which there are a number. Like Google&#8217;s Web Audio, it&#8217;s slow and can randomly introduce skips and clicks.</p>
<p>Since these two technologies encompass only about half of web traffic, we clearly need fallback mechanisms.</p>
<p>There is <a href="http://www.schillmania.com/projects/soundmanager2/">SoundManager2</a> which uses both HTMl5 and Flash 8 or 9+ to bridge platforms. It relies on MP3/AAC/OGG/WAV sample files and supports panning, sampling and &#8211; most valuable &#8211; event support. Events like <code>whileplaying</code> and <code>onposition</code> make it easy to sync your audio and video. Beyond equalization, volume and start/stop positions, however, you can&#8217;t do much to filter the sound output.</p>
<p>You might also try <a href="https://github.com/oampo/Audiolet">Audiolet</a>, which lets you generate your own waveforms in browser, giving you a full range of freedom, but it&#8217;s going to sound like 8-bit audio unless you use samples. (Hint: try combining it with MUSIC.js to make the most of that 8-bit arcade sound)</p>
<p>Then there is <a href="http://audiolibjs.org/">audiolib.js</a>, which goes even lower than Audiolet and can operate server-side. It allows you to both manipulate and <em>generate</em> audio samples in PCM format, which it can then save for future use.</p>
<p>Audiolet starts quickly and is half the size of SoundManager2, but can click and skip, especially when the browser is scrolling or otherwise pre-occupied. SoundManager2 can bog down when playing too many sounds at once. Try activating +follow and then moving your mouse quickly over its <a href="http://www.schillmania.com/projects/soundmanager2/demo/christmas-lights/">Smashing Christmas Lights demo</a> to see this in action.</p>
<p>Audiolib is extremely low level, but for generating short realistic  waveforms, it is effective and fast, both client-side and server. Sadly, in Firefox 9 on my Mac, <a href="http://audiolibjs.org/examples/bells.html">this example</a> only plays the first bell while Safari 5 and Opera 11.6 played nothing at all. Chrome 16 played it correctly. However, when I had the page open in 3 browsers simultaneously, even though only one was generating noise, the load was causing skipping and clicking in Chrome. Your audio could easily suffer if the end user&#8217;s computer is otherwise busy.</p>
<p>In short, there is no good solution yet that is widely supported <em>and</em> flexible <em>and</em> performant, even within modern browsers.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/09/the-sound-of-music-is-silence-and-sometimes-a-click/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bring HTML5 and ECMAScript 5 to a browser near you</title>
		<link>http://www.ajaxbestiary.com/2011/12/30/bring-html5-and-ecmascript-5-to-a-browser-near-you/</link>
		<comments>http://www.ajaxbestiary.com/2011/12/30/bring-html5-and-ecmascript-5-to-a-browser-near-you/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 12:00:40 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Javascript Frameworks]]></category>
		<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[ecmascript]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[ie]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=565</guid>
		<description><![CDATA[Unless you develop in-house sites for companies that have standardized on a very modern browser, you&#8217;re stuck developing sites for IE8 and even IE7. (Heaven help you if you&#8217;re still developing for IE6). How then do you access some of the powerful features of ECMAScript or the contextual tags of HTML5 without having to write [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Unless you develop in-house sites for companies that have standardized on a very modern browser, you&#8217;re stuck developing sites for IE8 and even IE7. (Heaven help you if you&#8217;re still developing for <a href="http://www.ie6countdown.com/">IE6</a>).</p>
<p>How then do you access some of the powerful features of <a href="http://kangax.github.com/es5-compat-table/">ECMAScript</a> or the contextual tags of HTML5 without having to write layer upon layer of fallbacks?</p>
<p>Your fellow JavaScript developers have produced shims to emulate <em>most</em> of this functionality, even in environments where <a href="http://www.ajaxbestiary.com/2011/06/03/strategically-retreating-to-chrome-frame/">Chrome Frame</a> isn&#8217;t viable.</p>
<p>The <a href="http://code.google.com/p/html5shiv/">html5shiv project</a> is still under active development. It not only adds support for HTML5 contextual tags, it sets their default styling and makes them print in IE8 and below. Naturally, their canvas element is not going to have the behaviors you see in other browsers, but at least you can get away with a single set of markup and fewer CSS rules.</p>
<p>The <a href="https://github.com/kriskowal/es5-shim#readme">es5-shim project</a> is also under active development. It alters prototypes of <a href="http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/">native objects</a>, so I wouldn&#8217;t combine it with prototype.js. This library also has the benefit of being well documented &#8211; including what <a href="https://github.com/kriskowal/es5-shim/blob/master/README.md">does and does not differ</a> from the specification. Heed the cautions from Kris Kowal, its author, though:</p>
<blockquote><p>&#8220;As closely as possible to ES5&#8243; is not very close. Many of these shims are intended only to allow code to be written to ES5 without causing run-time errors in older engines. In many cases, this means that these shims cause many ES5 methods to silently fail. Decide carefully whether this is what you want.</p></blockquote>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/12/30/bring-html5-and-ecmascript-5-to-a-browser-near-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event-driven development with Backbone</title>
		<link>http://www.ajaxbestiary.com/2011/12/05/event-driven-development-with-backbone/</link>
		<comments>http://www.ajaxbestiary.com/2011/12/05/event-driven-development-with-backbone/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 15:00:06 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Javascript Frameworks]]></category>
		<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=527</guid>
		<description><![CDATA[Do you really care if the user clicks an option inside of a SELECT? In most cases, it&#8217;s only a means to the end of getting the new value. So why is your change event handler sending data to the server and modifying the DOM? This leads to spaghetti code, violation of DRY and ever [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Do you really care if the user clicks an option inside of a SELECT? In most cases, it&#8217;s only a means to the end of getting the new value. So why is your change event handler sending data to the server and modifying the DOM? This leads to spaghetti code, violation of DRY and ever more expensive maintenance costs as your app&#8217;s interface evolves.</p>
<p>Thus was born Backbone, an extension of <a href="http://www.ajaxbestiary.com/2011/09/23/underscore-js-jquery-without-the-dom/" title="Underscore.js: jQuery without the DOM">underscore</a>, with default support for jQuery, and with a bit of editing, support for <a href="https://github.com/gaustin/backbone-mootools">MooTools</a>.</p>
<p>So let&#8217;s say you&#8217;re Amazon and you&#8217;re trying to find a way to comply with the legal requirements in some states that say affiliate sold items are subject to sales tax. This is complex and you probably only want to get the most relevant data as late in the process as possible. Backbone makes it surprisingly easy.</p>
<p>Bind to a change event on our data object:<br />
<code>
<pre>
var destination = new Backbone.Model();

_.extend(destination, {state: null});

var order = {
  subtotal: 100,
  tax: 0,
  total: 100
};

//underscore makes it easy to pseudo-subclass
_.extend(order, new Backbone.View());

destination.bind( "change", function() {
  //Pass null in the first parameter to save all model properties
  destination.save(null, {
    success: function(model, reps, xhr){
      //Apply the tax rate
      order.total = order.subtotal + order.subtotal * xhr.taxrate;

      //Update display. Note that this is a no-op by default and
      //you should define it as needed elsewhere.
      order.render();
    }
  } );
} );
</pre>
<p></code></p>
<p>Now for our event handler on the SELECT. Note that I&#8217;m using jQuery, but you could use any library (or none at all).</p>
<p><code>
<pre>
$("#state").change( function() {
  //Do whatever pre-processing is required
  var v = $(this).val();

  //This could be generalized very easily
  destination.set({
    state: v
  });
} );
</pre>
<p></code></p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/12/05/event-driven-development-with-backbone/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Thoughts on Google&#8217;s Native Client platform?</title>
		<link>http://www.ajaxbestiary.com/2011/11/29/thoughts-on-googles-native-client-platform/</link>
		<comments>http://www.ajaxbestiary.com/2011/11/29/thoughts-on-googles-native-client-platform/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 20:09:10 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[desktop app]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[NaCl]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=510</guid>
		<description><![CDATA[Steven Shankland, over at CNET, has written an interesting piece about Google&#8217;s NaCl (yes, chemistry geeks, that is the formula for table salt). Overall, it&#8217;s a fairly balanced review. On the one side, we get all of the benefits of WebKit, but with the performance of a compiled native application. In theory, that then allows [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Steven Shankland, over at CNET, has written an interesting piece about <a href="http://news.cnet.com/8301-30685_3-57332622-264/google-well-prove-native-clients-worth-on-the-web/">Google&#8217;s NaCl</a> (yes, chemistry geeks, that is the formula for table salt). Overall, it&#8217;s a fairly balanced review.</p>
<p>On the one side, we get all of the benefits of WebKit, but with the performance of a compiled native application. In theory, that then allows us to write a knock-off of Photoshop and make it cross-platform, with easy electronic distribution.</p>
<p>On the other side, it&#8217;s not so cross-platform that it works on mobile devices and it does splinter development efforts. It only works on x86 CPU&#8217;s to date and it requires a browser plug-in API, which already dates it, since IE10&#8242;s Metro version will be plug-in-free.</p>
<p>Finally, Google and Mozilla both offer competing engines. Google&#8217;s Dart is intended to supplant JavaScript while Mozilla&#8217;s IonMonkey will further improve compiler performance.</p>
<p>Overall, if you&#8217;re willing to venture into relatively uncharted territory, have significant say in your deployment environment, and need as much performance as possible, this is an intriguing initiative. I just wonder how many of us developers fall into that bucket.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/11/29/thoughts-on-googles-native-client-platform/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Accounting.js A handy formatting library for numbers and finance</title>
		<link>http://www.ajaxbestiary.com/2011/08/22/accounting-js-a-handy-formatting-library-for-numbers-and-finance/</link>
		<comments>http://www.ajaxbestiary.com/2011/08/22/accounting-js-a-handy-formatting-library-for-numbers-and-finance/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 20:18:26 +0000</pubDate>
		<dc:creator>Don Albrecht</dc:creator>
				<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=443</guid>
		<description><![CDATA[Today I stumbled across a handy little javascript framework called accounting.js.  Like the handy date.js library.  It focuses ongoing one thing extremely well. Convert numbers between simple strings of digits into nicely formatted easily readable strings. it has just a few functions. formatMoney() by default, format the string to USD with 2 decimal places, comma [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Today I stumbled across a handy little javascript framework called accounting.js.  Like the handy date.js library.  It focuses ongoing one thing extremely well. Convert numbers between simple strings of digits into nicely formatted easily readable strings.</p>
<p>it has just a few functions.</p>
<h3>formatMoney()</h3>
<p>by default, format the string to USD with 2 decimal places, comma separation at the thousands and a $ sign.  Optional params of [currencySymbol], [precision], [thousands separator], [decimal separator].</p>
<h3>formatColumn()</h3>
<p>just like formatMoney, but it takes an array of values and white space pads their conversions to the same length.</p>
<h3>unformat(string)</h3>
<p>parse a given number formatted string and return its numerical value.</p>
<h3>Joss Crowcroft&#8217;s Original Blog Announcment is here:</h3>
<p><a href="http://www.josscrowcroft.com/2011/code/my-weekend-project-accounting-js/">http://www.josscrowcroft.com/2011/code/my-weekend-project-accounting-js/<br /></a></p>
<h3>And the GitHub site is here:</h3>
<h3><span style="font-weight: normal; font-size: medium;"><a href="https://github.com/josscrowcroft/accounting.js">https://github.com/josscrowcroft/accounting.js</a></span></h3>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/08/22/accounting-js-a-handy-formatting-library-for-numbers-and-finance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

