<?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>Stephen Belanger &#187; Javascript</title>
	<atom:link href="http://stephenbelanger.com/category/web-programming/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://stephenbelanger.com</link>
	<description>Just another coder making the web a better place.</description>
	<lastBuildDate>Fri, 18 Nov 2011 20:46:11 +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>Finally open-sourced some new stuff</title>
		<link>http://stephenbelanger.com/2011/06/13/finally-open-sourced-some-new-stuff/</link>
		<comments>http://stephenbelanger.com/2011/06/13/finally-open-sourced-some-new-stuff/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 02:36:11 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery.droploader]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[real-time]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[xhr]]></category>

		<guid isPermaLink="false">http://stephenbelanger.com/2011/06/13/finally-open-sourced-some-new-stuff/</guid>
		<description><![CDATA[Express-asset, Jquery-droploader and Chattan--three awesome new projects I just open-sourced.]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/qard/express-asset">Express-asset</a></p>
<p>A handy middleware utility for node.js and express to queue scripts and styles to be rendered later. Supports supplying javascript via anonymous functions to avoid multi-line string issues and also has built-in minification, which can be enabled when you render the scripts.</p>
<p><a href="http://github.com/qard/chattan">Chattan</a></p>
<p>This is the expanded source of the chat demo I made for my Node.js presentation at OKDG. I added CouchDB user persistence, S3-backed file uploading and also inline media embedding via another open-source project of mine called <a href="http://github.com/qard/embedify">Embedify</a>.</p>
<p><a href="http://github.com/qard/jquery-droploader">Jquery-droploader</a></p>
<p>A jquery plugin for xhr-based upload management with support for drag-and-drop regions. I used this for handling file uploads to S3 in Chattan.</p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=180&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2011/06/13/finally-open-sourced-some-new-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An eventful week&#8230;</title>
		<link>http://stephenbelanger.com/2011/04/22/an-eventful-week/</link>
		<comments>http://stephenbelanger.com/2011/04/22/an-eventful-week/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 04:17:26 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Game Programming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[Peint]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Canvas. Yammer]]></category>
		<category><![CDATA[Chattan]]></category>
		<category><![CDATA[DuoStack]]></category>
		<category><![CDATA[Galaxy S]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[Opzi]]></category>
		<category><![CDATA[PlayBook]]></category>
		<category><![CDATA[San Francisco]]></category>
		<category><![CDATA[Startup]]></category>
		<category><![CDATA[TechCrunch]]></category>

		<guid isPermaLink="false">http://stephenbelanger.com/?p=158</guid>
		<description><![CDATA[It's been an interesting week so far. I had a job interview at Yammer in San Francisco on Tuesday morning, so I was to fly out from Kelowna on Monday.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been an interesting week so far. I had a job interview at Yammer in San Francisco on Tuesday morning, so I was to fly out from Kelowna on Monday. My passport however, had expired. I ended up having to drive to Vancouver through the middle of the night and go to the passport office there at 7:30AM Monday morning. The process would take awhile, so I slept in the van for a few hours while I waited and hoped. They managed to have the passport put together just in time for me to pick it up and go straight to the airport.</p>
<p>Eventually I made it to San Francisco, but the problems still hadn&#8217;t ended. From the airport I took a shuttle&#8230;to the wrong hotel. Then I caught a cab to the right one. Finally at my hotel, I checked in and went up to my room. Much to my dismay however, their internet login system doesn&#8217;t work with Linux so my &#8220;complimentary&#8221; internet went entirely to waste. I had to resort to my Galaxy S for checking emails&#8211;no doubt my next bill is going to be scary expensive. In typical hotel fashion, they charge you to do pretty much anything but sleep, so I slept.</p>
<p>The next day was somewhat better. I was to meet at the Yammer HQ, in the same building as TechCrunch, for a few hours at 10AM. Checkout time at the hotel was noon, so I had to pack my luggage along with me. I quickly packed up my things and took a cab over to their offices, which were just a few minutes away.</p>
<p>The interview seemed to go pretty well, hopefully I can get the job because they&#8217;d be a pretty awesome crew to work with. There was several sets of interviews with people from the various teams at Yammer. They asked me various questions about Javascript to test my knowledge, which was refreshing&#8211;sometimes I just get disregarded because of my lack of formal training. Most of the questions were pretty easy but there was a few things that they were a bit vague about so it took a bit of prodding to figure out what exactly they were fishing for. Overall the interview seemed to go over pretty well though. I got to share a tasty catered lunch with them too.</p>
<p>After the interview I basically stepped outside the office, jumped into a cab and went straight to the airport. It was a much smoother exit from San Francisco than the entrance. There was a stop in Seattle though that was a bit on the long side. I sat at the gate for my next flight for about 3 hours. Fortunately there is plenty to do at the Seatac airport, so I managed to keep myself entertained. I got to try out a PlayBook while I was there, which was neat. I can kind of see where people are coming from about the complaints of it being &#8220;incomplete&#8221;, but it&#8217;s still a pretty neat piece of tech. I think application development should make it a pretty exciting platform.</p>
<p>Anyway, eventually I got back to Kelowna and finally got the sleep I had been longing for since Monday morning. I slept until almost noon on Wednesday, which I haven&#8217;t done in awhile. But eventually I felt compelled to get up and get some programming in. I wanted to get some more work done on the game engine I&#8217;ve been working on for a web game I&#8217;ve been making. I made a few updates to my Actor class to add RM2K support and animations, so I decided I&#8217;d do some benchmarks. I managed to get 484 unique Actors on a grass-tiled screen at 1920&#215;968 before it the rendering started to drop below 30 fps. That&#8217;s some pretty decent performance. Now I need to work on layer grouping and pre-rendering so I&#8217;m not drawing each tile of each layer for every frame. I&#8217;m convinced I can actually make an infinite scrolling tilemap render fast enough to be viable for large scale game development.</p>
<p>Thursday morning was the second Evoke Game Group meeting. Unfortunately there was only three of us this time&#8211;the weather was a bit ugly and I think there was a bit of confusion with moving the meet to Thursday because of Good Friday. It should pick up again for the next meet though. I&#8217;ve got a few people who&#8217;ve invited some programmers to join us, so I&#8217;m optimistic that I can get a hacknight going soon. I&#8217;ll keep my fingers crossed.</p>
<p>Today was more game dev stuff and deploying Chattan to DuoStack. Hopefully I can get Cloudant working too so I can deploy another secret project I&#8217;ve been working on. Cloudant was one of the many SaaS companies hit hard by the EC2 outage today. Hopefully they recover soon, it&#8217;s a pretty awesome service. I also got a few more calls from some web companies in San Francisco, including Opzi; one of the startups presented at this years TechCrunch Disrupt. They are somewhat smaller than Yammer, but it sounds like they are trying to do some pretty neat stuff. I can&#8217;t wait to see where that goes.</p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=158&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2011/04/22/an-eventful-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple explanation of &#8220;new&#8221; in Javascript.</title>
		<link>http://stephenbelanger.com/2011/04/10/a-simple-explanation-of-new-in-javascript/</link>
		<comments>http://stephenbelanger.com/2011/04/10/a-simple-explanation-of-new-in-javascript/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 22:12:40 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Browsers & Compatibility]]></category>
		<category><![CDATA[Web Programming]]></category>

		<guid isPermaLink="false">http://stephenbelanger.com/?p=162</guid>
		<description><![CDATA[There is a major feature of Javascript that is sorely misunderstood--the "new" keyword. Using the "new" keyword when declaring a variable will assign it's value to the state of "this" upon completion of the function. Not using "new" will simply assign it's value to the return value, or 'undefined' if nothing was returned. I wrote a simple example below to illustrate the effects of using the new keyword.]]></description>
			<content:encoded><![CDATA[<p>There is a major feature of Javascript that is sorely misunderstood&#8211;the &#8220;new&#8221; keyword. Using the &#8220;new&#8221; keyword when declaring a variable will assign it&#8217;s value to the state of &#8220;this&#8221; upon completion of the function. Not using &#8220;new&#8221; will simply assign it&#8217;s value to the return value, or &#8216;undefined&#8217; if nothing was returned. I wrote a simple example below to illustrate the effects of using the new keyword.</p>
<pre class="prettyprint lang-javascript">function Test(name){
    this.test = function(){
        return 'This will only work through the "new" keyword.';
    }
    return name;
}

var test = new Test('test');
test instanceof Test; // returns true
test.test(); // returns 'This will only work through the "new" keyword.'
test // returns the instance object of the Test() function.

var test2 = Test('test');
test2 instanceof Test; // returns false
test2.test(); // throws TypeError: Object #&lt;Test&gt; has no method 'test'
test2 // returns 'test'</pre>
<p>As Andrew kindly pointed out; if you return an object the resulting value will be an instance of the returned object rather than the constructor.</p>
<pre class="prettyprint lang-javascript">function Test(name){
    this.test = function(){
        return 'This will only work through the "new" keyword.';
    }
    return {name:name};
}

var test = new Test('test');
test instanceof Test; // returns false
test2.test(); // throws TypeError: Object #&lt;Test&gt; has no method 'test'
test // returns {name:'test'}.</pre>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=162&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2011/04/10/a-simple-explanation-of-new-in-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Peint Update!</title>
		<link>http://stephenbelanger.com/2011/04/04/peint-update/</link>
		<comments>http://stephenbelanger.com/2011/04/04/peint-update/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 23:20:03 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Peint]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://stephenbelanger.com/?p=156</guid>
		<description><![CDATA[At last, Peint is usable enough to be called &#8220;beta&#8221; software. I was working on other things for awhile so it took a bit of time to get back to it. I&#8217;ve made many changes including; - Moved module system parts into a separate Utils library, which can easily attach the module system to any [...]]]></description>
			<content:encoded><![CDATA[<p>At last, Peint is usable enough to be called &#8220;beta&#8221; software. I was working on other things for awhile so it took a bit of time to get back to it.</p>
<p>I&#8217;ve made many changes including;<br />
- Moved module system parts into a separate Utils library, which can easily attach the module system to any object<br />
- Changed Peint.image.load() to allow for multiple loading in the same way as Peint.require()<br />
- Changed Peint.require() and Peint.image.load() callbacks to use arguments, rather than this.property<br />
- Add region module to allow defining of events based on regions of the screen. Used for buttons and such.</p>
<p>As usual, the current demo is viewable at <a title="peint.stephenbelanger.com" href="http://peint.stephenbelanger.com" target="_blank">peint.stephenbelanger.com</a> and the code is available on <a title="github.com/qard/peint" href="http://github.com/qard/peint" target="_blank">Github</a>.</p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=156&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2011/04/04/peint-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let&#8217;s chat about node.js</title>
		<link>http://stephenbelanger.com/2010/12/01/lets-chat-about-nodejs/</link>
		<comments>http://stephenbelanger.com/2010/12/01/lets-chat-about-nodejs/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 19:44:27 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[expressjs]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[okdg]]></category>

		<guid isPermaLink="false">http://stephenbelanger.com/?p=117</guid>
		<description><![CDATA[Last night I had the pleasure of presenting on <a href="http://nodejs.org">node.js</a> at the November <a href="http://okdg.org">OKDG</a> meet. It was a lot of fun, and there seemed to be quite a bit of interest in the technology. Well, now I've got the slideshow available in PDF form for all to see. :)

Not only that, the chat demo created in the presentation will remain live for all to play with. In addition to what was covered in the presentation, it also has a basic message filtering system to convert URLs to embedded content. Try posting a URL to an image, Youtube video or PDF and you can see it in action. <a href="http://chat.stephenbelanger.com">Check it out!</a>]]></description>
			<content:encoded><![CDATA[<p>Last night I had the pleasure of presenting on <a href="http://nodejs.org">node.js</a> and <a href="http://socket.io">socket.io</a> at the November <a href="http://okdg.org">OKDG</a> meet. It was a lot of fun, and there seemed to be quite a bit of interest in the technology. Well, now I&#8217;ve got the slideshow available in PDF form for all to see. <img src='http://stephenbelanger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Not only that, the chat demo created in the presentation will remain live for all to play with. In addition to what was covered in the presentation, it also has a basic message filtering system to convert URLs to embedded content. Try posting a URL to an image, Youtube video or PDF and you can see it in action. <a href="http://chat.stephenbelanger.com">Check it out!</a></p>
<p><iframe src="http://docs.google.com/gview?url=http://stephenbelanger.com/wp-content/uploads/2010/12/Let__s_chat_about_node_js1.pdf&amp;embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe><a href='http://stephenbelanger.com/wp-content/uploads/2010/12/Let__s_chat_about_node_js1.pdf'>Download as PDF</a></p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=117&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2010/12/01/lets-chat-about-nodejs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Peint &#8211; Event-based canvas drawing, yay!</title>
		<link>http://stephenbelanger.com/2010/09/14/peint-event-based-canvas-drawing-yay/</link>
		<comments>http://stephenbelanger.com/2010/09/14/peint-event-based-canvas-drawing-yay/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 05:00:38 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Peint]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Browsers & Compatibility]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.stephenbelanger.com/?p=112</guid>
		<description><![CDATA[I did a bunch of work on Peint today, refactoring it to something that I might actually consider good enough to release. On that note; Peint enters alpha as of now!]]></description>
			<content:encoded><![CDATA[<p>I did a bunch of work on Peint today, refactoring it to something that I might actually consider good enough to release. On that note; Peint enters alpha as of now! <a href="http://peint.stephenbelanger.com/peint.zip">Get it here</a>. It won&#8217;t blow up your computer! &#8230;I hope.</p>
<p>No documentation yet, but you can look at the updated sample code at <a href="http://peint.stephenbelanger.com">peint.stephenbelanger.com</a> to get an idea of what this thing is capable of. It&#8217;s pretty neat. <img src='http://stephenbelanger.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=112&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2010/09/14/peint-event-based-canvas-drawing-yay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peint &#8211; Painting to canvas made easy!</title>
		<link>http://stephenbelanger.com/2010/09/13/peint-painting-to-canvas-made-easy/</link>
		<comments>http://stephenbelanger.com/2010/09/13/peint-painting-to-canvas-made-easy/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 19:37:04 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Peint]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Browsers & Compatibility]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.stephenbelanger.com/?p=106</guid>
		<description><![CDATA[As I mentioned in my previous post, I have been working on a graphics rendering library for the html5 canvas element. Peint is an attempt to make using canvas easier and more flexible, while introducing event-based programming. You include only core library and then use Peint.require('yourscript', callback) to asynchronously load extra modules and execute the callback code once the module is ready. Using this method, http requests are made smaller and occur after page load, so execution appears near instant--no waiting for 100+ kb of code to download before the system starts setting itself up. :)]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my previous post, I have been working on a graphics rendering library for the html5 canvas element. Peint is an attempt to make using canvas easier and more flexible, while introducing event-based programming. You include only the core library and then use Peint.require(&#8216;yourscript&#8217;, callback) to asynchronously load extra modules and execute the callback code once the module is ready. Using this method, http requests are made smaller and occur after page load, so execution appears near instant&#8211;no waiting for 100+ kb of code to download before the system starts setting itself up. <img src='http://stephenbelanger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In the previous post, I showed you the viewport module, which allowed me to dynamically resize the canvas to cover the entire viewport and adjust itself automatically whenever the window is resized. This time I&#8217;ll be introducing part of the draw2d module. Canvas uses the fillRect() method to fill a rectangular area with a particular color, but it only suppports the standard pixel coordinates from a top left origin. I decide that wasn&#8217;t good enough for me.</p>
<p>In the example below, we fill the background with a pleasant blue color, and we draw 2 boxes using a mix of numeric pixel coordinates, css-style &#8217;100px&#8217; coordinates and even percentages. In addition to that, it also demonstrates positioning from a non-top/left origin! The canvas.coords() positioning system dynamically tranforms the input values using their key names and the current dimensions of the canvas, allowing lots of flexibility in element positioning. I have a neat demo showing the fill() and image() methods online here; <a href="http://peint.stephenbelanger.com">peint.stephenbelanger.com</a></p>
<pre class="prettyprint">
// Initialize our canvas screen.
var screen = Peint.init('#screen');

// Load draw2d module for basic 2D drawing tools.
Peint.require('draw2d', function(){
	var canvas = this;

	// Draw our background color.
	canvas.fill(canvas.rgb(0,100,130));

	// Draw some boxes...
	// This one is statically positioned with pixels.
	// 'px' is optional, it will assume that on numbers.
	canvas.fill(
		canvas.rgba(150,200,0,0.8)
		, canvas.coords({
			right:150
			, bottom:150
			, width:'100px'
			, height:'100px'
		})
	);
	// This one is dynamically positioned with percentages.
	canvas.fill(
		canvas.rgba(200,150,0,0.8)
		, canvas.coords({
			left:'2%'
			, top:'5%'
			, width:'15%'
			, height:'50%'
		})
	);
});
</pre>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=106&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2010/09/13/peint-painting-to-canvas-made-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On canvas, and how to use it well.</title>
		<link>http://stephenbelanger.com/2010/09/12/on-canvas-and-how-to-use-it-well/</link>
		<comments>http://stephenbelanger.com/2010/09/12/on-canvas-and-how-to-use-it-well/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 00:20:26 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Peint]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Browsers & Compatibility]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.stephenbelanger.com/?p=101</guid>
		<description><![CDATA[All day I have been working on a graphics library for html5's canvas element,  and I've come to the conclusion that it is not particularly easy to use "as-is" in more involved applications.]]></description>
			<content:encoded><![CDATA[<p>I have been working on a graphics library for html5&#8242;s canvas element lately, and I&#8217;ve come to the conclusion that it is not particularly easy to use &#8220;as-is&#8221; in more involved applications. I suppose that should be expected, it being such new technology and all, so I thought I&#8217;d share some of my experiences, insights and progress on this endeavor.</p>
<p>First of all, canvas doesn&#8217;t play nice with CSS width and height dimensions. Rather than adjusting the usable area like one might expect, it stretches the element while retaining the buffer size of the render area. That means making it &#8220;100%&#8221; width/height becomes needlessly difficult. That is one of the many things the library I&#8217;m working on is meant to handle. Here&#8217;s a code sample to show it forcing the canvas dimensions by using a &#8220;resize&#8221; event in my library.</p>
<pre class="prettyprint">
// Load viewport module.
Peint.require('viewport', function(){
	var viewport = this;

	// Initialize our canvas screen.
	screen = Peint.init('#screen');

	// Create onresize handler.
	var resizer = function(){
		// Get current viewport dimensions.
		var size = viewport.size();

		// Position and resize it.
		screen.position().resize(size);
	};

	// Attach handler to resize and load event of window.
	this.bind('resize', resizer);
	this.bind('load', resizer);
});
</pre>
<p>What this does, is create a callback function to attach to window.onresize and window.onload (Actually, window.onload doesn&#8217;t exist, so it fakes it). Every time this event is called, it repositions the element on the screen and resizes it to match the viewport size. As you&#8217;ve probably figured out by the Peint.require() with the callback, this library supports loading external modules with callbacks to run when the code is ready. It&#8217;s pretty neat. I&#8217;ll share more as I complete the modules.</p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=101&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2010/09/12/on-canvas-and-how-to-use-it-well/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Node.js &#8211; I&#8217;m a fanboy already.</title>
		<link>http://stephenbelanger.com/2010/02/17/node-js-im-a-fanboy-already/</link>
		<comments>http://stephenbelanger.com/2010/02/17/node-js-im-a-fanboy-already/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 03:31:46 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[narwhal]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[v8]]></category>
		<category><![CDATA[v8cgi]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://www.stephenbelanger.com/2010/02/17/node-js-im-a-fanboy-already/</guid>
		<description><![CDATA[About a week ago I discovered a unique new programming technology called <a href="http://nodejs.org/">node.js</a>. It's an event-driven javascript system running on Google's V8 engine and is primarily focused on functioning as a web server. I hesitate to call it a web server however--it's much more than that!]]></description>
			<content:encoded><![CDATA[<p>About a week ago I discovered a unique new programming technology called <a href="http://nodejs.org/">node.js</a>. It&#8217;s an event-driven javascript system running on Google&#8217;s V8 engine and is primarily focused on functioning as a web server. I hesitate to call it a web server however&#8211;it&#8217;s much more than that!</p>
<p>Using this amazing new system I was able to integrate support for the new WebSockets specification that Google recently added support for in Chrome, and I used this to make a simple real-time chat application with emoticon support and translation of image links to inline images and youtube links to inline videos.</p>
<p>&#8230;and the best part? This only took me about an hour!</p>
<p>There are some simple architectural differences that make it vastly more powerful that most any other popular web programming languages. One of my favorite characteristics of it&#8217;s unique design is that variables assigned in a global scope can be accessed across all requests&#8230;that means regular database querying becomes completely unnecessary! You could create a json object where you store your data, then check it over every once in awhile, and apply any changes to the database. It&#8217;d work as a query queue of sorts that would greatly reduce database interaction overhead and it wouldn&#8217;t require setting up some other incredibly complex software to proxy the requests!</p>
<p>I&#8217;m also quite fond of the branching design. There is a module called &#8216;http&#8217; for running web servers, but it&#8217;s really just routing everything through the tcp module, which essentially does the same thing. The &#8216;http&#8217; module just simplifies the interface and makes common actions like sending headers more elegant. It&#8217;s a clever design really; supply varying levels of complexity in control to match varying levels of complexity in application&#8211;not everyone is going to want the ability to create a mail server, so why would they want to have to access tcp directly? Inversely; not everyone is only going to want a web server, so why would you only supply access to http-related code?</p>
<p>Have a look at this sample code I ripped-off from the homepage of node.js;</p>
<pre>
var sys = require('sys'),
   http = require('http');
http.createServer(function (req, res) {
  setTimeout(function () {
    res.sendHeader(200, {'Content-Type': 'text/plain'});
    res.sendBody('Hello World');
    res.finish();
  }, 2000);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
</pre>
<p>Isn&#8217;t it so simple? You just include a few modules, run http.createServer() with a callback function passing in the request and response objects and tell the server to listen on whatever port you want and whatever domain you want. In the callback you can branch of by breaking apart request.url to find the user&#8217;s query and use that to redirect via a switch block or whatever other means you see fit. Best of all, it&#8217;s asynchronous, so you don&#8217;t need to halt execution for every little thing. It&#8217;s even compatible with many common Javascript utility libraries such as <a href="http://documentcloud.github.com/underscore/">Underscore</a></p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=83&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2010/02/17/node-js-im-a-fanboy-already/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jquery.flash v1.3.1 &#8211; Squashing IE-related bugs.</title>
		<link>http://stephenbelanger.com/2010/01/02/jquery-flash-v1-3-1-squashing-ie-related-bugs/</link>
		<comments>http://stephenbelanger.com/2010/01/02/jquery-flash-v1-3-1-squashing-ie-related-bugs/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 09:17:18 +0000</pubDate>
		<dc:creator>Qard</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery.flash]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[swfobject]]></category>

		<guid isPermaLink="false">http://www.stephenbelanger.com/?p=59</guid>
		<description><![CDATA[If you downloaded v1.3 of jquery.flash I would recommend switching to this one. There has been no functionality changes, so it should just be drop-in. It fixes a minor bug I added when I switched to using indexOf() for iterating through attributes and parameters...apparently IE doesn't support it. >.>]]></description>
			<content:encoded><![CDATA[<p>If you downloaded v1.3 of jquery.flash I would recommend switching to this one. There has been no functionality changes, so it should just be drop-in. It fixes a minor bug I added when I switched to using indexOf() for iterating through attributes and parameters&#8230;apparently IE doesn&#8217;t support it. >.></p>
<p>That&#8217;s fixed now and I did a few minor structural changes to reduce the character count a little and make things ever so slightly speedier. I also created a fancy tutorial page type thing for it, which you can check out here.</p>
<p><a href="http://www.stephenbelanger.com/jquery-flash/">Example</a></p>
<p>Downloads:<br />
<a href='http://www.stephenbelanger.com/wp-content/uploads/2010/01/jquery.flash.min_.js'>Minified &#8211; 2.03 KB</a><br />
<a href='http://www.stephenbelanger.com/wp-content/uploads/2010/01/jquery.flash.js'>Non-Minified &#8211; 4.35 KB</a></p>
<img src="http://stephenbelanger.com/?ak_action=api_record_view&id=59&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://stephenbelanger.com/2010/01/02/jquery-flash-v1-3-1-squashing-ie-related-bugs/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

