<?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>Bubble Foundry</title>
	<atom:link href="http://www.bubblefoundry.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bubblefoundry.com</link>
	<description></description>
	<lastBuildDate>Wed, 03 Mar 2010 10:45:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel='hub' href='http://www.bubblefoundry.com/?pushpress=hub'/>
		<item>
		<title>Aggregation Strategies</title>
		<link>http://www.bubblefoundry.com/blog/2010/03/aggregation-strategies/</link>
		<comments>http://www.bubblefoundry.com/blog/2010/03/aggregation-strategies/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 10:45:58 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[aggregate.js]]></category>
		<category><![CDATA[aggregation]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[samples]]></category>
		<category><![CDATA[sampling]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=326</guid>
		<description><![CDATA[How do you find the minimum, maximum, and average of values of a set of samples over time? What if some of your data sources are unreliable and prone to drop in and out? Should you group them into regular buckets, even if that may mean multiple samples from source A and none from source [...]]]></description>
			<content:encoded><![CDATA[<p>How do you find the minimum, maximum, and average of values of a set of samples over time? What if some of your data sources are unreliable and prone to drop in and out? Should you group them into regular buckets, even if that may mean multiple samples from source A and none from source B? Or should you calculate instantaneous aggregate numbers whenever a new sample comes in at the expense of having as many aggregate points as samples and potentially unevenly distributed across time? Are there better ways?</p>
<p>In the end I hacked up a simple library, <a href="http://github.com/pr1001/aggregate.js">aggregate.js</a>, to test various strategies using <a href="http://nodejs.org">Node</a>. Right now I just have the two basic windowing and instantaneous strategies implemented, but I plan on adding more as needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2010/03/aggregation-strategies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Constructors with an Array of Parameters</title>
		<link>http://www.bubblefoundry.com/blog/2010/03/javascript-constructors-with-an-array-of-parameters/</link>
		<comments>http://www.bubblefoundry.com/blog/2010/03/javascript-constructors-with-an-array-of-parameters/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 08:54:54 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[constructors]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=321</guid>
		<description><![CDATA[Say we have:

function myObj&#40;&#41; &#123;
  this.input = Array.prototype.slice.call&#40;arguments&#41;;
&#125;

We can pass a variable or an array but :

var myObj1 = new myObj&#40;1&#41;;
myObj1.input // -&#62; [1]
var myArr = &#91;1, 2, 3&#93;;
var myObj2 = new myObj&#40;myArr&#41;;
myObj2.input // -&#62; [[1, 2, 3]]

How then can we get, while still using myArr:

myObj3.input // -&#62; [1, 2, 3]

Here&#8217;s how, courtesy of [...]]]></description>
			<content:encoded><![CDATA[<p>Say we have:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> myObj<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;">input</span> <span style="color: #339933;">=</span> Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We can pass a variable or an array but :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myObj1 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> myObj<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myObj1.<span style="color: #660066;">input</span> <span style="color: #006600; font-style: italic;">// -&gt; [1]</span>
<span style="color: #003366; font-weight: bold;">var</span> myArr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> myObj2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> myObj<span style="color: #009900;">&#40;</span>myArr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myObj2.<span style="color: #660066;">input</span> <span style="color: #006600; font-style: italic;">// -&gt; [[1, 2, 3]]</span></pre></div></div>

<p>How then can we get, while still using myArr:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">myObj3.<span style="color: #660066;">input</span> <span style="color: #006600; font-style: italic;">// -&gt; [1, 2, 3]</span></pre></div></div>

<p>Here&#8217;s how, courtesy of <a href="http://www.ozoneasylum.com/30593">this site</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myObj3 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> myObj<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myObj.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>myObj3<span style="color: #339933;">,</span> myArr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note that <code>myObj3</code> needn&#8217;t be an instance of <code>myObj</code>, it just needs to be an <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Function/Apply#Parameters">existing value</a> so that the global object isn&#8217;t used as the value of <code>this</code>.</p>
<p>This is pretty cool, though of couse you can do it much easier in languages such as Scala:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">val</span> myObj4 <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> myObj<span style="color: #F78811;">&#40;</span>myArr<span style="color: #000080;">:</span> <span style="color: #000080;">_*</span><span style="color: #F78811;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2010/03/javascript-constructors-with-an-array-of-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Primitives</title>
		<link>http://www.bubblefoundry.com/blog/2010/02/javascript-primitives/</link>
		<comments>http://www.bubblefoundry.com/blog/2010/02/javascript-primitives/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 12:10:08 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[immutability]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[primitives]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=319</guid>
		<description><![CDATA[From the Mozilla Javascript Glossary:
primitive, primitive value
A data that is not an object and does not have any methods. JavaScript has 5 primitive datatypes: string, number, boolean, null, undefined. With the exception of null and undefined, all primitives values have object equivalents which wrap around the primitive values, e.g. a String object wraps around a [...]]]></description>
			<content:encoded><![CDATA[<p>From the <a href="https://developer.mozilla.org/en/JS/Glossary">Mozilla Javascript Glossary</a>:</p>
<blockquote><p>primitive, primitive value<br />
A data that is not an object and does not have any methods. JavaScript has 5 primitive datatypes: string, number, boolean, null, undefined. With the exception of null and undefined, all primitives values have object equivalents which wrap around the primitive values, e.g. a String object wraps around a string primitive. All primitives are immutable.</p></blockquote>
<p>Did you know that all Javascript primatives are immutable? I sure didn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2010/02/javascript-primitives/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Artvertentie</title>
		<link>http://www.bubblefoundry.com/blog/2010/02/artvertentie/</link>
		<comments>http://www.bubblefoundry.com/blog/2010/02/artvertentie/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 04:41:39 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Artvertentie]]></category>
		<category><![CDATA[caseclass.js]]></category>
		<category><![CDATA[Steganographia 2.0]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=315</guid>
		<description><![CDATA[At the end of last year I found myself with a bunch of advertising credit for the Amsterdam newspaper Het Parool and no pressing need to advertise my business (you&#8217;re already here on the Bubble Foundry blog, right?). So, my friends and I decided to have some fun and make it into an art project, [...]]]></description>
			<content:encoded><![CDATA[<p>At the end of last year I found myself with a bunch of advertising credit for the Amsterdam newspaper Het Parool and no pressing need to advertise my business (you&#8217;re already here on the Bubble Foundry blog, right?). So, my friends and I decided to have some fun and make it into an art project, which we called <a href="http://artvertentie.com/">Artvertentie</a>. In the January 2, 2010 issue of the newspaper&#8217;s Saturday magazine we had ads throughout the magazine showing our artworks where ads would normally be. My contribution, <a href="http://artvertentie.com/bubblefoundry.html">Steganographia 2.0</a>, in an ASCII art version of the Bubble Foundry logo based upon an encoded version of <a href="http://github.com/pr1001/caseclass.js">caseclass.js</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2010/02/artvertentie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My latest Scala-inspired Javascript library: pf.js</title>
		<link>http://www.bubblefoundry.com/blog/2010/02/my-latest-scala-inspired-javascript-library-pf-js/</link>
		<comments>http://www.bubblefoundry.com/blog/2010/02/my-latest-scala-inspired-javascript-library-pf-js/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 04:26:46 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[partial functions]]></category>
		<category><![CDATA[pf.js]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=313</guid>
		<description><![CDATA[What is a function? While many use the words &#8216;method&#8217; and &#8216;function&#8217; interchangeably, more mathematically-inclined programmers make a distinction between functions and methods based on between you are guaranteed a return value. Scala is one programming language that makes a distinction between functions and methods (though it&#8217;s actually pretty easy to jump between the two). [...]]]></description>
			<content:encoded><![CDATA[<p>What is a function? While many use the words &#8216;method&#8217; and &#8216;function&#8217; interchangeably, more mathematically-inclined programmers make a distinction between <a href="http://en.wikipedia.org/wiki/Function_(mathematics)">functions</a> and <a href="http://en.wikipedia.org/wiki/Function_(computer_science)">methods</a> based on between you are guaranteed a return value. Scala is one programming language that makes a <a href="http://jim-mcbeath.blogspot.com/2009/05/scala-functions-vs-methods.html">distinction between functions and methods</a> (though it&#8217;s actually pretty easy to jump between the two). Great, just like plenty of other languages, nothing special here. Javascript functions are funny beasts. On one hand, they seem to be simple subroutines which can be passed arguments and can <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)">enclose</a> variables – pretty standard methods in other words. However, regardless of whether you include <code>return</code> statements in a function, <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference:Functions#General">something is actually returned</a>, <code>undefined</code> being returned if you hadn&#8217;t specified a return value. Hmm, so they&#8217;re kind of like mathematical methods except there&#8217;s no way to know without looking at a function&#8217;s source code whether the author failed to return a value for the input you gave it or actually did return something, the <code>undefined</code> object.</p>
<p>However, Scala also provides a middle ground with <a href="http://suereth.blogspot.com/2008/11/using-partial-functions-and-pattern.html">PartialFunctions</a>. PartialFunctions are cool because they are only defined for specific inputs and you can check this. In addition, because they are defined for specific inputs, you can combine several PartialFunctions to create a new PartialFunction which is defined for the union of all the original PartialFunctions&#8217; inputs. Wouldn&#8217;t it be cool if Javascript did that too? Well, now it can with <a href="http://github.com/pr1001/pf.js">pf.js</a>. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2010/02/my-latest-scala-inspired-javascript-library-pf-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Subtle Javascript Mistake</title>
		<link>http://www.bubblefoundry.com/blog/2010/01/a-subtle-javascript-mistake/</link>
		<comments>http://www.bubblefoundry.com/blog/2010/01/a-subtle-javascript-mistake/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 00:46:01 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=311</guid>
		<description><![CDATA[I was just pounding my head against what turned out to be a simple  Javascript misconception that I hope I can save people from: in tests for the existance of a key, not a value, in an object or array. So the following work:

  var myObj = &#123;1: &#34;one&#34;, 2: &#34;two&#34;&#125;
  1 [...]]]></description>
			<content:encoded><![CDATA[<p>I was just pounding my head against what turned out to be a simple  Javascript misconception that I hope I can save people from: <code>in</code> tests for the existance of a <em>key</em>, not a value, in an object or array. So the following work:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">var</span> myObj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;one&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;two&quot;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #CC0000;">1</span> <span style="color: #000066; font-weight: bold;">in</span> myObj <span style="color: #006600; font-style: italic;">// -&gt; true</span>
  <span style="color: #CC0000;">2</span> <span style="color: #000066; font-weight: bold;">in</span> myObj <span style="color: #006600; font-style: italic;">// -&gt; true</span>
  <span style="color: #003366; font-weight: bold;">var</span> myArr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>
  <span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">in</span> myArr <span style="color: #006600; font-style: italic;">// -&gt; true</span>
  <span style="color: #CC0000;">1</span> <span style="color: #000066; font-weight: bold;">in</span> myArr <span style="color: #006600; font-style: italic;">// -&gt; true</span></pre></div></div>

<p>But you might be surprised at the following results (I was):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #CC0000;">2</span> <span style="color: #000066; font-weight: bold;">in</span> myArr <span style="color: #006600; font-style: italic;">// -&gt; false</span></pre></div></div>

<p>That is because <code>myArr</code> has values <code>1</code> and <code>2</code> at keys <code>0</code> and <code>1</code>, respectively. To test the existence of a value in an array, you need to use <code>indexOf</code>. For instance:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  myArr.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// -&gt; 0</span>
  myArr.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// -&gt; 1</span>
  myArr.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;doesn't exist&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// -&gt; -1</span></pre></div></div>

<p>As you can see, <code>-1</code> indicates the value does not exist in the array.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2010/01/a-subtle-javascript-mistake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Case Classes</title>
		<link>http://www.bubblefoundry.com/blog/2009/12/introduction-to-case-classes/</link>
		<comments>http://www.bubblefoundry.com/blog/2009/12/introduction-to-case-classes/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 02:53:38 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[actor.js]]></category>
		<category><![CDATA[Actors]]></category>
		<category><![CDATA[case classes]]></category>
		<category><![CDATA[caseclass.js]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[match-js]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=305</guid>
		<description><![CDATA[I&#8217;ve been recently chatting with the creator of match-js about how his library and caseclass.js might work together and I ended up written quite a bit about case classes. Enjoy.
Scala is a newish object-oriented/functional hybrid language that runs on the JVM. It actually takes a lot of concepts from Erlang, such as its actor library. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been recently chatting with the creator of <a href="http://github.com/jfd/match-js">match-js</a> about how his library and <a href="http://github.com/pr1001/caseclass.js">caseclass.js</a> might work together and I ended up written quite a bit about case classes. Enjoy.</p>
<p>Scala is a newish object-oriented/functional hybrid language that runs on the JVM. It actually takes a lot of concepts from Erlang, such as its actor library. One of its key features is <a href="http://www.scala-lang.org/node/120">pattern matching</a>, which at the most basic can be used to test equality. With the match operator that means you have something like switch/case in most languages:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">val</span> myVal <span style="color: #000080;">=</span> <span style="color: #F78811;">3</span><span style="color: #000080;">;</span>
myVal <span style="color: #0000ff; font-weight: bold;">match</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #F78811;">1</span> <span style="color: #000080;">=&gt;</span> <span style="color: #6666FF;">&quot;one&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #F78811;">2</span> <span style="color: #000080;">=&gt;</span> <span style="color: #6666FF;">&quot;two&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #F78811;">3</span> <span style="color: #000080;">=&gt;</span> <span style="color: #6666FF;">&quot;three&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span> <span style="color: #6666FF;">&quot;other&quot;</span>
<span style="color: #F78811;">&#125;</span> <span style="color: #008000; font-style: italic;">// returns &quot;three&quot;</span></pre></div></div>

<p><a href="http://www.scala-lang.org/node/107">Case classes</a> at a glance are just simple classes that be created without the new operator and automatic getters and setters:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #0000ff; font-weight: bold;">class</span> Person<span style="color: #F78811;">&#40;</span>name, age<span style="color: #F78811;">&#41;</span>
<span style="color: #0000ff; font-weight: bold;">val</span> peter <span style="color: #000080;">=</span> Person<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Peter Robinett&quot;</span>, <span style="color: #F78811;">25</span><span style="color: #F78811;">&#41;</span>
peter.<span style="color: #000000;">age</span> <span style="color: #000080;">==</span> <span style="color: #F78811;">25</span> <span style="color: #008000; font-style: italic;">// -&gt; true</span></pre></div></div>

<p>However, you can do a lot more advanced stuff:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;">unknownVar <span style="color: #0000ff; font-weight: bold;">match</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> n<span style="color: #000080;">:</span> String <span style="color: #000080;">=&gt;</span> println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;unknowVar is a String with value: &quot;</span> + n<span style="color: #F78811;">&#41;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> n<span style="color: #000080;">:</span> Int <span style="color: #0000ff; font-weight: bold;">if</span> n <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">0</span> <span style="color: #000080;">=&gt;</span> println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;unknownVar is an Int with a value greater than 0&quot;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> Person<span style="color: #F78811;">&#40;</span>name, <span style="color: #F78811;">100</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;unknownVar is a Person case class where property age is 100 and name is: &quot;</span> + name<span style="color: #F78811;">&#41;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>The last case example shows a cool use of a case class. Scala knows that when a case class instance is created in a case, you are testing for matching. So, it calls the class&#8217;s unapply method (any class can have one, case classes just have them automatically) to compare the instance based upon its properties. If the parameters match, the two instances are equal. However, you can also not specify properties to match. If you don&#8217;t care about them all you can just give a wildcard (the <code>_</code> character) or not give any parameters (<code>case Person</code> or <code>case person: Person</code>) but if you&#8217;d like to extract the value, you can. This is what I did. By giving it the undefined variable &#8216;name&#8217;, it knows that I am not comparing the name properties but instead want to assign <code>unknownVar.name</code> to <code>name</code> (assuming that <code>unknownVar</code> is an instance of <code>Person</code>!), which is then within the scope of the subsequent code block.</p>
<p>So, that&#8217;s a lot of Scala. What do I have in Javascript? Right now you can match based upon object types:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">CaseClass.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Person&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;age&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> peter <span style="color: #339933;">=</span> CaseClass.<span style="color: #660066;">Person</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Peter Robinett&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
peter.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>
  <span style="color: #009900;">&#123;</span>
    caseTest<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span>
    caseFunction<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;">return</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>
    caseTest<span style="color: #339933;">:</span> CaseClass.<span style="color: #660066;">Person</span><span style="color: #339933;">,</span>
    caseFunction <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;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// -&gt; return 1 – I'm not a Car!</span></pre></div></div>

<p>Parameter definition and extraction also works, though it&#8217;s limited:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> undef<span style="color: #339933;">;</span>
peter.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>
  <span style="color: #009900;">&#123;</span>
    caseTest<span style="color: #339933;">:</span> CaseClass.<span style="color: #660066;">Person</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Barack Obama&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">47</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    caseFunction<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;">return</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>
    caseTest<span style="color: #339933;">:</span> CaseClass.<span style="color: #660066;">Person</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Peter Robinett&quot;</span><span style="color: #339933;">,</span> undef<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    caseFunction <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;">return</span> age<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// -&gt; return 25</span></pre></div></div>

<p>As you can see, matching works fine though I need pass an uninitialized variable to Person() to indicate that I want to extract the corresponding property in peter. Because I cannot discover the name of this variable, I just have to create variables based upon the property names. I&#8217;d like to improve this, but the consensus seems to be that it&#8217;s <a href="http://stackoverflow.com/questions/1879915/javascript-function-parameter-names-at-time-of-call/">impossible with Javascript today</a> (ironically, earlier versions could). Beyond extractors, I&#8217;d like to be able to do more complex matching (better support for different object types, conditional stations) and be able to extend native objects to support my matching. I also like that your <code>Match()</code> method can stand alone, letting it be used as a callback and meaning that it acts as a sort of partial function, which is very cool. In Scala partial functions are functions that needn&#8217;t always return a value:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">def</span> myPF<span style="color: #F78811;">&#40;</span>num<span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #F78811;">1</span> <span style="color: #000080;">=&gt;</span> <span style="color: #6666FF;">&quot;one&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">case</span> -<span style="color: #F78811;">1</span> <span style="color: #000080;">=&gt;</span> <span style="color: #6666FF;">&quot;negative one&quot;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>To be honest, I&#8217;m not sure if our libraries could or should work together but they&#8217;re similar enough in spirit that I thought it might be exploring how they can complement each other. I see you&#8217;re doing stuff with web workers. I&#8217;ve also tried to take Scala&#8217;s actors and use them to do something in Javascript. <a href="http://github.com/pr1001/actor.js">actor.js</a> is the result and is a place where I think case classes would be great for message passing (this is a key use case for case classes in Scala). However, actors are both more complex and something that I have less experience with, so I haven&#8217;t put as much time into it as caseclass.js. However, the demo does work and is, in my opinion, pretty cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2009/12/introduction-to-case-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP for Web Developers</title>
		<link>http://www.bubblefoundry.com/blog/2009/12/http-for-web-developers/</link>
		<comments>http://www.bubblefoundry.com/blog/2009/12/http-for-web-developers/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 08:39:17 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=302</guid>
		<description><![CDATA[I&#8217;m often surprised how little web developers know about the HTTP protocol. I&#8217;m by no means an expert (feel free to correct what I write in the comments!) but I think I know a fair bit and I&#8217;ll outline the basics here.
Why does it matter? What if you&#8217;re a frontend developer doing AJAX calls? How [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m often surprised how little web developers know about the HTTP protocol. I&#8217;m by no means an expert (feel free to correct what I write in the comments!) but I think I know a fair bit and I&#8217;ll outline the basics here.</p>
<p>Why does it matter? What if you&#8217;re a frontend developer doing AJAX calls? How do you know that the request succeeded? Do you check that the response text isn&#8217;t empty? The status code is 200? Neither is optimal, though luckily most <a href="http://api.prototypejs.org/ajax/ajax/request.html#success-instance_method">good</a> <a href="http://docs.jquery.com/Ajax/ajaxSuccess#callback">libraries</a> will take care of figuring it out.</p>
<p>At its most basic <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a> is a request and a response. Messages are divided into a group of headers and a single body. Each request has a <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods">method</a>, the most common of which are GET and POST. It will also indicate the host (e.g. http://www.google.com) and the document, which may simply be &#8216;/&#8217; (the host root) or &#8216;*&#8217; (a wildcard). There are a lot more headers that a HTTP request may include, but those are the bare minimum. Most requests will have an empty body, though POSTs and PUTs are normally specifically used to send content to the server in the request body. A request body will consist of key value pairs, with the text pairs <a href="http://en.wikipedia.org/wiki/URL_encoding">URL encoded</a> and binary data <a href="http://en.wikipedia.org/wiki/Base64">base64</a> encoded.</p>
<p>Response messages will at least consist of a <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">status code</a> header and there is usually a message body too. A HEAD request specifically indicates that the response should only include headers (they are treated as GET requests otherwise). Your standard response has a 200 status code header, some other headers describing when and how the request was served, and a body containing an HTML webpage.</p>
<p>As you may have noticed, HTTP methods are a set of verbs that let the client tell the server &#8216;give me this information&#8217; or &#8216;process this data&#8217;. Since each verb means a specific thing, you actually get a very defined and powerful little language. As I see it, it is this observation (among other things!) that is <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>. While they often aren&#8217;t, URLs are at their most powerful when they represent unique things. HTTP methods let us indicate what we want to do with them. So, GET /blog/ would indicate that we wanted to get the blog webpage, while POST /blog/ might indicate that we want to submit a new blog post. Likewise, GET /blog/2009/12/http-for-web-developers/ gets the post while PUT /blog/2009/12/http-for-web-developers/ sends an updated version of the post. As you see, we&#8217;re dealing with the same blog post, we&#8217;re just doing different things with it.</p>
<p>HTTP status codes are powerful things and in my opinion people often overlook the cool things you can do with the right request headers and response status codes. For instance, your average browser will often include headers in its requests indicating that it has requested the resource before (e.g. If-Modified-Since, If-None-Match) and, if based on those means of comparison the resource hasn&#8217;t changed, you can return a 304 response with an empty body and the client will use its cached version. Especially with binary data (images!) you can avoid lots of bandwidth usage, something especially useful for clients on slow (mobile!) connections.</p>
<p>One specific thing that I&#8217;d like to draw your attention to is requesting and serving feeds. Since a client may request it often looking for changes, you definitely want to be efficient about your responses. If-Modified-Since and If-None-Match are great but responses to the requests must be all or nothing: 200 or 304. If you&#8217;re returning a 200 code you must return the entire feed. But what if the user requested a feed of 500 items and only the last one was created since the If-Modified-Since date they sent? There is an <a href="http://www.ietf.org/rfc/rfc3229.txt">unofficial but somewhat supported</a> <a href="http://rakaz.nl/2006/12/reducing-the-bandwidth-used-by-feeds.html">set of headers called A-IM and IM</a>. The request includes the A-IM header with the value &#8216;feed&#8217;,  indicating that they understand the resouce is a feed and so can support partial responses based upon their request criteria. The server can return a 200 or 304 as normal but it can also take a middle ground: it can respond with a 226 status code and the IM header, again with the &#8216;feed&#8217; value, and only include the changed feed items in its body. Major savings!</p>
<p>One thing I should add is that dates are always a major pain in HTTP headers. The correct format is &#8216;Fri, 01 Jan 1990 00:00:00 GMT&#8217;. In printf format that&#8217;s &#8216;%a, %d %b %Y %H:%M:%S %Z&#8217;.</p>
<p>Both <a href="http://code.google.com/speed/page-speed/docs/rules_intro.html">Google</a> and <a href="http://developer.yahoo.com/performance/">Yahoo</a> have very <a href="http://developer.yahoo.com/yslow/">good</a> <a href="http://code.google.com/speed/page-speed/">tools</a> for monitoring HTTP requests. The <a href="http://developer.yahoo.com/">Yahoo Developer Network</a> has great articles on <a href="http://developer.yahoo.net/blog/archives/2009/10/a_engineers_gui.html">bandwidth</a> and <a href="http://developer.yahoo.com/performance/rules.html">speeding up websites</a>. Significant portions of this work at both companies have been due to <a href="http://stevesouders.com/">Steve Souders</a>. His books <a href="http://www.amazon.com/gp/product/0596529309?ie=UTF8&amp;tag=petsblo07-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596529309">High Performance Web Sites</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=petsblo07-20&amp;l=as2&amp;o=1&amp;a=0596529309" border="0" alt="" width="1" height="1" /> and <a href="http://www.amazon.com/gp/product/0596522304?ie=UTF8&amp;tag=petsblo07-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596522304">Even Faster Web Sites</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=petsblo07-20&amp;l=as2&amp;o=1&amp;a=0596522304" border="0" alt="" width="1" height="1" /> are great guides.</p>
<p>With all this I think you have more than enough to make strong, efficient HTTP clients and servers. Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2009/12/http-for-web-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML and XML Character Encoding Gotchas in Javascript</title>
		<link>http://www.bubblefoundry.com/blog/2009/12/html-and-xml-character-encoding-gotchas-in-javascript/</link>
		<comments>http://www.bubblefoundry.com/blog/2009/12/html-and-xml-character-encoding-gotchas-in-javascript/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 02:41:41 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[character encoding]]></category>
		<category><![CDATA[character entity references]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[UTF-8]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=299</guid>
		<description><![CDATA[Recently I was trying to execute the following Javascript with jQuery: $("#someid").append("&#60;div&#62;...&#38;deg;C&#60;/div&#62;");
I was going crazy because it worked (a degrees symbol – ° – was shown) on one page but not another, where nothing was displayed or returned by the append method. After much frustration I stumbled on a solution and I&#8217;m sharing it here [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was trying to execute the following Javascript with jQuery:<code> $("#someid").append("&lt;div&gt;...&amp;deg;C&lt;/div&gt;");</code></p>
<p>I was going crazy because it worked (a degrees symbol – ° – was shown) on one page but not another, where nothing was displayed or returned by the <code>append</code> method. After much frustration I stumbled on a solution and I&#8217;m sharing it here to hopefully save others some time.</p>
<p>I was stumped but luckily I ended up reading the <a href="http://en.wikipedia.org/wiki/Character_encodings_in_HTML">Wikipedia page on character encoding in HTML</a> and learned that XML has a <a href="http://en.wikipedia.org/wiki/Character_encodings_in_HTML#XML_character_entity_references">much smaller set of character entity references</a>. In fact, there are only five: <code>&amp;amp;</code> → &amp;, <code>&amp;lt;</code> → &lt;, <code>&amp;gt;</code> → &gt;, <code>&amp;quot;</code> → &#8220;, <code>&amp;apos;</code> → &#8216;. Makes sense, since you should be using UTF-8.</p>
<p>As it turns out, my working example was an HTML page while the non-working one was XHTML. Because of the XHTML content-type declaration the parser (I&#8217;m not sure whether in jQuery or my browser) was choking on the invalid character entity reference and failing completely. So, problem solved, though I wish the single offending entity was dropped, not the whole string!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2009/12/html-and-xml-character-encoding-gotchas-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TLDapi</title>
		<link>http://www.bubblefoundry.com/blog/2009/12/tldapi/</link>
		<comments>http://www.bubblefoundry.com/blog/2009/12/tldapi/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 09:51:32 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[TLDapi]]></category>
		<category><![CDATA[top level domains]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=297</guid>
		<description><![CDATA[I whipped TLDapi up in the last few days. If you&#8217;re a programmer and you want a way to check if an exotic top level domain a user sent you is real, use the API to check.
]]></description>
			<content:encoded><![CDATA[<p>I whipped <a href="http://tld-api.appspot.com/">TLDapi</a> up in the last few days. If you&#8217;re a programmer and you want a way to check if an exotic top level domain a user sent you is real, use the API to check.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2009/12/tldapi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
