<?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>JamesORJamesOR - JavaScript and ActionScript Enthusiast</title>
	<atom:link href="http://jamesor.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamesor.com</link>
	<description>JavaScript and ActionScript Enthusiast</description>
	<lastBuildDate>Fri, 19 Oct 2012 03:37:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Backbone.js demo</title>
		<link>http://jamesor.com/2012/10/backbone-js-demo/</link>
		<comments>http://jamesor.com/2012/10/backbone-js-demo/#comments</comments>
		<pubDate>Fri, 19 Oct 2012 03:37:50 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=555</guid>
		<description><![CDATA[I recently presented a demonstration of Backbone.js at http://nycoders.org/. The group meets every Wednesday night from 7-9pm in NYC at Think Coffee, 248 Mercer Street between 3rd and 4th avenues. All off the source code and slides can be found on Github.com https://github.com/jamesor/backbone-demo]]></description>
				<content:encoded><![CDATA[<p>I recently presented a demonstration of Backbone.js at <a title="NY Coders" href="http://nycoders.org/" target="_blank">http://nycoders.org/</a>. The group meets every Wednesday night from 7-9pm in NYC at Think Coffee, 248 Mercer Street between 3rd and 4th avenues.</p>
<p>All off the source code and slides can be found on Github.com<br />
<a href="https://github.com/jamesor/backbone-demo" target="_blank">https://github.com/jamesor/backbone-demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/10/backbone-js-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do you remember your first reaction to Node.js?</title>
		<link>http://jamesor.com/2012/05/first-reaction-to-node-js/</link>
		<comments>http://jamesor.com/2012/05/first-reaction-to-node-js/#comments</comments>
		<pubDate>Tue, 15 May 2012 11:47:00 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=544</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<div id="attachment_546" class="wp-caption aligncenter" style="width: 635px"><img src="http://jamesor.com/wp-content/uploads/2012/05/nodejs.jpg" alt="" title="First reaction to Node.js" width="625" height="1039" class="size-full wp-image-546" /><p class="wp-caption-text">Was your first reaction to Node.js anything like this one?</p></div>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/05/first-reaction-to-node-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TodosMVC with Backbone.js, Node.js and MongoDB</title>
		<link>http://jamesor.com/2012/04/todosmvc-backbone-nodejs-mongodb/</link>
		<comments>http://jamesor.com/2012/04/todosmvc-backbone-nodejs-mongodb/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 23:03:18 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Backbone.js]]></category>
		<category><![CDATA[Express]]></category>
		<category><![CDATA[Jade]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Mongoose]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Stylus]]></category>
		<category><![CDATA[TodosMVC]]></category>
		<category><![CDATA[Underscore.js]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=518</guid>
		<description><![CDATA[This demo was written to illustrate how a server-side JavaScript solution could be applied to the TodosMVC application. I used Underscore.js, Backbone.js, Node.js, Express, Jade, Stylus, Mongoose and MongoDB. Fork this project on Github A newer version using Socket.io and Redis for multi-user editing and record locking can be forked here on Github. Technologies Used [...]]]></description>
				<content:encoded><![CDATA[<p>This demo was written to illustrate how a server-side JavaScript solution could be applied to the TodosMVC application.  I used Underscore.js, Backbone.js, Node.js, Express, Jade, Stylus, Mongoose and MongoDB.</p>
<p><span id="more-518"></span></p>
<p><a href="https://github.com/jamesor/todomvc/tree/939bf7a47d297562cfb61c453320dea281e24e83/labs/architecture-examples/backbone_node_mongo" rel="nofollow">Fork this project on Github</a></p>
<p>A newer version using <strong>Socket.io</strong> and <strong>Redis</strong> for multi-user editing and record locking can be <a href="https://github.com/jamesor/backbone-boilerplates/tree/master/option7_node_socketio" rel="nofollow">forked here</a> on Github.</p>
<h3>Technologies Used In This Demo</h3>
<ul>
<li><a href="http://documentcloud.github.com/underscore/" rel="nofollow">Underscore.js</a> &#8211; A utility-belt library for JavaScript without extending any of the built-in JavaScript objects.</li>
<li><a href="http://documentcloud.github.com/backbone/" rel="nofollow">Backbone.js</a> &#8211; Gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.</li>
<li><a href="http://jquery.com/" rel="nofollow">jQuery</a> &#8211; A fast, concise, library that simplifies how to traverse HTML documents, handle events, perform animations, and add AJAX.</li>
<li><a href="http://nodejs.org/" rel="nofollow">Node.js</a> &#8211; Event-driven I/O server-side JavaScript environment based on V8.</li>
<li><a href="http://expressjs.com/" rel="nofollow">Express</a> &#8211; High performance, high class web development for node.js.</li>
<li><a href="http://jade-lang.com/" rel="nofollow">Jade</a> &#8211; High performance template engine heavily influenced by Haml and implemented with JavaScript for node.js.</li>
<li><a href="http://learnboost.github.com/stylus/" rel="nofollow">Stylus</a> &#8211; Expressive, dynamic, robust CSS for node.js</li>
<li><a href="http://mongoosejs.com/" rel="nofollow">Mongoose</a> &#8211; A MongoDB object modeling tool designed to work in an asynchronous environment.</li>
<li><a href="http://www.mongodb.org/" rel="nofollow">MongoDB</a> &#8211; A scalable, high-performance, open source NoSQL database.</li>
</ul>
<h3>Running the Demo</h3>
<ol>
<li>Install <a href="http://nodejs.org/#download" rel="nofollow">node.js</a>.</li>
<li>Install <a href="http://www.mongodb.org/downloads" rel="nofollow">MongoDB</a>.</li>
<li>Start the MongoDB server from a terminal window:
<pre class="prettyprint lang-html"><code>$ mongod</code></pre>
</li>
<li>Change the working directory to the project root:
<pre class="prettyprint lang-html"><code>$ cd &lt;path to todosmvc&gt;/labs/architecture-examples/backbone_node_mongo/</code></pre>
</li>
<li>Install dependencies using the node package manger (npm).
<pre class="prettyprint lang-html"><code>$ sudo npm link</code></pre>
</li>
<li>Start the Todos demo server from a different terminal window:
<pre class="prettyprint lang-html"><code>$ node app</code></pre>
</li>
<li>Visit <a href="http://localhost:3000" rel="nofollow">http://localhost:3000</a> in a web browser.</li>
</ol>
<h3>Interesting Parts</h3>
<p>Here are a few interesting parts of the project that I wanted to highlight.</p>
<h4>Create the Model Schema</h4>
<p>Working with Mongoose is awesome.  Simply define a schema that Mongoose will use to proxy the database.  I know MongoDB is a schemaless document store but the schema is for Mongoose to use.</p>
<pre class="prettyprint lang-js linenums"><code>var mongoose = require('mongoose'),

  TodoSchema = new mongoose.Schema({
    title: { 'type': String, 'default': 'empty todo...' },
    order: { 'type': Number },
    done: { 'type': Boolean, 'default': false }
  });

module.exports = mongoose.model('Todo', TodoSchema);
</code></pre>
<h4>Setting Up the Routers</h4>
<p>In order for Express to handle requests from the Backbone application routers must be set up to route RESTful URIs to handlers.  Backbone has a default URI schema so the Express router is created to match it.  The schema is as follow:</p>
<pre class="prettyprint lang-js"><code>POST /todo //CREATE
GET /todo/:id //READ
PUT /todo/:id //UPDATE
DELETE /todo/:id //DELETE
</code></pre>
<p>For example the READ handler looks like this in my utils/crudUtils.js file.</p>
<pre class="prettyprint lang-js linenums"><code>(function (exports) {

  "use strict";

  // List, Create, Update and Delete omitted for brevity
  // See full source on Github.

  //------------------------------
  // Read
  //
  // Generate and return a handler with an injected model
  function getReadController(model) {
    // Returning a closure so that the model can be stored
    // in this function's environment
    return function (req, res) {
      // Look in MongoDB for the record
      model.findById(req.params.id, function (err, result) {
        if (err) {
          res.send(409, err);
        } else {
          res.send(result);
        }
      });
    };
  }

  // Export function so it's accessible outside of this module
  exports.initRoutesForModel = function (options) {
    var app = options.app
      , model = options.model
      , path
      , pathWithId;

    // We can only set up routers if we have a reference to the
    // Express app we want to create them on and the model
    // we want to create them for
    if (!app || !model) {
      return;
    }

    // Generate the RESTful URIs we expect to see from Backbone
    path = options.path || '/' + model.modelName.toLowerCase();
    pathWithId = path + '/:id';

    app.get(path, getListController(model));         // List all Todos
    app.post(path, getCreateController(model));      // CREATE
    app.get(pathWithId, getReadController(model));   // READ
    app.put(pathWithId, getUpdateController(model)); // UPDATE
    app.del(pathWithId, getDeleteController(model)); // DELETE
  };

}(exports));
</code></pre>
<h3>Credit</h3>
<ul>
<li><a href="http://jgn.me/" rel="nofollow">Jérôme Gravel-Niquet</a> &#8211; Created original demo</li>
<li><a href="http://addyosmani.com/" rel="nofollow">Addy Osmani</a> &#8211; Cleanup, edits</li>
<li><a href="http://jamesor.com/" rel="nofollow">James O&#8217;Reilly</a> &#8211; Added server-side tech from node.js to MongoDB</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/04/todosmvc-backbone-nodejs-mongodb/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript Immediately Run Functions</title>
		<link>http://jamesor.com/2012/04/javascript-immediately-run-functions/</link>
		<comments>http://jamesor.com/2012/04/javascript-immediately-run-functions/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 05:53:37 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=427</guid>
		<description><![CDATA[Immediately run functions (IRF) provide a mechanism in JavaScript to encapsulate an environment and protect it from external tinkering. One obvious benefit is that you&#8217;re able to create private variables and functions by controlling the environment your code runs in. Baseline example Here is a simple example which declares the variable answer and assigns it [...]]]></description>
				<content:encoded><![CDATA[<p>Immediately run functions (IRF) provide a mechanism in JavaScript to encapsulate an environment and protect it from external tinkering.  One obvious benefit is that you&#8217;re able to create private variables and functions by controlling the environment your code runs in.</p>
<p><script type="text/javascript">// <![CDATA[
  var answer=42,aa,ex0,ex1,ex2;aa=function(a){alert("The answer is "+a)};ex0=function(){aa(answer);};ex1=function(){var a=function(){return 42}();aa(a)};(function(ctx){var answer=42;function ex1(){alert("The answer is " + answer)};ctx.ex1=ex1;}(window));
// ]]&gt;</script></p>
<h4>Baseline example</h4>
<p>Here is a simple example which declares the variable <code><span class="pln">answer</span></code> and assigns it the value <code><span class="lit">42</span></code>. Then, the example alerts a dynamic statement made from the String <code><span class="str">"The answer is "</span></code> and the current value of <code><span class="pln">answer</span></code>.  Go ahead and run this example now to see the alert.</p>
<pre class="prettyprint lang-html linenums"><code>&lt;script type="text/javascript"&gt;
var answer = 42;
function ex0() {
  alert("The answer is " + answer);
}
&lt;/script&gt;</code></pre>
<p><a href="javascript:ex0()">Run Example</a></p>
<p>Now let&#8217;s try and mutate the value of <code><span class="pln">answer</span></code>.  We&#8217;ll use the Firebug plugin for Firefox here, but this will also work using similar tools for Safari, Chrome and Internet Explorer.</p>
<p>Open Firebug now and click on the &#8220;DOM&#8221; tab as highlighted in the image below.  Next, scroll though the list looking for the variable <code><span class="pln">answer</span></code>.  Finally, scan over to the second column and edit the value by double-clicking it and changing it to something else.  After you&#8217;ve completed those steps try running this example again to see the alert message display a different statement than before.</p>
<p><img src="http://jamesor.com/wp-content/uploads/2012/04/irf-edit-dom.png"></p>
<p><span id="more-427"></span></p>
<h4>Immediately Run Function Example</h4>
<p>In this example, we wrap our code in an immediately ran function.  This is simply a normal anonymous (unnamed) function followed immediately by a set of parentheses to call the function immediately after defining it.  In this example, the function hasn&#8217;t been given a name so it will later be inaccessible by code(<a href="#fn1"><sup>1</sup></a>) because there are no stored references to it&#8217;s location in memory.</p>
<pre class="prettyprint lang-html linenums"><code>&lt;script type="text/javascript"&gt;
(function (ctx) {
  var answer = 42;
  function ex1() {
    alert("The answer is " + answer);
  }
  ctx.ex1 = ex1;
}(window));
&lt;/script&gt;</code></pre>
<p><a href="javascript:ex1()">Run Example</a></p>
<p>Inside the IRF we can see our previous example of declaring the variable <code><span class="pln">answer</span></code> and the function <code><span class="pln">ex1</span><span class="pun">()</span></code>.  In order to make the function <code><span class="pln">ex1</span><span class="pun">()</span></code> accessible outside of the IRF, a context is passed into the IRF to inject data into that we want to expose.  In this case, we want to expose the <code><span class="pln">ex1</span><span class="pun">()</span></code> function so it&#8217;s injected into the context (<code><span class="pln">cxt</span></code>).  The context, in this case the <code><span class="pln">window</span></code> object, is passed into the IRL as an argument.  That argument becomes the parameter <code><span class="pln">cxt</span></code> inside the function.  Therefore, <code><span class="pln">ex1</span><span class="pun">()</span></code> is being injected into the global object <code><span class="pln">window</span></code>.</p>
<p>Try looking for the variable <code><span class="pln">answer</span></code> using Firebug.  You won&#8217;t be able to see it because it&#8217;s hidden away inside the IRF.  You will be able to see the function <code><span class="pln">ex1</span><span class="pun">()</span></code> because it was intentionally injected into the global object <code><span class="pln">window</span></code>.</p>
<h4>Syntax</h4>
<p>Just for reference, here is the syntax of a JavaScript function.</p>
<pre class="prettyprint lang-html linenums"><code>&lt;script type="text/javascript"&gt;
(function <em>name</em>(<em>FormalParameterList</em>) {
  // function body
}(<em>FormalArgumentList</em>));
&lt;/script&gt;</code></pre>
<p><em>* Italic parts are optional</em></p>
<p><a name="fn1"></a></p>
<h4>Footnotes</h4>
<ol>
<li>Inaccessible by code, does not mean it&#8217;s safe from hackers.  A simple breakpoint placed inside a function will give a user using development tools like Firebug access to the scope in which the data lives.  Inaccessible by code means you need not worry about another JavaScript instruction changing the value because it&#8217;s unreachable.  This reduces the likelihood of hard to find bugs and a crowed global space.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/04/javascript-immediately-run-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://jamesor.com/2012/03/437/</link>
		<comments>http://jamesor.com/2012/03/437/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 04:20:45 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Apps]]></category>
		<category><![CDATA[Wares]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=437</guid>
		<description><![CDATA[I miss the day when my #apps were called #wares]]></description>
				<content:encoded><![CDATA[<p>I miss the day when my #apps were called #wares</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/03/437/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BrowserQuest massively multiplayer RPG written in HTML5 with Node.js</title>
		<link>http://jamesor.com/2012/03/browserquest-html5-nodejs/</link>
		<comments>http://jamesor.com/2012/03/browserquest-html5-nodejs/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 03:56:33 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Local Storage]]></category>
		<category><![CDATA[Media Queries]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Underscore.js]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=429</guid>
		<description><![CDATA[BrowserQuest is a classic style video game written in HTML5 and Javascript by LittleWorkshop and Mozilla. The game makes use of HTML5&#8242;s Web Workers to enable fast two-way communication between the browser and the server which is essential for a massively multiplayer game. This is achieved with HTML5 in the browser and Node.js server using [...]]]></description>
				<content:encoded><![CDATA[<p>BrowserQuest is a classic style video game written in HTML5 and Javascript by LittleWorkshop and Mozilla.</p>
<p>The game makes use of HTML5&#8242;s Web Workers to enable fast two-way communication between the browser and the server which is essential for a massively multiplayer game.  This is achieved with HTML5 in the browser and Node.js server using the websocket-server module.  HTML5&#8242;s localStorage is used to store your character&#8217;s progress.  The various graphics layers (background, characters, gui) are rendered to individual HTML5 canvases from a 2D engine.</p>
<p><span id="more-429"></span></p>
<p><script type="text/javascript" src="http://s3.amazonaws.com/s3.www.universalsubtitles.org/embed.js">
({"video_url": "http://www.youtube.com/watch?v=kYcNJQ3Y6Sg"})
</script></p>
<p>Links:</p>
<ul>
<li><a href="http://browserquest.mozilla.org" target="_ext" rel="nofollow">Begin Your Quest</a></li>
<li><a href="http://github.com/mozilla/BrowserQuest" target="_ext" rel="nofollow">Grab the Source on Github</a></li>
<li><a href="http://hacks.mozilla.org/2012/03/browserquest/" target="_ext" rel="nofollow">Learn More About the Technology</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/03/browserquest-html5-nodejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparing Apple to Apples</title>
		<link>http://jamesor.com/2012/03/apple-to-apples/</link>
		<comments>http://jamesor.com/2012/03/apple-to-apples/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 03:00:16 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=367</guid>
		<description><![CDATA[A beautiful infographic by mbaonline comparing the Apple computer company to the apple fruit industry. Created by: MBAOnline.com]]></description>
				<content:encoded><![CDATA[<p>A beautiful infographic by mbaonline comparing the Apple computer company to the apple fruit industry.</p>
<p><span id="more-367"></span></p>
<p><a href="http://www.mbaonline.com/apple-to-apples/"><img src="http://data.mbaonline.com.s3.amazonaws.com/applesvsapples.gif" alt="Apple to Apples" width="100%" border="0" /></a><br />
Created by: <a href="http://www.mbaonline.com/">MBAOnline.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/03/apple-to-apples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Douglas Adams, “Mostly Harmless”</title>
		<link>http://jamesor.com/2012/03/universe-was-created/</link>
		<comments>http://jamesor.com/2012/03/universe-was-created/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 02:03:28 +0000</pubDate>
		<dc:creator>James O'Reilly</dc:creator>
				<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Bad Move]]></category>
		<category><![CDATA[Douglas Adams]]></category>
		<category><![CDATA[Universe]]></category>

		<guid isPermaLink="false">http://jamesor.com/?p=389</guid>
		<description><![CDATA[“In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.”]]></description>
				<content:encoded><![CDATA[<p>“In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.”</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesor.com/2012/03/universe-was-created/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
