<?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>KOO Studios Blog</title>
	<atom:link href="http://blog.koostudios.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.koostudios.com</link>
	<description>Tutorials, Trends and the Totally Awesome Web</description>
	<lastBuildDate>Mon, 07 May 2012 23:01:39 +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>BrowserID: Logging in with BrowserID, Passport and NodeJS</title>
		<link>http://blog.koostudios.com/?p=506</link>
		<comments>http://blog.koostudios.com/?p=506#comments</comments>
		<pubDate>Sat, 05 May 2012 12:46:50 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=506</guid>
		<description><![CDATA[BrowserID is a hot new way of signing in to your favorite web applications without the need of typing in your password for each website. It lets users sign in once through BrowserID and then use different websites that use &#8230; <a href="http://blog.koostudios.com/?p=506">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.koostudios.com/wp-content/uploads/2012/05/browserid.jpg"><img class="aligncenter size-full wp-image-527" title="browserid" src="http://blog.koostudios.com/wp-content/uploads/2012/05/browserid.jpg" alt="" width="620" height="348" /></a></p>
<p><a href="http://browserid.org" target="_blank">BrowserID</a> is a hot new way of signing in to your favorite web applications without the need of typing in your password for each website. It lets users sign in once through BrowserID and then use different websites that use BrowserID without typing in their details again and again (a quick guide is <a href="http://support.mozilla.org/en-US/kb/what-browserid-and-how-does-it-work" target="_blank">located here</a>). This NodeJS service, soon to be renamed <a href="http://identity.mozilla.com/post/18038609895/introducing-mozilla-persona" target="_blank">Mozilla Persona</a>, is <em>super</em> easy to implement with a lightweight authentication module called <a href="http://passportjs.org" target="_blank">Passport</a>. For this tutorial, we&#8217;ll go through a whirlwind tour of BrowserID and Passport and hopefully, this will show you just how easy it is to use BrowserID in your application. This tutorial is uploaded as a Github Gist and is <a href="https://gist.github.com/2600946" target="_blank">located here</a> if you want to have a look at the code as a whole.</p>
<p><span id="more-506"></span></p>
<h2>1. Setting Up</h2>
<p>The easiest way to start a NodeJS project is to install <a href="http://nodejs.org">NodeJS</a> and create a file called <strong>package.json</strong> with the following:</p>
<div id="gist-2600946" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>	<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;browserid-tutorial&quot;</span><span class="p">,</span></div><div class='line' id='LC3'>	<span class="nt">&quot;description&quot;</span><span class="p">:</span> <span class="s2">&quot;BrowserID: Logging in with BrowserID, Passport and NodeJS&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>	<span class="nt">&quot;version&quot;</span><span class="p">:</span> <span class="s2">&quot;0.1.0&quot;</span><span class="p">,</span></div><div class='line' id='LC5'>	<span class="nt">&quot;author&quot;</span><span class="p">:</span> <span class="s2">&quot;Alexander Yuen &lt;koo.studios@gmail.com&gt; (http://www.koostudios.com/)&quot;</span><span class="p">,</span></div><div class='line' id='LC6'>	<span class="nt">&quot;main&quot;</span><span class="p">:</span> <span class="s2">&quot;server.js&quot;</span><span class="p">,</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;node&quot;</span><span class="p">:</span> <span class="s2">&quot;0.6.x&quot;</span><span class="p">,</span></div><div class='line' id='LC8'>	<span class="nt">&quot;dependencies&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC9'>		<span class="nt">&quot;coffee-script&quot;</span>     <span class="p">:</span> <span class="s2">&quot;1.2.x&quot;</span><span class="p">,</span></div><div class='line' id='LC10'>		<span class="nt">&quot;express&quot;</span>           <span class="p">:</span> <span class="s2">&quot;2.5.x&quot;</span><span class="p">,</span></div><div class='line' id='LC11'>		<span class="nt">&quot;jade&quot;</span>              <span class="p">:</span> <span class="s2">&quot;0.20.x&quot;</span><span class="p">,</span></div><div class='line' id='LC12'>		<span class="nt">&quot;passport&quot;</span>          <span class="p">:</span> <span class="s2">&quot;0.1.x&quot;</span><span class="p">,</span></div><div class='line' id='LC13'>		<span class="nt">&quot;passport-browserid&quot;</span><span class="p">:</span> <span class="s2">&quot;0.1.x&quot;</span></div><div class='line' id='LC14'>	<span class="p">},</span></div><div class='line' id='LC15'>	<span class="nt">&quot;license&quot;</span><span class="p">:</span> <span class="s2">&quot;MIT&quot;</span></div><div class='line' id='LC16'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2600946/7643118f2eceec66222b71e50576b672a34e3f66/package.json" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2600946#file_package.json" style="float:right;margin-right:10px;color:#666">package.json</a>
            <a href="https://gist.github.com/2600946">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Now, simply change directory into the directory containing the package.json file using your terminal and run <strong>npm install </strong>to install all the dependencies in this file. Notice that Passport is located in two modules. This allows Passport to be very slim since we only need to include the particular system of authentication that we are using, called a &#8216;strategy&#8217;. In this case, it&#8217;s &#8216;passport-browserid&#8217; which is the module required for BrowserID but there are many more strategies available (<a href="https://github.com/jaredhanson/passport#strategies-1">see the full list here</a>).</p>
<p>Next, we create a file called <strong>server.js</strong> :<br />
<div id="gist-2600946" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;coffee-script&#39;</span><span class="p">);</span></div><div class='line' id='LC2'><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./main&#39;</span><span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2600946/d639982619493b0a625701ee00637e01bc8c7a45/server.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2600946#file_server.js" style="float:right;margin-right:10px;color:#666">server.js</a>
            <a href="https://gist.github.com/2600946">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
</p>
<p>This file is simple. It loads the CoffeeScript module and then the main part of the code, which will be located on a CoffeeScript file called &#8216;main.coffee&#8217;. The CoffeeScript module allows you to simply require &#8216;.coffee&#8217; files throughout the NodeJS app without using the extension and will compile them on-the-fly when you run &#8216;node server&#8217;</p>
<h2>2. Passport Up!</h2>
<p>The bulk of the code, as you may have guessed is contained within the <strong>main.coffee</strong> file. This is quite a complex script at first but we will go through it bit by bit:</p>
<div id="gist-2600946" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1"># Variables</span></div><div class='line' id='LC2'><span class="nv">exp = </span><span class="nx">require</span> <span class="s">&#39;express&#39;</span></div><div class='line' id='LC3'><span class="nv">app = </span><span class="nx">exp</span><span class="p">.</span><span class="nx">createServer</span><span class="p">()</span></div><div class='line' id='LC4'><span class="nv">pass = </span><span class="nx">require</span> <span class="s">&#39;passport&#39;</span></div><div class='line' id='LC5'><span class="nv">BrowserID = </span><span class="nx">require</span><span class="p">(</span><span class="s">&#39;passport-browserid&#39;</span><span class="p">).</span><span class="nx">Strategy</span>	</div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'><span class="c1"># Passport Serialize and Deserialize Functions</span></div><div class='line' id='LC8'><span class="nx">pass</span><span class="p">.</span><span class="nx">serializeUser</span> <span class="nf">(user, done) -&gt;</span></div><div class='line' id='LC9'>	<span class="nx">done</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">user</span><span class="p">.</span><span class="nx">email</span></div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'><span class="nx">pass</span><span class="p">.</span><span class="nx">deserializeUser</span> <span class="nf">(email, done) -&gt;</span></div><div class='line' id='LC12'>	<span class="nx">done</span> <span class="kc">null</span><span class="p">,</span> <span class="p">{</span><span class="nv">email: </span><span class="nx">email</span><span class="p">}</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'><span class="c1"># Passport-BrowserID Strategy</span></div><div class='line' id='LC15'><span class="nx">pass</span><span class="p">.</span><span class="nx">use</span> <span class="s">&#39;browserid&#39;</span><span class="p">,</span> <span class="k">new</span> <span class="nx">BrowserID</span> <span class="p">{</span><span class="nv">audience: </span><span class="s">&#39;http://dev.koostudios.com:1337&#39;</span><span class="p">},</span> <span class="nf">(email, done) -&gt;</span></div><div class='line' id='LC16'>	<span class="c1"># Interface with Database would go here</span></div><div class='line' id='LC17'>	<span class="nx">done</span> <span class="kc">null</span><span class="p">,</span> <span class="p">{</span><span class="nv">email: </span><span class="nx">email</span><span class="p">}</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'><span class="c1"># App Configuration		</span></div><div class='line' id='LC20'><span class="nx">app</span><span class="p">.</span><span class="nx">configure</span> <span class="nf">() -&gt;</span></div><div class='line' id='LC21'>	<span class="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="s">&#39;view engine&#39;</span><span class="p">,</span> <span class="s">&#39;jade&#39;</span></div><div class='line' id='LC22'>	<span class="nx">app</span><span class="p">.</span><span class="nx">set</span> <span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="nx">__dirname</span> <span class="o">+</span> <span class="s">&#39;/views&#39;</span></div><div class='line' id='LC23'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">exp</span><span class="p">.</span><span class="nx">static</span> <span class="nx">__dirname</span> <span class="o">+</span> <span class="s">&#39;/public&#39;</span></div><div class='line' id='LC24'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">exp</span><span class="p">.</span><span class="nx">cookieParser</span><span class="p">()</span></div><div class='line' id='LC25'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">exp</span><span class="p">.</span><span class="nx">bodyParser</span><span class="p">()</span></div><div class='line' id='LC26'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">exp</span><span class="p">.</span><span class="nx">methodOverride</span><span class="p">()</span></div><div class='line' id='LC27'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">exp</span><span class="p">.</span><span class="nx">session</span> <span class="p">{</span><span class="nv">secret: </span><span class="s">&#39;somesecretstringhere&#39;</span><span class="p">}</span></div><div class='line' id='LC28'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">pass</span><span class="p">.</span><span class="nx">initialize</span><span class="p">()</span></div><div class='line' id='LC29'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">pass</span><span class="p">.</span><span class="nx">session</span><span class="p">()</span></div><div class='line' id='LC30'>	<span class="nx">app</span><span class="p">.</span><span class="nx">use</span> <span class="nx">app</span><span class="p">.</span><span class="nx">router</span></div><div class='line' id='LC31'><br/></div><div class='line' id='LC32'><span class="c1"># Run App	</span></div><div class='line' id='LC33'><span class="nx">app</span><span class="p">.</span><span class="nx">listen</span> <span class="s">&#39;1337&#39;</span></div><div class='line' id='LC34'><span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s">&#39;Server running at port &#39;</span> <span class="o">+</span> <span class="nx">app</span><span class="p">.</span><span class="nx">address</span><span class="p">().</span><span class="nx">port</span></div><div class='line' id='LC35'><br/></div><div class='line' id='LC36'><span class="c1"># Routes</span></div><div class='line' id='LC37'><span class="nx">app</span><span class="p">.</span><span class="nx">get</span> <span class="s">&#39;/&#39;</span><span class="p">,</span> <span class="nf">(req, res) -&gt;</span></div><div class='line' id='LC38'>	<span class="k">if</span> <span class="nx">req</span><span class="p">.</span><span class="nx">isAuthenticated</span><span class="p">()</span></div><div class='line' id='LC39'>		<span class="nx">res</span><span class="p">.</span><span class="nx">send</span> <span class="s">&quot;Congratulations! You&#39;ve signed in as &quot;</span> <span class="o">+</span> <span class="nx">req</span><span class="p">.</span><span class="nx">user</span><span class="p">.</span><span class="nx">email</span></div><div class='line' id='LC40'>	<span class="k">else</span></div><div class='line' id='LC41'>		<span class="nx">res</span><span class="p">.</span><span class="nx">render</span> <span class="s">&#39;index&#39;</span></div><div class='line' id='LC42'><br/></div><div class='line' id='LC43'><span class="nx">app</span><span class="p">.</span><span class="nx">post</span> <span class="s">&#39;/login&#39;</span><span class="p">,</span> <span class="nx">pass</span><span class="p">.</span><span class="nx">authenticate</span> <span class="s">&#39;browserid&#39;</span><span class="p">,</span></div><div class='line' id='LC44'>	<span class="nv">successRedirect: </span><span class="s">&#39;/&#39;</span></div><div class='line' id='LC45'>	<span class="nv">failureRedirect: </span><span class="s">&#39;/&#39;</span></div><div class='line' id='LC46'>	<span class="nv">failureFlash: </span><span class="kc">true</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2600946/3d9275a1346d567a0b9260fb063bf1909d83e190/main.coffee" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2600946#file_main.coffee" style="float:right;margin-right:10px;color:#666">main.coffee</a>
            <a href="https://gist.github.com/2600946">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h3><strong>Variables</strong></h3>
<p>These are pretty straightforward. We use the require function to include the Express framework, the Passport module and the BrowserID strategy. Note that the actual method of the BrowserID strategy that contains the class needed is &#8216;.Strategy&#8217;. Immediately after including the Express framework, we call on the createServer() function of Express which creates the application.</p>
<h3><strong>Passport Serialize and Deserialize Functions</strong></h3>
<p>To ensure that the server knows that a user is logged in as the user moves from page to page, the user&#8217;s browser is required to keep a string of characters in a cookie that is unique and identifiable to that user. This information is sent to the server each time a request is made so that the server knows who to send privileged information to but it must be serialized, or encoded before being sent to avoid misuse. Passport requires the developer to provide the necessary functions to &#8216;serialize&#8217; and &#8216;deserialize&#8217; this cookie with the session secret (see below) so that the information is kept safe on the client&#8217;s computer. This just means providing the done function with the email in the serializeUser function and checking the email matches with the done function in the deserializeUser function.</p>
<h3>Passport-BrowserID Strategy</h3>
<p>This is the major Passport function that contains the BrowserID strategy. Firstly we set the namespace of this strategy to &#8216;browserid&#8217;, which we will use later and then we create a new instance of the BrowserID class. This class requires an &#8216;audience&#8217; variable and a verification function.</p>
<ul>
<li><strong>The audience variable</strong> is used by BrowserID to identify the requesting party, which is your application. This should contain the website you are calling BrowserID from.</li>
<li><strong>The verification function</strong> ensures that the user requested is valid on both ends. It checks that the user activated from BrowserID is the same as the one in your database, or one that you have just created in your database. However, in the example code above, it just passes the done function with the same email straight back but normally, database functions should be included in this function.</li>
</ul>
<h3>App Configuration and Run App</h3>
<p>This is the standard configuration and run app lines. Of note are the <strong>session secret</strong> which is required for serializing the user information into a session ID that is placed into the User&#8217;s cookies. Ensure the configuration lines appear in that order as they are needed in this order.</p>
<h3>Routes</h3>
<p>This simple application will only include 2 routes but only one page:</p>
<ul>
<li>The first route checks if the user is authenticated through the function <strong>req.isAuthenticated()</strong>. If the user is not authenticated, the route will display the &#8216;index&#8217; file which will contain the button to sign in.</li>
<li>The second route activates the authentication function of the BrowserID strategy by sending a POST to &#8216;/login&#8217;. The authentication strategy requires at least specifying where the user should redirect on failure through the &#8216;failureRedirect&#8217; but you may like to add the &#8216;successRedirect&#8217; if you wish. When failureFlash is set to true, it allows the developer to show the error messages on the jade file through the variable <strong>error</strong>.</li>
</ul>
<h2>3. The Front-End</h2>
<p>Now that the NodeJS is out of the way, it is time to create the front-end. We use two files that will put in a <strong>views</strong> folder &#8211; <strong>layout.jade</strong> (that acts as a template) and<strong> index.jade </strong>(that contains the form):</p>
<div id="gist-2600946" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>!!! 5</div><div class='line' id='LC2'>html(lang= &#39;en&#39;)</div><div class='line' id='LC3'>	head</div><div class='line' id='LC4'>		meta(charset= &#39;utf-8&#39;)</div><div class='line' id='LC5'>		title= &#39;BrowserID with Passport and NodeJS&#39;</div><div class='line' id='LC6'>	body</div><div class='line' id='LC7'>		!=body</div><div class='line' id='LC8'>		script(src= &#39;http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js&#39;)</div><div class='line' id='LC9'>		script(src= &#39;https://browserid.org/include.js&#39;)</div><div class='line' id='LC10'>		script(src= &#39;/client.js&#39;)</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2600946/3c5656a340e4abe5b0582da058244b3b5cbbef21/layout.jade" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2600946#file_layout.jade" style="float:right;margin-right:10px;color:#666">layout.jade</a>
            <a href="https://gist.github.com/2600946">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>In layout, we specify a simple HTML5 template page which will include three important scripts that is placed after the main body markup: the jQuery library, the BrowserID library and the client.js script which we will write. Note that the BrowserID file is necessary in the frontend to login to BrowserID as we shall see later.</p>
<div id="gist-2600946" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>form(method= &#39;post&#39;, action= &#39;/login&#39;)</div><div class='line' id='LC2'>	input(name= &#39;assertion&#39;, type= &#39;hidden&#39;)</div><div class='line' id='LC3'>	input#browserid(type= &#39;submit&#39;, value= &#39;Sign in with BrowserID&#39;)</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2600946/858926c830653254307350fc23ea41c284f6d40b/index.jade" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2600946#file_index.jade" style="float:right;margin-right:10px;color:#666">index.jade</a>
            <a href="https://gist.github.com/2600946">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The markup in the <strong>index.jade</strong> file goes exactly where the != body is in the previous<strong> layout.jade</strong> file. This markup is simply a form which posts to &#8216;/login&#8217; (which was one of our routes) with a hidden input for an &#8216;assertion&#8217; variable and a login button.</p>
<p>The final thing to gel everything together is the client-side script, which I am neatly calling <strong>client.js</strong>, containing the following. This file should be placed in a folder called <strong>public</strong> as we have specified that all static files should be in there.</p>
<div id="gist-2600946" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#browserid&quot;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;click&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">()</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">navigator</span><span class="p">.</span><span class="nx">id</span><span class="p">.</span><span class="nx">getVerifiedEmail</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">assertion</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">assertion</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;input[name=assertion]&quot;</span><span class="p">).</span><span class="nx">val</span><span class="p">(</span><span class="nx">assertion</span><span class="p">);</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;form&quot;</span><span class="p">).</span><span class="nx">submit</span><span class="p">();</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">location</span><span class="p">.</span><span class="nx">reload</span><span class="p">();</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC11'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2600946/66b54f3a023f1cab24b2c9dd073cb24c804bc6f0/client.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2600946#file_client.js" style="float:right;margin-right:10px;color:#666">client.js</a>
            <a href="https://gist.github.com/2600946">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This file merely calls the function &#8216;navigator.id.getVerifiedEmail&#8217; from the BrowserID file that we included before. This function activates the BrowserID process, showing a popup allowing the user to login. When the user successfully logs into the BrowserID service, the function sends back an <strong>assertion</strong>. This assertion is a password key that is sent back to the server through the hidden input with the form. The form activates the server-side process outlined above through the &#8216;/login&#8217; route, completing the authentication process by verifying with BrowserID that the user has been found and logged in.</p>
<h2>4. Running</h2>
<p>No need to compile the CoffeeScript file, simply use the cd command to change to your director and run &#8216;node server&#8217;. If you see a message saying &#8216;Server running at port 1337&#8242;, you&#8217;ve done something right!</p>
<p>Now, simply point your browser to http://your-local-domain:1337 and then click on the login button that you&#8217;ve created! You should see a popup with BrowserID. From there, simply signup or login and then let BrowserID do its job. If you have been successful, you should get the message &#8216;Congratulations! You&#8217;ve signed in as &lt;your email here&gt;&#8217;.</p>
<h2>Conclusion</h2>
<p>BrowserID is a hot new authentication system that relieves developers of the need for complicated processes such as the OAuth system that requires the developer to deal with authentication tokens and secrets. Instead, an assertion is provided in the frontend and then the server sends it back to BrowserID to get the user information. It is a much more streamlined process that is made even simpler by the Passport-BrowserID strategy of the Passport module. This handles a lot of things for the developer, leaving more focus on the actual application itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=506</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Websockets: Chat App with Socket.io and NodeJS</title>
		<link>http://blog.koostudios.com/?p=470</link>
		<comments>http://blog.koostudios.com/?p=470#comments</comments>
		<pubDate>Fri, 24 Feb 2012 00:00:53 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=470</guid>
		<description><![CDATA[Amazing World of Chat &#8211; Illustration by kdonovan_gaddy Websockets is amazing technology in the new HTML5 specifications that allows for a new way of communicating between browsers and servers. Through this technology, applications can easily and quickly provide bi-directional communication in &#8230; <a href="http://blog.koostudios.com/?p=470">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://farm3.staticflickr.com/2696/4314364949_a3d9a9b87b_z.jpg?zz=1" alt="" width="640" height="400" /></p>
<p><small><em>Amazing World of Chat &#8211; Illustration by <a href="http://www.flickr.com/photos/kdonovan_gaddy/">kdonovan_gaddy</a></em></small></p>
<p>Websockets is amazing technology in the new HTML5 specifications that allows for a new way of communicating between browsers and servers. Through this technology, applications can easily and quickly provide bi-directional communication in realtime. This allows developers to create all sorts of realtime applications (e.g. statistics, chat applications) without the need of relying on huge AJAX calls that continuously poll the server and take up large amounts of resources. With <a href="http://www.socket.io">Socket.io</a>, working with Websockets is astoundingly easy and works perfectly with the non-blocking and quick realtime server, NodeJS. Plus, with <a href="http://socket.io">Socket.io</a>, browser compatibility for Websockets is no longer an issue as it solves the problem by choosing whatever communication protocol available for the browser at hand. So, let&#8217;s have a peek at parts of an application that uses Socket.io, a program I am developing called LightChat.<span id="more-470"></span></p>
<h2>The Aim</h2>
<p>A chat application is the simplest way of demonstrating the deliciousness of Websockets and Socket.io. For this, we will just need the user to be able to:</p>
<ul>
<li>Send a chat message to be broadcasted to everyone that is &#8216;connected&#8217;</li>
<li>Receive a chat message</li>
</ul>
<div>Plus, if you follow the optional &#8216;More Complicated&#8217; section, we will be able to let the user create their own chatroom so that it only broadcasts to people at that URL.</div>
<p>This tutorial requires the following software / node modules. Be sure to download them through the links below or through npm.</p>
<ul>
<li><a href="http://nodejs.org/">NodeJS</a> (v 0.6.9)</li>
<li><a href="http://coffeescript.org/">CoffeeScript</a> (v 1.2.0)</li>
<li><a href="http://expressjs.com/">Express.js</a> (v 0.5.8)</li>
<li><a href="http://jade-lang.com/">Jade Template Engine</a> (v 0.20.0)</li>
<li><a href="http://www.socket.io">Socket.io</a> (v 0.8.7)</li>
</ul>
<h2>1. Setting Up</h2>
<p>Again, we can set up our project structure as in my previous two tutorials. If you need help with creating this structure again, please have a look at one of <a href="http://blog.koostudios.com/?p=398">my previous posts</a>. Next, we should create our application file in our root folder. I&#8217;m calling mine <strong>main.coffee:</strong></p>
<pre class="brush: coffeescript; title: ; notranslate">
exp = require 'express'
app = exp.createServer()
io = require('socket.io').listen app

app.configure -&gt;
    app.set 'views', __dirname + '/views'
    app.set 'view engine', 'jade'
    app.use exp.static __dirname + '/public'

app.listen 1337
console.log 'Server running at http://localhost:1337'
</pre>
<p>If you have seen any NodeJS application before, this will be one of the most simple configurations but in this example, it is simply all we need. The only new thing is perhaps<strong> line 3</strong> which requires Socket.io and then configures it to listen to the application created by Express. Apart from that, we are doing everything very standard here.</p>
<h2>2. Fun with Socket.IO</h2>
<p>Here comes the fun part. When Socket.io makes a connection as in the following script, it figures out the browser and chooses the most appropriate communication method, whether that be Websockets, Flash or whatever. So, we need code that triggers connection and that code that fits in<strong> main.coffee:</strong></p>
<pre class="brush: coffeescript; title: ; notranslate">
io.sockets.on 'connection', (socket) -&gt;
    socket.on 'send', (data) -&gt;
        socket.broadcast.emit 'distribute', data
</pre>
<p><strong>Lines 2 and 3</strong> are the awesomesauce and everything needed to run the chat application. Socket.io works on listeners and senders. However, in the language, these verbs become &#8216;on&#8217; and &#8216;emit&#8217;, respectively. <strong>Line 2</strong> serves as the listener function, waiting for the function &#8216;send&#8217;. When &#8216;send&#8217; is emitted from the client side (see below), <strong>line 3</strong> sends a function named &#8216;distribute&#8217; which sends the data back. Using the broadcast tag, Socket sends the same data to everyone that is connected except for the user itself.</p>
<p>For the client side, I am going to write a jQuery file called <strong>client.coffee</strong> under the directory <strong>/public/js/:</strong></p>
<pre class="brush: coffeescript; title: ; notranslate">
$ -&gt;
    socket = io.connect 'http://localhost'
    socket.on 'distribute', (data) -&gt;
        $('#results').append('&lt;div&gt;' + data.message + '&lt;/div&gt;')

    $('#chatter').on 'submit', (e) -&gt;
        e.preventDefault &amp; e.preventDefault()
        message = $('#message').val()
        socket.emit 'send', {'message': message}
        $('#results').append('&lt;div&gt;' + message + '&lt;/div&gt;')
</pre>
<p>The client side is slightly more involved but no less simple.</p>
<p>In <strong>line 1</strong>, the variable socket must be connected to a file that is served automatically on the host. If you have installed socket.io correctly (remember this means globally), it should be served when you require it. In my case, it is on http://localhost.</p>
<p>Using the socket variable, we are able to create listener and sender functions through either <em>socket.on</em> or <em>socket.emit</em>. This works exactly the same as the ones on the server. Now, we can define functions such as &#8216;send&#8217; on<strong> line 9</strong>, which passes a variable &#8216;message&#8217; to the server when a form is submitted. As we saw before, the server will be listening for the &#8216;send&#8217; function and will broadcast the function &#8216;distribute&#8217; in return. We can define what happens on functions such as &#8216;distribute&#8217; as in <strong>line 3</strong>, in which we append the &#8216;message&#8217; variable to a element called &#8216;#results&#8217;. Simple.</p>
<p>If that has you muddled up, think of the entire process of sending and receiving one chat message. The user types something in a form, submits it and <strong>client.coffee</strong> emits a function called send, which sends what the user typed as the variable &#8216;message&#8217; to the server. The server, on <strong>main.coffee</strong>, listens for the &#8216;send&#8217; function and when it receives the function, broadcasts a function called &#8216;distribute&#8217; and sends the data along to everyone except the user. Everyone that is connected has <strong>client.coffee</strong> which listens for the &#8216;distribute&#8217; function. On receipt of &#8216;distribute&#8217;, it appends the message to the screen in the &#8216;#results&#8217; element.</p>
<h2>3. Front-End</h2>
<p>Now that we&#8217;ve created all the logic and understood it (Yes, that was all there was to it), let us create a simple interface for our chat application.</p>
<p>For this, let&#8217;s quickly render an index file in <strong>main.coffee</strong> when one goes to &#8216;/&#8217;:</p>
<pre class="brush: coffeescript; title: ; notranslate">
app.get '/', (req, res) -&gt;
res.render 'index', {locals: {title: 'LightChat'}}
</pre>
<p>Now, we can create a <strong>layout.jade</strong> and an <strong>index.jade</strong>. The <strong>layout.jade</strong> will be very simple with the bare basics:</p>
<pre class="brush: plain; title: ; notranslate">
!!! 5
html
    head
        title= title
    body
        != body
</pre>
<p>However, <strong>index.jade</strong> will be where all the magic happens:</p>
<pre class="brush: plain; title: ; notranslate">
#results
form#chatter
    input#message(type= &quot;text&quot;, placeholder= &quot;Type Something...&quot;)
    input(type= &quot;submit&quot;, value= &quot;Send&quot;)

script(src= &quot;/js/jquery.min.js&quot;)
script(src= &quot;/js/client.js&quot;)
</pre>
<p>As you can see, it is merely an element called &#8216;#results&#8217;, which we will use to append messages and a form called &#8216;#chatter&#8217;, which the user will type in the &#8216;message&#8217; input to send to the server. Finally, in the last two lines, jQuery and the client file will be served.</p>
<h2>4. More Complicated Please</h2>
<p>If you&#8217;re complaining that this tutorial was too simple (I was!), here is a little bit more, before you go ahead and run everything. You can follow this if you want or jump right down to the next section if you have had enough. Either way, it should run perfectly well (we hope).</p>
<p>I want to show you how easy it is to create a multiroom chat application wherein users who have entered a chatroom only get the messages from people in the chatroom they are in. To simplify the chatroom experience, however, I am going to use URLs as the identifying factor. This means that separate chatrooms are going to separated by the pathname, everyone who is connected to the same pathname e.g. <strong>/abc</strong> is going to be in the same chatroom.</p>
<p>So, let&#8217;s modify the socket.io code in <strong>main.coffee</strong> and create a new app.get so that we serve index.jade when going to <strong>http://localhost:1337/</strong> and then whatever id.</p>
<pre class="brush: coffeescript; title: ; notranslate">
app.get '/:id', (req, res) -&gt;
    res.render 'index', {locals: {title: req.params.id}}

io.sockets.on 'connection', (socket) -&gt;
    socket.on 'switch', (room) -&gt;
        socket.join room

    socket.on 'send', (data) -&gt;
        socket.broadcast.to(data.room).emit 'distribute', data
</pre>
<p>You will notice there are some slight differences with this code and the last. Firstly, we grab the ID of the chatroom by calling req.params.id. This only serves to render the index.jade layout and set the title of the page to the ID of the chatroom.</p>
<p>Now, there are two different lines in the socket code. <strong>Lines 5 and 6</strong> is where the magic happens. These lines allows us to join a room, when the function &#8216;switch&#8217; is triggered, a function we are going to set when a person first comes onto a webpage. Then, the last line,<strong> Line 9 </strong>lets us broadcast the same way as before but only to the room that we are going to specify by adding it in the data.</p>
<p>Now that we&#8217;ve changed the server-side, let&#8217;s give the server what it needs. The first is to emit a function called &#8216;switch&#8217; that happens when the user goes to a URL. This function, situated in <strong>client.coffee</strong>, will pass on the pathname:</p>
<pre class="brush: coffeescript; title: ; notranslate">
room = window.location.pathname.slice 1
socket.emit 'switch', room
</pre>
<p>Since the pathname contains a slash, I am slicing it to avoid confusion. However, I am pretty sure everything would still run even without it. I am only doing this to keep consistent with the Node side.</p>
<p>Finally, we also have to pass on the room variable when something is sent. To do this, we only have to add the &#8216;room&#8217; variable when sending in the previous <strong>client.coffee</strong>:</p>
<pre class="brush: coffeescript; title: ; notranslate">
socket.emit 'send', {'message': message, 'room': room}
</pre>
<p>Done! Now, you have a chat application capable of multiple chatrooms all separated by simply the URL pathname. Everyone with the same pathname will be able to listen in but users in different pathnames will be in separated chatrooms. Very neat!</p>
<h2>5. Running</h2>
<p>Again, if you have not got the awesome command line <em>coffee &#8211;watch &#8211;compile</em> happening, then remember to compile the coffee files before running. Also remember that the <strong>client.coffee</strong> file needs to compile too. After this, you can go back to your project folder and run:</p>
<pre class="brush: plain; title: ; notranslate">
node main.js
</pre>
<p>To test it out, I recommend opening two browsers, preferably two different kinds side by side and then posting in one and then posting in the other. And voila! It is amazing in so little code is it not?!</p>
<h2>Conclusion</h2>
<p>Writing realtime applications like the chat application in this tutorial is amazingly simple with Websockets and Socket.io. And, added with the astounding asynchronous and non-blocking nature of NodeJS, it makes these applications super fast and super simple to write. In this example, we managed to create a chat application in which a user can broadcast a message and users can simultaneously talk to each other with two functions socket.on and socket.emit and around 10 lines of code related to it. With the same functions, any realtime communication between browser and server just became much, much simpler and real fun to write. So, dream up big because realtime communication is now all the more real with Socket.io and NodeJS.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=470</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>OAuth: Logging In with EveryAuth and NodeJS</title>
		<link>http://blog.koostudios.com/?p=453</link>
		<comments>http://blog.koostudios.com/?p=453#comments</comments>
		<pubDate>Wed, 15 Feb 2012 00:26:20 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=453</guid>
		<description><![CDATA[Lock and Key &#8211; Photo by Bohman (Flickr) [CC-BY 2.0] Connecting to social networks is nearly a must have for every new fangled website in the works. And increasingly, many websites are using OAuth authentication of other social networks to log &#8230; <a href="http://blog.koostudios.com/?p=453">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://farm1.staticflickr.com/97/210977249_da533e62a4_z.jpg?zz=1" alt="" width="620" /> <small><em>Lock and Key &#8211; Photo by <a href="http://www.flickr.com/photos/bohman/210977249/">Bohman</a> (Flickr) [CC-BY 2.0]</em></small></p>
<p>Connecting to social networks is nearly a must have for every new fangled website in the works. And increasingly, many websites are using OAuth authentication of other social networks to log in to their websites, thereby alleviating users of the need to remember a separate username and password for your website. Using Node, it is surprisingly easy to hookup to your favourite social network with the node module, Everyauth.  So, without further ado, let&#8217;s demonstrate how to log into a website using Twitter. <span id="more-453"></span></p>
<h2>The Aim</h2>
<p>Let&#8217;s create a basic authentication system that allows:</p>
<ul>
<li>User to log in to the website using a button</li>
<li>Display to the user a greeting with their name, like &#8220;Hi, KOOStudios!&#8221; (That&#8217;s my Twitter handle &#8211; Follow Me!)</li>
</ul>
<div>This tutorial requires the following software / node modules. Be sure to download them through the links below or through npm.</div>
<div>
<ul>
<li><a href="http://nodejs.org/">NodeJS</a> (v 0.6.9)</li>
<li><a href="http://couchdb.apache.org/">CouchDB</a> (v 1.0.2)</li>
<li><a href="http://coffeescript.org/">CoffeeScript</a> (v 1.2.0)</li>
<li><a href="http://expressjs.com/">Express.js</a> (v 0.5.8)</li>
<li><a href="http://jade-lang.com/">Jade Template Engine</a> (v 0.20.0)</li>
<li><a href="https://github.com/bnoguchi/everyauth">Everyauth</a> (v 0.2.30)</li>
</ul>
</div>
<h2>1. Setting Up</h2>
<p>Let&#8217;s do the configuration first. You may generate a project folder using the same structure as a normal NodeJS application. If you don&#8217;t  remember how, be sure to check <a href="http://blog.koostudios.com/?p=398#more-398">my previous post</a>. Now, we start with our file, <strong>main.coffee </strong>which will be pretty generic:</p>
<pre class="brush: coffeescript; title: ; notranslate">
# Requires and Variables
exp = require 'express'
app = exp.createServer()

# App Configuration
app.configure () -&gt;
    app.set 'view engine', 'jade'
    app.set 'views', __dirname + '/views'
    app.use exp.static __dirname + '/views'
    app.use exp.bodyParser()
    app.use exp.methodOverride()
    app.use exp.cookieParser()
    app.use exp.session {secret: 'bobsyouruncle'}
    app.use everyauth.middleware()
    app.use app.router

app.listen 1337
console.log 'Server running at http://localhost:1337'
</pre>
<p>If you followed my previous blog post, most of this is the same. What appears different is that we&#8217;ve added four extra lines at the bottom of the configuration. Here&#8217;s a little explanation of what they are:</p>
<ul>
<li><strong>Line 12</strong> calls on the cookieParser. When the user logs in, the session information (explained below) will be saved into a cookie, allowing users to move from page to page. The cookieParser method allows us to deal with cookies.</li>
<li><strong>Line 13</strong> calls on the session method which allows us to deal with sessions. When a user logs in to the site, a &#8220;session&#8221; is generated, like a temporary ID card that allows the site to recognise the user when they use it. The secret will be the secret passphrase that will hash it from prying eyes.</li>
<li><strong>Line 14</strong> imports the everyauth middleware. We don&#8217;t expressly need this in this tutorial but this will lets us use express helpers which are functions which can determine if the user is logged in or let us access the user details.</li>
<li><strong>Line 15</strong> is the app.router which tells the application to mount the routes. Normally we use app.get which is sufficient but everyauth uses default routes that can save all the trouble by using this one line.</li>
</ul>
<div>Note, I recommend writing these lines in this order, not only because it makes more sense but some lines are dependent on lines before it.</div>
<div>&nbsp;</div>
<h2>2. Getting Cozy with the Twitter API</h2>
<p>To work with Twitter, you actually need to sign up your application and get a username and password to access Twitter&#8217;s interface. These are called the consumer key and consumer secret. You can get these by signing up <a href="https://dev.twitter.com/apps/new">here</a>. Keep the consumer key and secret handy, you will need them.</p>
<p>After you &#8220;create&#8221; your application with Twitter, there&#8217;s just one tiny little thing we have to do. Because Twitter sends users back to a callback URL, that URL has to be acceptable by Twitter. If you try putting in http://localhost, Twitter will reject it. It&#8217;s stingy like that. So we have to make Twitter believe that we have a real URL.</p>
<p>To do this, you can edit the host file. This process will depend on your operating system but the hosts file sets out the domains that are to be preferentially directed to certain locations. In our case, we will be directing something innocent like <a href="http://dev.koostudios.com">http://dev.koostudios.com</a>, which is not a real location, to our localhost, 127.0.0.1. So, find your hosts file (try <a href="http://en.wikipedia.org/wiki/Hosts_(file)">this</a> if you don&#8217;t know where it is) and open it up in your favourite editor to add the following line. You may need root access.</p>
<pre class="brush: plain; title: ; notranslate">
127.0.0.1  dev.koostudios.com
</pre>
<p>Feel free to substitute your own namespace! Save the file and get ready for the awesomesauce.</p>
<h2>3. Starting with Everyauth</h2>
<p>Whoa! That was a lot of configuration wasn&#8217;t it? Let&#8217;s get on to the easy bit with the logging in part. First things first, this is the application logic to log into Twitter. Place this in the <strong>main.coffee</strong> file <em>above</em>the app configuration lines.</p>
<pre class="brush: coffeescript; title: ; notranslate">
everyauth = require 'everyauth'
everyauth.twitter
    .consumerKey('')
    .consumerSecret('')
    .findOrCreateUser((session, token, secret, user) -&gt;
        promise = @.Promise().fulfill user
    ).redirectPath '/'
</pre>
<p>Done! That&#8217;s it! This is the backend of the logging in process. We tell our application to include the package <strong>everyauth</strong> and use the <strong>twitter</strong> method (Lines 1 and 2). Then, we give it our consumer key and secret (Lines 3 and 4) and the real magic happens in the findOrCreateUser method. This allows you to log in to Twitter when the browser is turned to <strong>/auth/twitter</strong> and be returned straight back to the root location. Plus logging out is as easy as hitting up <strong>/logout</strong>. All Automagically!</p>
<p>What isn&#8217;t much explained is <strong>Line 6</strong>. OAuth requires you to send back information from your end of who is actually logging in. However, because NodeJS is asynchronous, that is, it keeps on going and does not wait for lines to stop, it is a tad too fast and sends out a promise that we will give it user information instead. The findOrCreateUser function must return a fulfilled promise so I&#8217;ve just sent the user information straight back in Line 6. Please note, normally we would have a few lines before fulfilling the promise to find the user on our database first (as we see later).</p>
<h2>4. Fun with Front-End</h2>
<p>Now that you have the entire login mechanism on the back-end, it is time to deal with the front-end. As mentioned previously, you only need a link to <strong>/auth/twitter</strong> to start the login process and a link to <strong>/logout</strong> to log out. So let us set up the link for logging in and logging out by determining whether we&#8217;ve logged in. Heck, let&#8217;s even add a greeting to say hi when they&#8217;ve logged in. Here is the routing done on <strong>main.coffee</strong>.</p>
<pre class="brush: coffeescript; title: ; notranslate">
app.get '/', (res, req) -&gt;
    if (req.session.auth)
        user = req.session.auth.twitter.screen_name

res.render('index', {
    layout: false
    locals: {user: user}
}
</pre>
<p>Notice that I am still rendering &#8216;index&#8217; if I am logged in or not. The only difference is that the user variable will be set to their twitter screen name if they are logged in or will be undefined if they are logged out. We can use this information now to build <strong>index.jade</strong>.</p>
<pre class="brush: plain; title: ; notranslate">
!!! 5
html
    body
        - if (typeOf(user) != 'undefined')
            span= &quot;Hi, &quot; + user + &quot; &quot;
            a(href=&quot;/logout&quot;) = &quot;Logout&quot;
        - else
            a(href= &quot;/auth/twitter&quot;)= &quot;Login&quot;
</pre>
<p>And that&#8217;s done! We&#8217;re using the neat JavaScript feature in index.jade to figure out whether user is defined or not and displaying a greeting with a logout button or a login button depending on the answer. Cool, huh?</p>
<h2>5. Running</h2>
<p>If you are using the awesome coffee &#8211;watch command, your amazing coffee files will have been compiled. However, if you are not, run the following in your project folder:</p>
<pre class="brush: plain; title: ; notranslate">coffee --compile main.coffee</pre>
<p>Now, you can run your little monster! Simply type:</p>
<pre class="brush: plain; title: ; notranslate">node main.js</pre>
<p>Remember the compiled version of the file is the one you need to run! And if you get your own lovely message of &#8216;Server running at http://localhost:1337&#8242;, you know you&#8217;ve got yourself a winner. Just hit up your browser and take a look at the magic!</p>
<h2>Conclusion</h2>
<p>Dealing with OAuth in NodeJS is dead simple. In fact, I think it is laughably simple. EveryAuth deals with everything and deals with everything automagically for you. You simply have to give it your API details and it logs the user in, saves their information in a cookie and lets you have default login and logout paths. The great thing about EveryAuth is that the process is pretty much the same for all the other APIs that it supports, so don&#8217;t stop with Twitter but keep going&#8230; Google, Facebook, LinkedIn&#8230; it all awaits!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=453</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Blog with CoffeeScript, Node.js and CouchDB</title>
		<link>http://blog.koostudios.com/?p=398</link>
		<comments>http://blog.koostudios.com/?p=398#comments</comments>
		<pubDate>Sat, 04 Feb 2012 05:40:32 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=398</guid>
		<description><![CDATA[The combination of CoffeeScript, Node.js and CouchDB as a language, a server-side environment and database isn&#8217;t just amazingly cool and hip. It&#8217;s cool and hip for a reason. And that reason is because it is outrageously simple and blazingly fast &#8230; <a href="http://blog.koostudios.com/?p=398">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.koostudios.com/wp-content/uploads/2012/02/couchpress.jpg"><img class="aligncenter size-full wp-image-444" title="couchpress" src="http://blog.koostudios.com/wp-content/uploads/2012/02/couchpress.jpg" alt="" width="620" height="434" /></a></p>
<p>The combination of CoffeeScript, Node.js and CouchDB as a language, a server-side environment and database isn&#8217;t just amazingly cool and hip. It&#8217;s cool and hip for a reason. And that reason is because it is outrageously simple and blazingly fast to write a very cool web application. But as fast and simple as it is, tutorials and documentation are somehow lacking or non-existent and following them just leave beginners frustrated. So here is a comprehensive tutorial on building a simple blog made with CoffeeScript, NodeJS and CouchDB. It&#8217;s not really for professionals but great for the curious and hobbyists who want to move from more traditional server-side technologies to Node.<br />
<span id="more-398"></span></p>
<blockquote><p><strong>Update:</strong> I have changed a couple of things to make it much more easier for first time CoffeeScript, NodeJS or CouchDB users. So if you find yourself in a bit of trouble, make sure you read the Tips before you start doing anything.</p></blockquote>
<h2>The Aim</h2>
<p>Forget the &#8220;Hello Worlds!&#8221; let&#8217;s build a simple blog! For a simple blog I want to be able to:</p>
<ul>
<li>To view all the posts</li>
<li>To add a post</li>
</ul>
<p>Two simple objectives. To achieve this, we&#8217;re going to use the following software. If you want to follow along, I recommend installing these using the links given (most need the <a href="http://npmjs.org/">Node Package Manager</a>).</p>
<ul>
<li><a href="http://nodejs.org">NodeJS</a> (v 0.6.9)</li>
<li><a href="http://couchdb.apache.org/">CouchDB</a> (v 1.0.2)</li>
<li><a href="http://coffeescript.org/">CoffeeScript</a> (v 1.2.0)</li>
<li><a href="http://expressjs.com/">Express.js</a> (v 0.5.8)</li>
<li><a href="http://jade-lang.com">Jade Template Engine</a> (v 0.20.0)</li>
<li><a href="http://cloudhead.io/cradle">Cradle</a> (v 0.5.8)</li>
</ul>
<blockquote><p><strong>Tip:</strong> For CoffeeScript, Express and Jade, you can install them using the command &#8220;npm install &#8221; in your terminal. Depending on your system and privileges, you may want to install CoffeeScript and Express globally by the command &#8220;sudo npm install -g &#8221; to take advantage of their command-line interfaces. Or, you may install it locally to save it in your local node_modules folder. If you are unsure about installing packages globally, check out <a href="http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/">this</a></p></blockquote>
<h2>1. Setting Up</h2>
<p>For this simple blog, I recommend creating a project folder &#8220;couchpress&#8221;, a subfolder called &#8220;views&#8221; and another one called &#8220;public&#8221;.</p>
<p>Now let&#8217;s understand this structure a bit. All the application logic, the CoffeeScript and JavaScript files go in the project folder, the root directory that I&#8217;ve called &#8220;couchpress&#8221;. The <strong>/views</strong> folder contains all the template files using the Jade Template Engine and the <strong>/public</strong> folder contains all the static content; images, client-side JavaScripts and stylesheets.</p>
<p>Now that we&#8217;re organised in our mind what goes where, let&#8217;s tell NodeJS, the server-side environment of our blog. Let&#8217;s create a file named &#8220;<strong>main.coffee</strong>&#8221; with the following in it:</p>
<pre class="brush: coffeescript; title: ; notranslate">
# Requires and Variables
exp = require 'express'
app = exp.createServer()

# App Configuration
app.configure () -&gt;
    app.set 'view engine', 'jade'
    app.set 'views', __dirname + '/views'
    app.use exp.static __dirname + '/public'
    app.use exp.bodyParser()
    app.use exp.methodOverride()

# Run App
app.listen 1337
console.log 'Server running at http://localhost:1337/'
</pre>
<blockquote><p><strong>Tip:</strong> While it looks like I&#8217;ve put the indentation (the tabs) on the file to make it look pretty, they are actually necessary in CoffeeScript. Make sure you follow the indentation as I have in this tutorial. As a rule of thumb, indent when you write the lines of a function or some other kind of block like an &#8220;if&#8221; statement. If you do not follow the indentation, CoffeeScript will not understand which lines are for which function and throw errors at you.</p></blockquote>
<p>NodeJS can run off a single JavaScript file like this <strong>main.coffee</strong> which contains all the code to essentially create the server. I&#8217;m using Express, a web development framework for NodeJS, which essentially relieves me of creating all the server stuff over and over again for each project. Instead, the first two lines are nearly all that is necessary. The <strong>first</strong> to tell Node that we need Express and will call it &#8216;exp&#8217; from now on and the <strong>second</strong> to create the server.</p>
<p>The configuration is pretty simple as well. Let&#8217;s go through it:</p>
<ul>
<li><strong>Line 7</strong> sets the template engine, Jade, as the view engine. We&#8217;ll talk about this later but it means we don&#8217;t have to add the &#8220;.jade&#8221; extension.</li>
<li><strong>Lines 8 and 9</strong> sets the folders for views (template files) in the <strong>/views</strong> folder and the static folder as the <strong>/public</strong> folder. Notice the &#8220;__dirname&#8221; part sorts out the location of the current file and everything else is in relation to that.</li>
<li><strong>Line 10 </strong>tells Express to use methodOverride() that let&#8217;s us use Node using RESTful methods. With this, we will be able to post forms to a specific location and let Node handle it. We need this in our new post form.</li>
</ul>
<div>Finally, the last two lines just tell us to connect it to port 1337, my favourite port for Node and the console.log gives us a response when running it.</div>
<div>&nbsp;</div>
<h2>2. Connecting Up the Database</h2>
<p>Now that we&#8217;ve got the boring stuff out of the way, let&#8217;s have some fun with the database. If you&#8217;ve followed the installation guides for CouchDB well enough, you should be able to hit up <a href="http://localhost:5984/_utils/">http://localhost:5984/_utils/</a> to access Futon, the command centre for your database. Or, if you&#8217;re on a Mac, you can open up the application CouchDBX<strong>.</strong></p>
<p>Let&#8217;s create a new database using the &#8220;<strong>New Database</strong>&#8221; button (I&#8217;ve called mine &#8220;couchpress&#8221;) and get straight on to creating our first <strong>view</strong>to simply list all the posts. The quickest and easiest way to do this is to open up the database you&#8217;ve just created and select &#8220;<strong>Temporary view&#8230;</strong>&#8221; in the dropdown box in the top right. We just need to save this default view using the &#8220;<strong>Save As</strong>&#8221; button and save it in the design document &#8220;<strong>_design/couchpress</strong>&#8221; with the view name of &#8220;<strong>all</strong>&#8220;.</p>
<p><a href="http://blog.koostudios.com/wp-content/uploads/2012/02/couchdbx.png"><img class="aligncenter size-full wp-image-423" title="couchdbx" src="http://blog.koostudios.com/wp-content/uploads/2012/02/couchdbx.png" alt="" width="620" height="388" /></a></p>
<p>If you&#8217;re unfamiliar with views, they&#8217;re the lifeblood of CouchDB and makes querying very much faster because it generates the results of a query ahead of time. It&#8217;s really the equivalent of a report. But much cooler. If you want to know more, try the <a href="http://guide.couchdb.org">CouchDB Guide</a>.</p>
<blockquote><p><strong>Tip:</strong> If you would like to learn how to add a new post through Futon (the name of this CouchDB utility), go back to the main screen and click on your database and create a new document using the &#8220;New Document&#8221; button. The &#8220;_id&#8221; of the document is automatically generated by CouchDB so we will let it be but let&#8217;s create two fields using the &#8220;Add Field&#8221; button. Create a &#8220;body&#8221; and a &#8220;title&#8221; field and put in there what you would like. A &#8220;Hello World&#8221; will do in each case.</p></blockquote>
<p>Now that the database is set up (I know <em>quick</em>, right?), we need to connect with it. For this, I&#8217;m creating a class called &#8220;Articler&#8221; to handle all the article functions in a file called<strong> articler.coffee</strong>, also in the same folder as our <strong>main.coffee</strong>. This is what&#8217;s in it:</p>
<pre class="brush: coffeescript; title: ; notranslate">
# Articler Class - Handles all article functions
cradle = require 'cradle'

class Articler
    constructor: (host, port) -&gt;
        @connect = new cradle.Connection host, port, {
            cache: true
            raw: false
        }
        @db = @connect.database 'couchpress'

    findAll: (callback) -&gt;
        @db.view 'couchpress/all', {descending: true}, (err, res) -&gt;
            if (err)
                callback err
            else
                docs = []
                res.forEach (row) -&gt;
                    docs.push row
                callback null, docs

    save: (articles, callback) -&gt;
        @db.save articles, (err, res) -&gt;
            if (err)
                callback err
            else
                callback null, articles

exports.Articler = Articler
</pre>
<blockquote><p><strong>Tip:</strong> Those &#8216;@&#8217; signs look funny don&#8217;t they? An @ sign in CoffeeScript simply stands for &#8220;this.&#8221;. It is just a quick shortcut that is very useful to know.</p></blockquote>
<p>Articler looks a bit complicated but everything is really easy. Articler has three methods: the <strong>constructor</strong> (which connects with database), <strong>findAll</strong> (which displays all the posts) and <strong>save</strong> (which saves, duh):</p>
<ul>
<li>The <strong>constructor</strong> method lets us do all the talking through the namespace <strong>@db</strong> as we set it to our database &#8216;couchpress&#8217; and in the rest of the methods, we simply do an action towards the database.</li>
<li>In <strong>findAll</strong>, we pointed to the view document we created just moments ago using:<br />
@db.view &#8216;couchpress/all&#8217;</li>
<li>In <strong>save</strong>, we save the variable <em>articles</em>, which will be an array we will be putting in it using:<br />
@db.view articles</li>
</ul>
<p>The rest is just callback functions so that we can pass on the variables gathered from the database. For example, in <strong>findAll</strong>, we put everything into the array called <strong>docs</strong> so that we can present it on the screen.</p>
<p>To join our newly created Articler class to our <strong>main.coffee</strong> file, we just need to add these lines after the configuration to grab the Articler class and then point in the direction of our CouchDB url in new instance of Articler:</p>
<pre class="brush: coffeescript; title: ; notranslate">
# Articler Class
Articler = require('./articler').Articler
article = new Articler 'http://localhost', 5984
</pre>
<p>There we go! The great thing is that the Articler class can be copied and pasted in every app where you want to contact a CouchDB.</p>
<blockquote><p><strong>Tip:</strong> Before you continue, you may want to check that you have created the database correctly and the view correctly by going to your database folder through your browser. In my case, that is http://localhost:5984/couchpress/. If you see the doc_count to be greater than 0, then you should have done everything but if you have a doc_count of 0, try going over the steps to see if you have missed something.</p></blockquote>
<h2>3. Creating the Frontend</h2>
<p>Now that we&#8217;ve got the server and the database, we can turn our attention to the displaying of our information. First, we&#8217;ll create a jade template file called <strong>layout.jade</strong> in the <strong>/views</strong> folder. Express uses this file as a template for every page. Therefore, you want to put things like the header and footer in there. I&#8217;ve also took the liberty of creating a CSS stylesheet but you should be able to do that. Remember create the stylesheet in the <strong>/public</strong> folder and link it as below:</p>
<pre class="brush: plain; title: ; notranslate">
!!! 5
html(lang=&quot;en&quot;)
    head
        title= title
        link(rel= 'stylesheet', href= '/style.css')
    body
        header
            a(href='/')
                h1= 'CouchPress'
        section.content
            != body
</pre>
<p><strong>Jade</strong> is a templating engine that lets us create markup by just writing the tag and then putting the contents of that tag either after the equal signs (i.e. h1= &#8216;Couchpress&#8217;) or on the next lines marked by a tab (like the header tag). What&#8217;s more is that anything not in quotation marks can be a variable. For example, we will be changing the title of the page to reflect what we&#8217;re doing. Furthermore, the rest of the page is marked by the != body.</p>
<blockquote><p><strong>Tip: </strong> You will notice that there Jade includes a lot of logic. That is part of the beauty but also the font of most of your annoyance. Make sure you keep with the indentation and type everything, especially the symbols correctly. Jade will not be as sympathetic as HTML.</p></blockquote>
<p>To fill the body, let&#8217;s create an index page called <strong>index.jade</strong> also in the <strong>/views</strong> folder where we will be listing all the posts:</p>
<pre class="brush: plain; title: ; notranslate">
- each article in articles
    .article
        h1= article.title
        span.created= article.created_at
        span.body= article.body
</pre>
<p>This is where Jade comes to its prime. It is able to use a bit of logic in the form of JavaScript to iterate over an array, like the JSON one that CouchDB is going to give us. The first line marked with the &#8220;-&#8221; is the JavaScript that tells Jade to go through every item in the array that we will pass to it.</p>
<p>Finally, I&#8217;ll create a quick form called <strong>new.jade</strong> also in the <strong>/views</strong> folder to create new posts:</p>
<pre class="brush: plain; title: ; notranslate">
form(method=&quot;post&quot;)
    input(type=&quot;text&quot;, name=&quot;title&quot;, placeholder=&quot;Title&quot;)

textarea(name=&quot;body&quot;, rows=&quot;20&quot;)
input(type=&quot;submit&quot;, value=&quot;Publish&quot;)
</pre>
<p>Great. We&#8217;ve created three files in the <strong>/views</strong> folder: <strong>layout.jade</strong> for the template, <strong>index.jade</strong> to list all the articles and <strong>new.jade</strong> to create a form to publish new posts.</p>
<h2>4. The Final Bits</h2>
<p>The last thing we have to do now is to join up what the user does in the browser to everything we&#8217;ve created. In Express, the easy way to do this is via routing. Routing uses the usual HTTP commands like &#8220;get&#8221; and &#8220;post&#8221; but allows us to code our own magic to each of these.</p>
<p>Ok, let&#8217;s start with the index. When people go to the domain (which we call &#8220;/&#8221;), we want to grab the <strong>findAll</strong> function of Articler and then put it all in the index.jade to show us all the post. For this, we need the following lines in <strong>main.coffee</strong> (after everything else we&#8217;ve done):</p>
<pre class="brush: coffeescript; title: ; notranslate">
app.get '/', (req, res) -&gt;
    article.findAll (err, docs) -&gt;
        res.render 'index', {
            locals: {
                title: 'CouchPress'
                articles: docs
             }
        }
</pre>
<p>Notice that we render &#8216;index&#8217; which is the &#8216;index.jade&#8217;. Because we set the view engine to jade and the view folder to /views, Express knows where to look and doesn&#8217;t need to extension &#8216;.jade&#8217;. And, remember the variables we put in the Jade files? Well, they&#8217;re the &#8220;local&#8221; variables. I want to set the page title to &#8216;Couchpress&#8217; and the articles as the docs that Articler is going to give us.</p>
<p>Now, we can deal with posting a new post. First we have to display the form when the user goes to &#8220;/new&#8221; or in our case, &#8220;http://localhost:1337/new&#8221;. That&#8217;s as simple as this:</p>
<pre class="brush: coffeescript; title: ; notranslate">
app.get '/new', (req, res) -&gt;
    res.render 'new', {locals: {title: 'CouchPress / New Post'}}
</pre>
<p>And then to process the form, we grab the form details that will be posted to &#8220;/new&#8221; and then save it using the Articler method <strong>save</strong>. You can grab the form post parameters by using <strong>req.param</strong> and then the name of the input, like so:</p>
<pre class="brush: coffeescript; title: ; notranslate">
app.post '/new', (req, res) -&gt;
    article.save {
        title: req.param 'title'
        body: req.param 'body'
        created_at: new Date()
    }, (err, docs) -&gt;
        res.redirect('/')
</pre>
<p>Don&#8217;t forget, the last line is the callback to tell the browser to redirect when it is all good and done!</p>
<h2>5. Running</h2>
<p>Wow it&#8217;s been quite a journey! Now let&#8217;s test it. First, if you haven&#8217;t been using the nifty CoffeeScript command &#8220;coffee &#8211;watch&#8221;, then we have to compile the files. Direct your terminal to the project folder (for me, that&#8217;s <strong>couchpress</strong>), and then use the following command:</p>
<pre class="brush: plain; title: ; notranslate">coffee --compile main.coffee articler.coffee</pre>
<p>If you look at the folder now, coffee has created two files into JavaScript for you. Awesome! Now, you can run your project (while double-crossing your fingers hoping that you&#8217;ve done nothing wrong). To run the project, just run:</p>
<pre class="brush: plain; title: ; notranslate">node main.js</pre>
<p>If you get your message &#8220;Server running at http://localhost:1337&#8243;, you can breathe a little easier. Now, you can try out your baby! Because we don&#8217;t have any posts, go to <a href="http://localhost:1337/new">http://localhost:1337/new</a> in your favourite browser and create a post. And, because we&#8217;ve made a redirect, so it should redirect you to <a href="http://localhost:1337">http://locahost:1337/</a> and you can view your site!</p>
<blockquote><p><strong>Tip:</strong> Node will give you an error if go straight to &#8220;/&#8221; because there&#8217;s nothing in the database. But I am sure that you can now figure out how to deal with an empty database (<strong>hint</strong>: we&#8217;ve put in nice little error variables so you can pass on errors).</p></blockquote>
<p>There it is! A quick blogging platform that let&#8217;s you view all the posts and save them!</p>
<h2>Conclusion</h2>
<p>While our blog is not quite production ready, we <em>have</em> managed to create a basic server, link it to a database, create a frontend and join it altogether in less than 100 lines of code (go on count it) and for me, under an hour. And, it works! Furthermore, this little blog software which can retrieve entries from a database, display it with Jade files and save entries into a database forms the basis of almost any application. So you&#8217;ve learnt quite enough to make your own applications! In under 100 lines! I hope this article shows that the combination of CoffeeScript, NodeJS and CouchDB (along with all the other technologies we&#8217;ve used) is an amazing mix of fast and innovative technology that allows one to create quick and elegant web applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=398</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Why I&#8217;m Writing in CoffeeScript Next</title>
		<link>http://blog.koostudios.com/?p=382</link>
		<comments>http://blog.koostudios.com/?p=382#comments</comments>
		<pubDate>Mon, 23 Jan 2012 13:46:33 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=382</guid>
		<description><![CDATA[Enjoying the Coffee Experience &#8211; Photo by Josh Liba I have to admit. My foray into Ruby and Python left me a little jealous. Here was two, very beautiful, elegant, succinct and whitespaced languages that shone in comparison with my &#8230; <a href="http://blog.koostudios.com/?p=382">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://farm3.staticflickr.com/2796/4184463547_0b04939b93_z.jpg" alt="" width="620" /><small><em>Enjoying the Coffee Experience &#8211; Photo by <a href="http://www.flickr.com/photos/jliba/4184463547/">Josh Liba</a></em></small></p>
<p>I have to admit. My foray into Ruby and Python left me a little jealous. Here was two, very beautiful, elegant, succinct and whitespaced languages that shone in comparison with my language of choice, JavaScript. Of course, I could not be converted to Ruby or Python, simply because I enjoy client-side development and JavaScript, with its applications in <a href="commonjs.org/">CommonJS</a>, <a href="nodejs.org/">NodeJS</a> and others, is currently showing great promise as a all-round language, capable of many, many things. But there were so many things that you could like about Ruby and Python that just wasn&#8217;t in JavaScript. And then, I stumbled upon <a href="coffeescript.org">CoffeeScript</a>.<span id="more-382"></span></p>
<p><img class="aligncenter" src="http://upload.wikimedia.org/wikipedia/en/1/1c/CoffeeScript-logo.png" alt="" width="250" height="67" /></p>
<p>CoffeeScript is not JavaScript. It&#8217;s a little language, inspired by both Ruby and Python, that allows you to write scripts quickly and then compile them to JavaScript, or to be technical, transcompile into JavaScript. There&#8217;s no interpreter at runtime, like Ruby or Python, but it means that you can use CoffeeScript everywhere where you use JavaScript. Compiled with the included <a href="http://zaach.github.com/jison/">J</a><a href="http://zaach.github.com/jison/">ison</a>-based compiler (written in CoffeeScript!), CoffeeScript scripts are mostly faster than pure JavaScript and you can use it with any other existing JavaScript library seamlessly. Awesome.</p>
<p>How can a language that essentially uses nearly identical syntax as JavaScript be as awesome as Ruby or Python? It starts with removing the ugly things. Curly brackets are gone, replaced by whitespace, just like Python (which is my favourite feature). So are semi-colons, the most controversial character in the JavaScript writer&#8217;s arsenal. And then, there are the JavaScript improvements. The language gets rid of global variables, the nightmare that they are, and leaves only local variables. Functions are replaced with a simple arrow &#8220;-&gt;&#8221; and iterators are done Python and Ruby style with the &#8220;for i in array&#8221; line. They even replace the common &#8220;this&#8221; item with a simple &#8220;@&#8221;. Brilliant.</p>
<p style="text-align: center;"><a href="http://blog.koostudios.com/wp-content/uploads/2012/01/coffeescript1.png"><img class="aligncenter  wp-image-387" title="coffeescript" src="http://blog.koostudios.com/wp-content/uploads/2012/01/coffeescript1.png" alt="" width="620" /></a></p>
<p> What is interesting in CoffeeScript is that it encourages the use of classes with its simple class structure, as in Ruby and Python. JavaScript is actually a somewhat class-based object-orientated programming language, though using classes are very, very rare, most likely because of its near impossible syntax. However, classes are dead simple in CoffeeScript and uses the same conventions as any other programming language with a &#8220;class&#8221; declaration for once that is sure to improve scripting in general. Super simple and elegant.</p>
<p>To be honest, I had some reservations about using CoffeeScript. The first time I read the documentation, I did dismiss it a bit. I thought, rather wrongly, that it was another metalanguage, like Sass, Haml or Stylus that didn&#8217;t really change the language much and offered little drastic improvements. But I would argue CoffeeScript is quite different from JavaScript and tries to make JavaScript ever nicer and closer to Python or Ruby.</p>
<p>Then there&#8217;s the fact that it must be compiled, meaning there&#8217;s another step you have to do. But you don&#8217;t mind it after a while, especially after you write a quick AppleScript in your favourite editor to compile it. Plus, you can have the option to add a quick script in browser so that it runs on the page as a &#8220;text/coffeescript&#8221;. That is pretty neat. And, lastly, but most importantly, CoffeeScript is still JavaScript and will still have the problems of JavaScript as long as it has to be compiled back down to it. However, as I said before, that is what makes it particularly awesome as it means that you can use CoffeeScript basically anywhere that JavaScript can be used. Which these days, is pretty much anywhere.</p>
<p>People are raving about CoffeeScript. And I can see why. The language is pretty and elegant, it&#8217;s fast to write and run, and it goes everywhere JavaScript goes. The language brings pure joy to the writing of JavaScript applications and alleviates most of the gotchas of JavaScript. However, moving to CoffeeScript is going to be hard. And, as long as it is not supported in browsers or applications, it will be another language to switch between in development. Nevertheless, let&#8217;s start this brave adventure in a pretty, pretty land.</p>
<p><em>CoffeeScript is released under the MIT Licence. Try it out now at <a href="http://coffeescript.org/">coffeescript.org</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=382</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Throwing a Dart into the Ring</title>
		<link>http://blog.koostudios.com/?p=369</link>
		<comments>http://blog.koostudios.com/?p=369#comments</comments>
		<pubDate>Tue, 11 Oct 2011 03:22:09 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=369</guid>
		<description><![CDATA[The Dart Logo - Dartlang.org Dart, a new structured programming language for the web, has just been announced today by Google. Despite the fact that Google has pretty much failed to introduce a widely-used programming language before, this new foray into &#8230; <a href="http://blog.koostudios.com/?p=369">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><a href="http://blog.koostudios.com/?p=369"><img class="aligncenter size-full wp-image-372" title="dart" src="http://blog.koostudios.com/wp-content/uploads/2011/10/dart.jpg" alt="" width="620" height="300" /></a></p>
<p><em><small>The Dart Logo - <a href="http://dartlang.org">Dartlang.org</a></small></em></p>
<p><a href="http://www.dartlang.org/">Dart</a>, a new structured programming language for the web, has <a href="http://googlecode.blogspot.com/2011/10/dart-language-for-structured-web.html">just been announced today by Google</a>. Despite the fact that Google has pretty much failed to introduce a widely-used programming language <a href="http://golang.org/">before</a>, this new foray into web programming languages seems promising. Interestingly, the authors of Dart have been vague about its use and there are possible hints that Dart may be used for cloud-based applications in a standardised mobile platform. Most of the features, like types and the object-orientated structure hasn&#8217;t excited me as such, as they aren&#8217;t really innovations to programming languages. However, even in this early stage, some really awesome features have floated up and caught my eye.<span id="more-369"></span></p>
<h2>1. Isolates</h2>
<p>While Dart remains single-threaded like Javascript, it offers what they call <em>isolates</em>, or units for concurrency. Hence, blocks of code can be run concurrently with each other thereby creating several processes that can run at the same time. Additionally, separate isolates have their own memory and own thread of control so hopefully, an error in one thread won&#8217;t stop the entire application.</p>
<h2>2. Server-side Dart</h2>
<p>When I first heard of Dart (or Dash as it was called), I merely thought it was built to simply replace client-based javascript. However, its plans are much wider and greater than that. Dart was built from the ground up in the same idea as Javascript and NodeJS, a web programming language that could be run on both the server and the client. Additionally, because of its focus on web programming, it is tailored for quick performance and the authors aim to make it much faster.</p>
<h2>3. Snapshot</h2>
<p>Perhaps the most exciting news is the Snapshot feature, even though this isn&#8217;t exactly a feature of the language. This allows the VM to load code 10 times faster as it initialises the code beforehand and allows an application to start an instance at that point. This would be where the speed gains are most impressive, especially as you don&#8217;t have to wait for all the code to initialise.</p>
<h2>Conclusion</h2>
<p>While Dart, like Google&#8217;s previous attempt Go, represents a promising future in web programming languages, it still remains to be seen if it can be adopted as a standard. Sure, there are some cool features as outlined above but the real test is to see if Dart is adopted by other browsers so it can garner widespread use. At the moment, it&#8217;s certainly interesting to play with but Google should find  other ways of enticing us towards Dart.</p>
<p>For more information on Dart, be sure to check out its <a href="http://dartlang.org">website</a> and the <a href="http://code.google.com/p/dart/">GoogleCode</a> website. Oh, and for once, the <a href="http://www.dartlang.org/docs/spec/dartLangSpec.pdf">specification</a> is worth reading and be sure to try the programming language out on the awesome <a href="http://try.dartlang.org/">Dartboard</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=369</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Portamento Makes Floating Panels Easy</title>
		<link>http://blog.koostudios.com/?p=360</link>
		<comments>http://blog.koostudios.com/?p=360#comments</comments>
		<pubDate>Fri, 26 Aug 2011 03:27:37 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=360</guid>
		<description><![CDATA[Floating like a lotus flower There&#8217;s a growing trend towards using what are called floating or sliding panels. What are floating panels? To put most simply, they are panels (most likely &#60;div&#62; tags) that stay in their position while the &#8230; <a href="http://blog.koostudios.com/?p=360">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/Lotus.jpg"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/Lotus.jpg" alt="" title="Lotus" width="620" height="301" class="aligncenter size-full wp-image-361" /></a><small><em>Floating like a lotus flower</small></em></p>
<p>There&#8217;s a growing trend towards using what are called floating or sliding panels. What are floating panels? To put most simply, they are panels (most likely &lt;div&gt; tags) that stay in their position while the user is scrolling down. It is particularly useful for bringing into light important things such as information about the site, or bringing the attention of the user towards call to action buttons, like &#8220;Download Now&#8221; or &#8220;Sign Up&#8221; kind of buttons. How to? Well, <a href="http://simianstudios.com/portamento/">Portamento</a> is a neat jQuery plugin that lets you do just that &#8211; and do it simply.<span id="more-360"></span></p>
<p>Portamento needs only to be stuck on the end of a selector to work (after you include jQuery and the plugin of course):</p>
<pre class="brush: jscript; title: ; notranslate">
$('div.element').portamento();
</pre>
<p>Simple! This plugin also lets you specify a wrapper that you want the sliding panel to stay within, and a gap from the top to make sure your new floating panel isn&#8217;t in the wrong place and covering another element.</p>
<p>Portamento is very simple and easy to use, and even includes a workaround for legacy browsers that don&#8217;t quite support the <code>position: fixed</code> CSS property (which is how a floating panel works). Visit their site to try it out and download it <a href="http://simianstudios.com/portamento/">here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=360</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inspiration &#8211; CSS Inspiration Galleries</title>
		<link>http://blog.koostudios.com/?p=350</link>
		<comments>http://blog.koostudios.com/?p=350#comments</comments>
		<pubDate>Wed, 24 Aug 2011 08:12:17 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=350</guid>
		<description><![CDATA[I love good design and one of my past-times is trawling through websites dedicated to being galleries of nicely designed websites. Not only can you absorb the delicious eye-candy, but also a lot to learn from looking at other people&#8217;s &#8230; <a href="http://blog.koostudios.com/?p=350">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.koostudios.com/?p=350"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/Awwwards.png" alt="" title="Awwwards" width="620" height="300" class="aligncenter size-full wp-image-353" /></a><br />
I love good design and one of my past-times is trawling through websites dedicated to being galleries of nicely designed websites. Not only can you absorb the delicious eye-candy, but also a lot to learn from looking at other people&#8217;s designs, especially those chosen by the design community as particularly beautiful, innovative or just nicely designed. Keep reading for some of my favourite website or inspiration galleries!<span id="more-350"></span></p>
<h2>CSS Gallery</h2>
<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/CSS-Gallery.com_.png"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/CSS-Gallery.com_.png" alt="" title="CSS Gallery.com" width="620" height="300" class="aligncenter size-full wp-image-351" /></a><br />
Produced by the venerable <a href="http://smashingmagazine.com">Smashing Magazine</a>, CSS Gallery is the site to be at because it is full of inspiration awesomeness. Sites selected always have an edge and the easy navigation of the site makes viewing amazing designs so easy!</p>
<p><center><a class="more-link" href="http://www.cssgallery.com/">Visit</a></center></p>
<h2>CSS Mania</h2>
<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/CSS-Mania.png"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/CSS-Mania.png" alt="" title="CSS Mania" width="620" height="300" class="aligncenter size-full wp-image-352" /></a><br />
With a website that is <i>so</i> nice it deserves to be featured in another gallery, <a href="http://www.cssmania.com/" target="_new">CSS Mania</a> is a friendly-looking website with big thumbnails (big plus!). An important and useful feature is the ability to choose colours and their colour selector does it really well (it just needs a search function).</p>
<p><center><a class="more-link" href="http://www.cssmania.com/">Visit</a></center></p>
<h2>Awwwards</h2>
<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/Awwwards.png"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/Awwwards.png" alt="" title="Awwwards" width="620" height="300" class="aligncenter size-full wp-image-353" /></a><br />
Not really an inspiration gallery, Awwwards features selected websites that have received the somewhat awkwardly named &#8220;Awwwards&#8221;. Selected daily by an international jury of talented designers, the websites have been rated so you get to see the best but also figure what the designers did best and what they could have done better.</p>
<p><center><a class="more-link" href="http://www.awwwards.com/">Visit</a></center></p>
<h2>One Page Love</h2>
<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/One-Page-Love.png"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/One-Page-Love.png" alt="" title="One Page Love" width="620" height="300" class="aligncenter size-full wp-image-354" /></a><br />
Uniquely focussing on one page websites, One Page Love sports an easy blog-like interface that makes you just want to keep scrolling down, pressing the next page, rinse and repeat. The websites featured are always amazing and innovative with keeping everything on one page.</p>
<p><center><a class="more-link" href="http://www.onepagelove.com/">Visit</a></center></p>
<h2>Web Creme</h2>
<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/Web-Creme.png"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/Web-Creme.png" alt="" title="Web Creme" width="620" height="300" class="aligncenter size-full wp-image-355" /></a><br />
The design of Web Creme may be simple but the ease of the site is a big plus. All sites are given categories of colour so it is very easy to focus and look at just blue websites. Neat.</p>
<p><center><a class="more-link" href="http://www.webcreme.com/">Visit</a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=350</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 HTML5 Lifesaving Fallbacks</title>
		<link>http://blog.koostudios.com/?p=332</link>
		<comments>http://blog.koostudios.com/?p=332#comments</comments>
		<pubDate>Mon, 22 Aug 2011 07:21:35 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=332</guid>
		<description><![CDATA[Mmmmm&#8230; HTML5 &#8211; Photo by slavic_V HTML5 and its lovely brother CSS3 are both very fun and easy to use and produces wonderful results. That is, until your client views your beautifully designed and coded site in the dreaded Internet &#8230; <a href="http://blog.koostudios.com/?p=332">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/DSC_0010.jpg"><img src="http://blog.koostudios.com/wp-content/uploads/2011/08/DSC_0010.jpg" alt="" title="DSC_0010" width="618" height="300" class="aligncenter size-full wp-image-335" /></a><small><em>Mmmmm&#8230; HTML5 &#8211; Photo by <a href="http://www.flickr.com/photos/22290288@N03/5865570794">slavic_V</a></small></em></p>
<p>HTML5 and its lovely brother CSS3 are both very fun and easy to use and produces wonderful results. That is, until your client views your beautifully designed and coded site in the dreaded Internet Explorer. Audio and video elements don&#8217;t work, things go all over the place and don&#8217;t even mention the word semantics because I&#8217;m sorry, IE does not understand! Fortunately, there are many lifesaving ways to allow our sites to fallback on previous methods, or to &#8220;degrade&#8221; gracefully &#8211; so you wouldn&#8217;t notice there&#8217;s a difference. Keep reading to find out 5 ways of falling forward!<span id="more-332"></span></p>
<h2>Conditional Statements</h2>
<p>Want different stylesheets, or different scripts when you&#8217;re in a low-end browser? That&#8217;s easy with conditional statements. Normally, comments are ignored by browsers but some browsers (such as IE) can handle certain structures of comments as instructions. In this way, the browser can detect whether to include a certain stylesheet. So, if you want a stylesheet for a particular browser version, you just do this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE 6]&gt;
&lt;link rel=&quot;stylesheet&quot; src=&quot;ie6.css&quot;&gt;
&lt;![endif]--&gt;
</pre>
<p>The statements can be even more dynamic to include groups of browsers like these:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!--[if lt IE9]&gt;
&lt;!--[if lte IE8]&gt;
&lt;!--[if (IE6)|(IE7)]&gt;
</pre>
<p>However, this method, though useful, is generally discouraged because it is a little browser hack that is not maintained or standardised and are not so great semantically (and there are many other reasons &#8211; something for another blog!)</p>
<h2>HTML5 Natural Fallbacks</h2>
<p>Some elements in HTML5 have a neat feature of allowing fallbacks within their own elements. The best example of this is the &lt;audio&gt; and the &lt;video&gt; tags. If you put a fallback like a flash object within these tags, legacy browsers will ignore the new tags and just read the middle stuff while new browsers will recognise the new tags and read the new tags. Have a look:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;video src=&quot;movie.mp4&quot; controls&gt;
     &lt;embed src=&quot;movie.flv&quot; type=&quot;application/x-shockwave-flash&quot;  allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot;&gt;&lt;/embed&gt;
&lt;/video&gt;
</pre>
<p>Of course, this won&#8217;t work on everything but keep an eye out for these special elements because it does save a bit of time.</p>
<h2>Javascript Shiv</h2>
<p>Probably the most popular way is to tack on what&#8217;s called a javascript shiv (or shim). In javascript, it is possible to add elements that a browser does not understand and using this feature, add the additional elements that HTML5 provides. Thankfully, we don&#8217;t have add each one individually as some <a href="http://code.google.com/p/html5shiv/">good people</a> have already done it for us. Simply tack this on at the end of your &lt;head&gt;:</p>
<pre class="brush: xml; title: ; notranslate">&lt;script src=&quot;http://html5shiv.googlecode.com/svn/trunk/html5.js&quot;&gt;&lt;/script&gt;</pre>
<p>Keep in mind that IE will not suddenly recognise all your HTML5 features, but really this script gives you an ability to identify it within CSS and style it the way you like it. You can use a <a href="http://html5doctor.com/html-5-reset-stylesheet/">HTML5 Reset Stylesheet</a> to make sure all the new elements will display consistently. </p>
<h2>Modernizr</h2>
<p>Modenizr is an awesome javascript library that allows you to detect if features are available and then gets the client to download the right file. The library can detect a huge list of features and then allows you to write your own workaround. Using Modenizr is as simple as:</p>
<pre class="brush: jscript; title: ; notranslate">
Modernizr.load({
  test: Modernizr.geolocation,
  yep : 'geo.js',
  nope: 'geo-polyfill.js'
});
</pre>
<p>This tests if the browser supports geolocation, if yes, loads &#8220;geo.js&#8221; and if no loads &#8220;geo-polyfill.js&#8221;. Easy, no? Modenizr also allows you to fine tune responses for multiple features if necessary or even add your own test which you can script.</p>
<h2>Google Chrome Frame</h2>
<p>It&#8217;s not really a solution but if worse comes to worse, it is possible to use the Google Chrome Frame. The GCF (as it is more affectionately called) is an Internet Explorer plugin that allows IE to render exactly like the Google Chrome Browser. Therefore, it can support all your html5 just like that. To enable it for someone with GCF installed, you simply add:</p>
<pre class="brush: xml; title: ; notranslate">&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;chrome=1&quot;&gt;</pre>
<p>You may also want to ask someone to install GCF and Google comes with a script handy to check for and ask to install if GCF is not enabled. Simply put the following in the body somewhere:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;
     src=&quot;http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;prompt&quot;&gt;&lt;/div&gt;
&lt;script&gt;
     window.attachEvent(&quot;onload&quot;, function() {
       CFInstall.check({
         mode: &quot;inline&quot;, // the default
         node: &quot;prompt&quot;
       });
     });
&lt;/script&gt;
</pre>
<h2>Conclusion</h2>
<p>As you can see, there are many many ways to get around the annoyance of a browser not supporting a particular feature and most don&#8217;t take that much time. For most cases a shiv and some clever HTML and CSS is enough but for others, Modenizr is the way to go. However, these features are so important to keeping a consistent and better looking interface across all browsers. If you want to read or learn more about HTML5 fallbacks, be sure to check <a href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills">&#8220;The All-In-One Entirely-Not-Alphabetical No-Bullshit Guide to HTML5 Fallbacks&#8221;</a> which has a whole heap of information on this topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=332</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Friday Freebies &#8211; 5 Grass Wallpapers</title>
		<link>http://blog.koostudios.com/?p=302</link>
		<comments>http://blog.koostudios.com/?p=302#comments</comments>
		<pubDate>Thu, 18 Aug 2011 23:05:34 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Freebies]]></category>

		<guid isPermaLink="false">http://blog.koostudios.com/?p=302</guid>
		<description><![CDATA[Grass Wallpaper &#8211; Wallpaper by Uberfoto The one thing I like as much as creating wallpapers is finding wallpapers. As a guy who changes wallpapers nearly every week, I find a lot of great looking wallpapers on a day to &#8230; <a href="http://blog.koostudios.com/?p=302">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><a rel="attachment wp-att-317" href="http://blog.koostudios.com/?attachment_id=317"><img class="aligncenter size-full wp-image-317" title="grass_wallpaper_by_uberfoto-d2qr683" src="http://blog.koostudios.com/wp-content/uploads/2011/08/grass_wallpaper_by_uberfoto-d2qr6831.jpg" alt="" width="620" height="300" /></a><small><em>Grass Wallpaper &#8211; Wallpaper by Uberfoto</em></small></p>
<p>The one thing I like as much as creating wallpapers is finding wallpapers. As a guy who changes wallpapers nearly every week, I find a lot of great looking wallpapers on a day to day basis. There&#8217;s no wallpaper more peaceful and more beautiful than a nice grass wallpaper.  These are not mine, but a couple from the great community called the internet. Keep reading for download links!<span id="more-302"></span></p>
<h2>Longhorn Bliss by DJMattRicks</h2>
<p><center><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/lh_bliss2_005.jpg"><img class="aligncenter size-full wp-image-310" title="lh_bliss2_005" src="http://blog.koostudios.com/wp-content/uploads/2011/08/lh_bliss2_005.jpg" alt="" width="620" height="300" /></a><a class="more-link" href="http://browse.deviantart.com/?qh=&amp;section=&amp;global=1&amp;q=longhorn+bliss#/dwc60r">Download Now</a></center></p>
<h2>Grass Wallpaper by Uberfoto</h2>
<p><center><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/grass_wallpaper_by_uberfoto-d2qr683.jpg"><img class="aligncenter size-full wp-image-315" title="grass_wallpaper_by_uberfoto-d2qr683" src="http://blog.koostudios.com/wp-content/uploads/2011/08/grass_wallpaper_by_uberfoto-d2qr683.jpg" alt="" width="620" height="300" /></a><a class="more-link" href="http://www.gaia10.us/gallery/gallery-minimal/">Download Now</a></center></p>
<h2>Minimal by Pete Harrison</h2>
<p><center><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/Minimal.jpg"><img class="aligncenter size-full wp-image-303" title="Minimal" src="http://blog.koostudios.com/wp-content/uploads/2011/08/Minimal.jpg" alt="" width="619" height="300" /></a><a class="more-link" href="http://www.gaia10.us/gallery/gallery-minimal/">Download Now</a></center></p>
<h2>Longhorn Aero Grass by OsmosisChing</h2>
<p><center><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/longhorn_aero_grass_by_osmosisching-d2yfaiz.jpg"><img class="aligncenter size-full wp-image-313" title="longhorn_aero_grass_by_osmosisching-d2yfaiz" src="http://blog.koostudios.com/wp-content/uploads/2011/08/longhorn_aero_grass_by_osmosisching-d2yfaiz.jpg" alt="" width="620" height="300" /></a><a class="more-link" href="http://browse.deviantart.com/?qh=&amp;section=&amp;q=longhorn+grass#/d2yfaiz">Download Now</a></center></p>
<h2>Simpleness by Emats</h2>
<p><center><a href="http://blog.koostudios.com/wp-content/uploads/2011/08/Simpleness_by_emats.jpg"><img class="aligncenter size-full wp-image-316" title="Simpleness_by_emats" src="http://blog.koostudios.com/wp-content/uploads/2011/08/Simpleness_by_emats.jpg" alt="" width="619" height="300" /></a><a class="more-link" href="http://browse.deviantart.com/?qh=&amp;section=&amp;q=grass+wallpaper#/d231fdi">Download Now</a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koostudios.com/?feed=rss2&#038;p=302</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://stats.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

