<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>{Code: Impossible}</title>
    <link>http://codeimpossible.com</link>
    <description>It's just this blog, ya know?</description>
    <item>
      <title>NodeJS on Windows Part 3: The feedback loop</title>
      <link>http://codeimpossible.com/2012/4/30/NodeJS-on-Windows-Part-3-The-feedback-loop</link>
      <description>&lt;p&gt;
	&lt;a href="http://codeimpossible.com/2012/4/16/NodeJS-on-Windows-Part-2-using-the-Jade-ViewEngine"&gt;In the last blog post&lt;/a&gt; I showed you how to install jade and create your first view. However the development cycle leaves a lot to be desired. Nothing sucks more than the web ux/ui development cycle. Make a change, restart the server (optional), refresh the browser, lather rinse, repeat.&lt;/p&gt;
&lt;p&gt;
	I&amp;#39;m going to show you something awesome. Open a powershell window (&lt;a href="http://www.codeimpossible.com/2012/4/23/Reasons-to-use-PowerShell-instead-of-CMD"&gt;you &lt;strong&gt;are&lt;/strong&gt; using powershell aren&amp;#39;t you?&lt;/a&gt;) and execute:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ npm install supervisor -g
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	This will install a package named Supervisor globally on your machine. Now, I could &lt;em&gt;tell&lt;/em&gt; you what supervisor is but it&amp;#39;s waaaaaay better to show you. It&amp;#39;s ok, you can trust me, I&amp;#39;m a blog post.... those never lie.&lt;/p&gt;
&lt;p&gt;
	Anyway, let&amp;#39;s run supervisor on the node app we created last time.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ supervisor app.js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	You&amp;#39;ll see the normal app bootup messages, when you visit &lt;code&gt;http://localhost:8000&lt;/code&gt; the site should load normally and show you &amp;quot;Hello World!&amp;quot;.&lt;/p&gt;
&lt;p&gt;
	Aaaaaaand nothing is different.&lt;/p&gt;
&lt;h3&gt;
	What gives?&lt;/h3&gt;
&lt;p&gt;
	Yeah this doesn&amp;#39;t sound awesome yet... but it will soon enough. Open your app.js and add the following to the &lt;code&gt;configure()&lt;/code&gt; callback:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;console.log(&amp;quot;Jared is super awesome!&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Now, save your js file and check your powershell window. Go ahead... I&amp;#39;ll wait.&lt;/p&gt;
&lt;p&gt;
	WASN&amp;#39;T THAT AWESOME?!?! Supervisor watches all your js files for changes, when changes are detected it will reload the app automatically! So let&amp;#39;s change the header and see what happens.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;res.send(&amp;quot;&amp;lt;h1&amp;gt;Jared is the best!&amp;lt;/h1&amp;gt;&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Hmmm, looks like supervisor reloaded but we have to reload the browser manually. That seems... tedious. What if we wrote some code to have the client listen for changes on the server and refresh the page as needed?&lt;/p&gt;
&lt;h3&gt;
	Kick it up a notch&lt;/h3&gt;
&lt;p&gt;
	First, we&amp;#39;ll need a few more packages.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ npm install socket.io express
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Socket.io is a framework that makes &lt;a href="http://en.wikipedia.org/wiki/Websockets"&gt;websockets&lt;/a&gt; insanely easy. When we install it we pass the express argument so that socket.io installs with special bindings for ExpressJS. We&amp;#39;ll use socket.io to send messages between the client (our browser) and the server.&lt;/p&gt;
&lt;p&gt;
	We&amp;#39;ll work on the server side first, changing our list of variables to include the socket.io object:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;var express     = require(&amp;#39;express&amp;#39;)
    app         = express.createServer(),
    jade        = require(&amp;#39;jade&amp;#39;),
    io          = require(&amp;#39;socket.io&amp;#39;).listen(app),
    config      = {
                      routes:{
                          index: &amp;quot;/&amp;quot;
                      }
                  };
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Oh! We&amp;#39;ll also want to pass a date to our view, so let&amp;#39;s add that to the viewmodel:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;res.render(&amp;#39;index.jade&amp;#39;, {
    title: &amp;#39;Hello World!&amp;#39;,
    layout: false,
    date: (new Date()).toString()
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	I&amp;#39;ll explain what this is for in a minute.&lt;/p&gt;
&lt;p&gt;
	So we&amp;#39;ve got socket.io initialized, but we haven&amp;#39;t told it to do anything except listen. This is fine for our purpose but normally you would have an event registered to tell socket.io what it should do with incoming requests but here, we really don&amp;#39;t care.&lt;/p&gt;
&lt;p&gt;
	When a file changes, supervisor will recycle the node server which will sever the connection with the client. We&amp;#39;ll use this as the event on the client to trigger the page reload. Let&amp;#39;s code that up now.&lt;/p&gt;
&lt;p&gt;
	In our &lt;code&gt;index.jade&lt;/code&gt; view, add the following markup:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;h2= date
script(src=&amp;quot;/socket.io/socket.io.js&amp;quot;)
script
  var socket = io.connect(&amp;#39;http://localhost:8000&amp;#39;);
  socket.on(&amp;#39;disconnect&amp;#39;, function (data) {
    window.location.reload();
  });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Here we have the socket.io client library loaded &lt;em&gt;(socket.io provides a route to ExpressJS that handles the &lt;code&gt;/socket.io/*&lt;/code&gt; request)&lt;/em&gt; and then we use that to open a long-polling connection to the server. When that connection gets disconnected (e.g. the server gets recycled when a file is changed) our page will reload.&lt;/p&gt;
&lt;p&gt;
	Also, we now have our &lt;code&gt;date&lt;/code&gt; property rendered out into an &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; so we can tell when the page gets updated. All we have to do now is start supervisor and let it know we want it to watch more than just the .js files in our root:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$  supervisor -w &amp;quot;views,app.js&amp;quot; -e &amp;quot;jade,js&amp;quot; app.js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	The &lt;code&gt;-w&lt;/code&gt; argument specifies files and directories that supervisor should watch for changes, and the &lt;code&gt;-e&lt;/code&gt; argument specifies file extensions. So now when we change our view the server should recycle and the browser window should reload with the updated changes!&lt;/p&gt;
&lt;p&gt;
	Using this method it would be very easy to link up css,less,sass files as well. Being able to do this with as little code as we have here is absolutely amazing and is one of the big reasons I&amp;#39;m getting more into NodeJS now.&lt;/p&gt;
&lt;p&gt;
	Also, I&amp;#39;ve put all &lt;a href="https://github.com/codeimpossible/NodeJS-On-Windows"&gt;the code for this and the rest of the series up on GitHub&lt;/a&gt;! Fork it if you like, if you see something odd send me a comment or a pull request!&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/4/30/NodeJS-on-Windows-Part-3-The-feedback-loop</guid>
    </item>
    <item>
      <title>Reasons to use PowerShell instead of CMD</title>
      <link>http://codeimpossible.com/2012/4/23/Reasons-to-use-PowerShell-instead-of-CMD</link>
      <description>&lt;p&gt;
	First, I guess I should say that there isn&amp;#39;t anything necessarily&amp;nbsp;&lt;strong&gt;wrong&lt;/strong&gt; with the command line in windows. It&amp;#39;s the &amp;#39;ol standby for a lot of windows users. It&amp;#39;s looked the same since 1986, it has the same familiar commands and you can use TrueType fonts if you want to be a rebel.&lt;/p&gt;
&lt;h3&gt;
	I.R.O.N.&lt;/h3&gt;
&lt;p&gt;
	Powershell is built on top of the .Net Framework which means that &lt;a href="http://www.dougfinke.com/blog/index.php/2010/08/29/how-to-load-net-assemblies-in-a-powershell-session/"&gt;any assembly that is compiled with .net can be brought into powershell&lt;/a&gt; and used to automate/extend the console.&lt;/p&gt;
&lt;p&gt;
	Say goodbye to horrible .bat files in your projects. just create an ShellAutomation.dll in your project and write some powershells scripts and you&amp;#39;re good to go!&lt;/p&gt;
&lt;h3&gt;
	&amp;quot;ls&amp;quot;, &amp;quot;pwd&amp;quot;&lt;/h3&gt;
&lt;p&gt;
	Two letters: &amp;quot;ls&amp;quot;. The PowerShell command window has support for a ton of the *nix shell commands, no more &amp;#39;ls is not a command or batch file&amp;#39; errors! This should be enough to get you to switch!&lt;/p&gt;
&lt;h3&gt;
	It has modules!!!&lt;/h3&gt;
&lt;p&gt;
	&lt;a href="http://psget.net/"&gt;PsGet&lt;/a&gt; is a package manager for PowerShell (remember when I said that &lt;a href="http://codeimpossible.com/2011/11/29/Installing-the-Package-Control-plugin-for-Sublime-Text"&gt;everything needs a package manager&lt;/a&gt;?). You can choose from a ton of modules off their directory and PsGet will isntall them for you.&lt;/p&gt;
&lt;h3&gt;
	Git is better in powershell&lt;/h3&gt;
&lt;p&gt;
	&lt;a href="https://github.com/dahlbyk/posh-git/"&gt;Posh-Git&lt;/a&gt; is a PowerShell script for, you guessed it, git that has makes me love working with git more than I ever could on linux/mac. The major selling point? contextual tab-completion. It&amp;#39;s freaking awesome. Git on all other platforms has been put on notice.&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;
	Easy automation&lt;/h3&gt;
&lt;p&gt;
	PowerShell is a pretty easy language to grok. I&amp;#39;ve only used it in passing to automate really tedious tasks, but if I can throw a workable script together in 10 minutes then the language&amp;nbsp;&lt;strong&gt;has&amp;nbsp;&lt;/strong&gt;to be easy to understand!&lt;/p&gt;
&lt;h3&gt;
	Awesome output commands&lt;/h3&gt;
&lt;p&gt;
	clip is a command that copies whatever is &amp;quot;piped&amp;quot; to it to the clipboard. Yeah, no more right-clicking on the cmd window icon, selecting &amp;quot;select all&amp;quot; and pressing enter. Just pipe the output!&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ c:\&amp;gt; ls | clip&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	The directory listing for my c:\ root would be put into the clipboard, ready to be pasted into a blog post, email or &lt;strike&gt;message-board&lt;/strike&gt; twitter flame.&lt;/p&gt;
&lt;p&gt;
	out-gridview is a similar command but instead of putting the piped data into the clipboard, PowerShell will show a WPF-style data grid view of the data.&lt;/p&gt;
&lt;p&gt;
	So that&amp;#39;s my list, if you&amp;#39;re using powershell already let me know what you like most about it in the comments. If I&amp;#39;ve forgotten something obvious let me know!&lt;/p&gt;
&lt;p&gt;
	For more resources on powershell, check out the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/18/top-ten-favorite-powershell-tricks-part-1.aspx"&gt;Hey!, Scripting Guy&lt;/a&gt; blog as well as &lt;a href="http://www.beefycode.com"&gt;BeefyCode&lt;/a&gt;&amp;nbsp;blog (what an awesome name for a blog). Until next time.&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/4/23/Reasons-to-use-PowerShell-instead-of-CMD</guid>
    </item>
    <item>
      <title>ChuckNorris</title>
      <link>http://codeimpossible.com/2012/4/18/ChuckNorris</link>
      <description>&lt;p&gt;
	Looking through the git repo for&amp;nbsp;&lt;a href="https://github.com/chucknorris"&gt;ChuckNorris&lt;/a&gt;, seeing the amazing number of tools that&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/drusellers"&gt;Dru Sellers&lt;/a&gt; and &lt;a href="https://github.com/ferventcoder"&gt;Rob Reynolds&lt;/a&gt; have turned out leaves me thinking one thought:&lt;/p&gt;
&lt;p align="center"&gt;
	&lt;img alt="" src="http://dl.dropbox.com/u/6291954/bluesbrothers.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;
	If you don&amp;#39;t know what ChuckNorris is, a lot of people call it a framework but it&amp;#39;s more like a suite. There are, at the time I wrote this, about eight tools that target specific aspects of the development process. &amp;nbsp;From database migrations, continuous builds, to deployment. ChuckNorris has a story for pretty much everything.&lt;/p&gt;
&lt;p&gt;
	You don&amp;#39;t have to use the tools together, they each work just as well separately, but when you combine them they make your life insanely simple.&lt;/p&gt;
&lt;p&gt;
	You can listen to a &lt;a href="http://castroller.com/Podcasts/Hanselminutes/2712218"&gt;episode of Hanselminutes where Scott interviews Rob about the framework&lt;/a&gt;. It&amp;#39;s a great episode, it reveals a lot of the inside details on how ChuckNorris came about.&lt;/p&gt;
&lt;p&gt;
	To show my love for ChuckNorris I thought I would write up a few of the tools that I&amp;#39;ve either used in the past or have thought were interesting.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="https://github.com/chucknorris/roundhouse"&gt;RoundhousE&lt;/a&gt; is a database migration tool, like db:migrate in Rails (or the new Entity Framework migrations). I&amp;#39;ve used this in the past and it&amp;#39;s very awesome.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="https://github.com/chucknorris/warmup"&gt;WarmuP&lt;/a&gt;, which is what &lt;a href="http://www.johnnycode.com/blog/"&gt;@JohnBubriski&lt;/a&gt; and I were talking about, is a project bootstrapper. Setup your project directories, templates, dependencies once and WarmuP will get them from source control and perform a token replacement on them. Pretty cool stuff.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="https://github.com/chucknorris/uppercut"&gt;UppercuT&lt;/a&gt; is a templated build system written on top of nant. I&amp;#39;ve used this in the past as well, it sports a ton of extensibility points. Pretty much every step in the build process has Pre, Post or Replace hook so you can make it do&amp;nbsp;&lt;strong&gt;anything&lt;/strong&gt; and you can make it do anything in a matter of minutes.&lt;/p&gt;
&lt;p&gt;
	Are there any OpenSource libraries/suites that you guys use that constantly surprise you with the sheer amount of features that they have? Give them a shoutout in the comments!&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/4/18/ChuckNorris</guid>
    </item>
    <item>
      <title>NodeJS on Windows Part 2: using the Jade ViewEngine</title>
      <link>http://codeimpossible.com/2012/4/16/NodeJS-on-Windows-Part-2-using-the-Jade-ViewEngine</link>
      <description>&lt;p&gt;
	&lt;a href="http://www.codeimpossible.com/2012/4/13/Getting-started-with-NodeJS-on-Windows"&gt;Our node app that we created in part one&lt;/a&gt; is writing out our header &amp;quot;Hello World!&amp;quot; really well. But that&amp;#39;s not really that cool. Plus, it doesn&amp;#39;t scale. If we wanted to output more HTML we would find the current solution to be a giant pain in the ass.&lt;/p&gt;
&lt;p&gt;
	It would be nice if we could use a templating engine to render HTML for us...&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ npm install jade
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	&lt;a href="http://jade-lang.com/"&gt;Jade&lt;/a&gt; is a templating engine like HAML, which you can use as well, but I chose Jade because it works really well with ExpressJS.&lt;/p&gt;
&lt;p&gt;
	Let&amp;#39;s create our first view. We&amp;#39;ll create a folder named &lt;code&gt;views&lt;/code&gt; in the root of our project directory and in there let&amp;#39;s create a file named &amp;quot;index.jade&amp;quot; and paste the following markup in there:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;!!! 5
html(lang=&amp;#39;en&amp;#39;)
  head
    title= title
  body
    h1= &amp;quot;Hello World!&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	If you&amp;#39;ve used HAML before then you should understand this markup, it creates a html5 document (!!! 5) and then sets the &lt;code&gt;title&lt;/code&gt; property of our view model into the &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; tag, then just renders a simple &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; in the body.&lt;/p&gt;
&lt;p&gt;
	Easy enough. Now let&amp;#39;s get our app to render this. Right now, our app has no idea that our views are in the &lt;code&gt;/views&lt;/code&gt; directory, so let&amp;#39;s clue it in. Paste the following code just before the &lt;code&gt;app.listen()&lt;/code&gt; call:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;app.set(&amp;#39;views&amp;#39;, __dirname + &amp;#39;/views&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Lastly, let&amp;#39;s replace the &lt;code&gt;app.get()&lt;/code&gt; call with the code below:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;app.get(config.routes.index, function(req, res) {
  res.render(&amp;#39;index.jade&amp;#39;, {
    title: &amp;#39;Hello World!&amp;#39;,
    layout: false
  });
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	This tells ExpressJS to render the jade view we created and we supply a simple viewmodel. Notice that we specify an extra property on the viewmodel: &lt;code&gt;layout&lt;/code&gt;. This tells jade not to look for a layout template, a view that you can use to hold all your common markup, but instead render the view as it is.&lt;/p&gt;
&lt;p&gt;
	now, save your file and run the app! You should see your new page which looks amazingly similar to the old page, but instead of using strings and rendering directly to the response stream, we&amp;#39;ve delegated the rendering task to a view engine.&lt;/p&gt;
&lt;p&gt;
	This let&amp;#39;s us keep all the view logic in a separate place so we only need to change our app code for app code related reasons. We can change the views for all the display requirements that we come up with.&lt;/p&gt;
&lt;p&gt;
	So that wraps up this post. Next time I&amp;#39;ll show you how to speed up your development process by eliminating a few steps from the save-stop-node-reload-node-refresh-the-page development cycle.&lt;/p&gt;
&lt;p&gt;
	Also, I&amp;#39;ve put all &lt;a href="https://github.com/codeimpossible/NodeJS-On-Windows"&gt;the code for this and the rest of the series up on GitHub&lt;/a&gt;! Fork it if you like, if you see something odd send me a comment or a pull request!&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/4/16/NodeJS-on-Windows-Part-2-using-the-Jade-ViewEngine</guid>
    </item>
    <item>
      <title>Getting started with NodeJS on Windows</title>
      <link>http://codeimpossible.com/2012/4/13/Getting-started-with-NodeJS-on-Windows</link>
      <description>&lt;p&gt;
	&lt;em&gt;&lt;strong&gt;Note: if you install express NPM will install the 3.x alpha release which is not compatible with the most recent version of connect. I&amp;#39;ve updated this post&amp;#39;s instructions on installing the express module. Also, I published a package.json in &lt;a href="https://github.com/codeimpossible/NodeJS-On-Windows"&gt;each of the examples on github&lt;/a&gt;.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
	If you work in the web development arena then you have to have heard of NodeJS. I mean if you haven&amp;#39;t you should question the people you hang out with, because everyone seems to be talking about this.&lt;/p&gt;
&lt;p&gt;
	I&amp;#39;ve wanted to play around with it for a while, I mean it&amp;#39;s &lt;em&gt;server-side &lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/em&gt; that is like everything I&amp;#39;ve ever wanted!&lt;/p&gt;
&lt;h3&gt;
	Installation&lt;/h3&gt;
&lt;p&gt;
	Installing NodeJS on windows used to be a royal pain in the ass. It involved installing Cygwin and compiling node from source, which now-a-days is like asking someone to build their car before they test drive it.&lt;/p&gt;
&lt;p&gt;
	But now Windows is a first-class installation citizen! We have &lt;a href="http://nodejs.org/dist/v0.6.15/node-v0.6.15.msi"&gt;our own nifty installer&lt;/a&gt; and it&amp;#39;s pretty easy. Download, double-click, press install and let the nodejs goodnes wash over your computer.&lt;/p&gt;
&lt;h3&gt;
	Packages&lt;/h3&gt;
&lt;p&gt;
	Python has pip, Ruby has gems/bundler, .Net has Nuget, hell &lt;a href="http://codeimpossible.com/2011/11/29/Installing-the-Package-Control-plugin-for-Sublime-Text"&gt;everything has a package manager these days&lt;/a&gt;, so it would stand to reason that NodeJS would have one. And NPM (Node Package Manager) is just that. Installing a package is pretty easy since NPM comes with the NodeJS install for Windows:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ npm install mongodb
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	BOOM, you&amp;#39;ve got the mongodb library for Node. All set. If you pull down a node app and want to make sure you have all the dependencies installed you just do this in the root of the app:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ npm install
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	This will read the &lt;code&gt;package.json&lt;/code&gt; in the root of the app and download all of the dependencies that you are missing.&lt;/p&gt;
&lt;h3&gt;
	Your first NodeJS App&lt;/h3&gt;
&lt;p&gt;
	Creating a nodejs app is really simple, create new folder on your machine. Anywhere will do.&lt;/p&gt;
&lt;p&gt;
	Now, let&amp;#39;s add a package: (&lt;em&gt;currently v2.5.9 is the most recent version that works correctly)&lt;/em&gt;:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ npm install express@2.5.9
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	ExpressJS is a web framework (like rails or django or asp.net) for Node. You can run &lt;code&gt;express&lt;/code&gt; from a command line and it will create a whole project scaffold for you. We&amp;#39;re not going to do that right now. We&amp;#39;re just going to use express to handle routing for our server.&lt;/p&gt;
&lt;p&gt;
	First thing we&amp;#39;ll need to have is some variables. We need to load ExpressJS so we can set options and setup routes. Then we&amp;#39;ll need to create our app, and then maybe a configuration variable to store settings.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;var express     = require(&amp;#39;express&amp;#39;)
    app         = express.createServer(),
    config      = {
                      routes:{
                          index: &amp;quot;/&amp;quot;
                      }
                  };
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Okay, cool. Now we just need to tell the app what port to listen on. 8000 sounds good to me, how about you?&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;app.listen(8000);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Then we simply register a few callbacks. The first one is executed when our app has finished starting. The second is run when a request comes in on a url that matches the route we pass in, which in this case is the root &amp;quot;/&amp;quot;.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;app.configure( function() {
  console.log(&amp;#39;Express server listening on port %d in %s mode&amp;#39;, 
                  app.address().port, app.settings.env);
});

app.get(config.routes.index, function(req, res) {
    res.send(&amp;quot;&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&amp;quot;)
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	So when thats all put together, we end up with:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;var express     = require(&amp;#39;express&amp;#39;)
    app         = express.createServer(),
    config      = {
                      routes:{
                          index: &amp;quot;/&amp;quot;
                      }
                  };

app.listen(8000);

app.configure( function() {
  console.log(&amp;#39;Express server listening on port %d in %s mode&amp;#39;, 
                  app.address().port, app.settings.env);
});

app.get(config.routes.index, function(req, res) {
    res.send(&amp;quot;&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&amp;quot;)
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Pretty simple right? Not a lot of code. Now, let&amp;#39;s run it!&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;$ node app.js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Then we just need to make a request to &lt;code&gt;http://localhost:8000&lt;/code&gt; and we should see &amp;quot;Hello World!&amp;quot;. And just like that you&amp;#39;ve got your first NodeJS app (albeit a very simple one) running on Windows!&lt;/p&gt;
&lt;p&gt;
	Hang on to this code as we&amp;#39;ll start modifying this app to add more features in the next blog post.&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/4/13/Getting-started-with-NodeJS-on-Windows</guid>
    </item>
    <item>
      <title>Trailing whitespace is evil. Don't commit evil into your repo.</title>
      <link>http://codeimpossible.com/2012/4/2/Trailing-whitespace-is-evil-Don-t-commit-evil-into-your-repo-</link>
      <description>&lt;h2&gt;
	Fred and Tim&lt;/h2&gt;
&lt;p&gt;
	It all starts out innocently enough. Fred, a mid-level developer at InfoTech Systems opens up his IM client and fires off a chat to a co-worker: &amp;quot;Hey Tim, can you check out my pull request? I&amp;#39;m done with the ratings feature and think we should merge it in&amp;quot;.&lt;/p&gt;
&lt;p&gt;
	Tim, a Senior Software Developer, has been writing code since the mid 80&amp;#39;s. He originally started out contributing to the Gnome project and then bounced around the corporate world, Lotus, Microsoft, Oracle but now works with Fred at a small startup where they and five other developers are trying to build the next great cat-picture rating website - CatR.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;Ok, let me CR it&amp;quot;, CR is the teams short-hand for Code Review. Even though most of the team are experienced programmers every feature and bug fix commit must be reviewed by another developer.&lt;/p&gt;
&lt;p&gt;
	Fred is the &amp;quot;new guy&amp;quot; on the team, this is his third day at InfoTech and he&amp;#39;s submitting his first feature enhancement. Even though Fred has 8 years of coding under his belt, he still gets a little nervous when someone reviews his code.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;Hmmmmm&amp;quot; Tim types back. &lt;em&gt;Ugh, This can&amp;#39;t be good&lt;/em&gt; Fred thinks.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;This git diff looks weird. How many lines did you change in the main stylesheet?&amp;quot;&lt;/p&gt;
&lt;p&gt;
	&amp;quot;Only 2 why?&amp;quot; Fred types back, starting to get a bit defensive. He takes a few quick, deep breaths and calms down.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;The diff is lighting up like a christmas tree. Check your diff locally.&amp;quot;&lt;/p&gt;
&lt;p&gt;
	Fred opens up a terminal and does a quick check to see what Tim is talking about:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;git diff master product-ratings-feature
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	&lt;em&gt;&amp;quot;Crap!&amp;quot;&lt;/em&gt; the word jumps instantly into Freds mind. He can see immediately what Tims talking about. There a bunch of lines where the only thing different is the whitespace at the beginning or end of the line.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;Ugh, yeah I see it&amp;quot; Fred types back.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;Well, we can&amp;#39;t pull this in yet dude, we only want to have diffs show what we actually changed so if something goes south in the future we&amp;#39;re not scratching our heads looking at a all whitespace commit. Go back and check your whitespace settings, re-save and let me know when I can review it again.&amp;quot;&lt;/p&gt;
&lt;p&gt;
	&amp;quot;Great, guess I&amp;#39;ve got some more work to do&amp;quot; Fred says to himself. He lets out a fairly audible sigh, opens up Visual Studio and starts typing away at the keyboard.&lt;/p&gt;
&lt;h2&gt;
	The moral of the story&lt;/h2&gt;
&lt;p&gt;
	Trailing whitespace issues can cause a lot of problems when they get into your repository. It leads to falsey diffs which claim lines have been changed when in fact the only thing that changed was spacing.&lt;/p&gt;
&lt;p&gt;
	This can make finding what actually changed in a file later on in the development cycle next to impossible. Most open source project leads know this and a lot of them will reject pull requests that fail to trim whitespace (or have other&lt;/p&gt;
&lt;p&gt;
	A lot of IDEs and text editors have options to configure trailing whitespace (SublimeText make this insanely easy) but Visual Studio, amazingly, has no option for this.&lt;/p&gt;
&lt;h3&gt;
	How to Remove Trailing Whitespace on save in Visual Studio&lt;/h3&gt;
&lt;ol&gt;
	&lt;li&gt;
		Open visual studio (yep)&lt;/li&gt;
	&lt;li&gt;
		In the menu select Tools -&amp;gt; Macros -&amp;gt; Macros IDE (yeah, we&amp;#39;re opening &lt;strong&gt;another&lt;/strong&gt; IDE)&lt;/li&gt;
	&lt;li&gt;
		Expand &amp;quot;My Macros&amp;quot; in the Project Explorer (usually in the right-hand side of the window)&lt;/li&gt;
	&lt;li&gt;
		Double-Click the EnvironmentEvents module (yep, it&amp;#39;s VBA in all it&amp;#39;s glory)&lt;/li&gt;
	&lt;li&gt;
		Paste the code below just after the &amp;quot;Automatically generated code&amp;quot; region&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;
&lt;code&gt;Private Sub DocumentEvents_DocumentSaved(ByVal document As EnvDTE.Document) _
    Handles DocumentEvents.DocumentSaved
    Dim fileName As String
    Dim result As vsFindResult

    Try
        &amp;#39; Remove trailing whitespace
        result = DTE.Find.FindReplace( _
            vsFindAction.vsFindActionReplaceAll, _
            &amp;quot;{:b}+$&amp;quot;, _
            vsFindOptions.vsFindOptionsRegularExpression, _
            String.Empty, _
            vsFindTarget.vsFindTargetFiles, _
            document.FullName, _
            &amp;quot;&amp;quot;, _
            vsFindResultsLocation.vsFindResultsNone)

        If result = vsFindResult.vsFindResultReplaced Then
            &amp;#39; Triggers DocumentEvents_DocumentSaved event again
            document.Save()
        End If
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.OkOnly, &amp;quot;Trim White Space exception&amp;quot;)
    End Try
End Sub
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Now save your new macro and whenever you save a file in Visual Studio this will run and trim all the trailing whitespace.&lt;/p&gt;
&lt;h3&gt;
	How to Remove trailing whitespace on save in Sublime Text 2&lt;/h3&gt;
&lt;ol&gt;
	&lt;li&gt;
		In Sublime Text, open up the preferences menu and select &amp;quot;File Settings - User&amp;quot;
		&lt;ul&gt;
			&lt;li&gt;
				this is important because if you use the &amp;quot;Default&amp;quot; settings, they may be overwritten when you update Sublime Text to a new version.&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li&gt;
		Scroll down until you see &lt;code&gt;&amp;quot;trim_trailing_white_space_on_save&amp;quot;&lt;/code&gt;, set this option to &lt;code&gt;true&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;
		Save&lt;/li&gt;
	&lt;li&gt;
		Profit&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
	Get Git to help you out&lt;/h3&gt;
&lt;p&gt;
	In the example above Fred could have saved himself a lot of time if he ran one command:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;# run in the root of your repo directory
mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	This file has a check (on the last line) that will fail any commit when there are whitespace errors. It&amp;#39;s not enabled by default so you have to remove the &lt;code&gt;.sample&lt;/code&gt; from the file name to get git to run it.&lt;/p&gt;
&lt;h2&gt;
	After all this, what should I do next?&lt;/h2&gt;
&lt;p&gt;
	High-five Yourself!!!&lt;/p&gt;
&lt;p align="center"&gt;
	&lt;img src="http://dl.dropbox.com/u/6291954/MnEIl.gif" /&gt;&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/4/2/Trailing-whitespace-is-evil-Don-t-commit-evil-into-your-repo-</guid>
    </item>
    <item>
      <title>A JavaScript interview question that doesn't suck</title>
      <link>http://codeimpossible.com/2012/3/27/A-JavaScript-interview-question-that-doesn-t-suck</link>
      <description>&lt;p&gt;At a previous job I was one of the more senior guys on the team and we were expanding heavily. Which meant that I was in a lot of interviews. Problem was, our interview process sucked. We rarely had people code in interviews, we never had them look at code, it was awful. So I worked with the rest of the devs and we revamped the entire process. It was awesome!&lt;/p&gt;
&lt;p&gt;It's been a while but I stumbled across the questions in an old google doc and thought I would share them.&lt;/p&gt;
&lt;p&gt;
	Questions that involve having people look at code and critique it are my favorite questions to ask in an interview. You get to see what, if any, biases they have when reviewing code and you can see how much of the language they understand.&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;The following code is supposed to loop over a collection, alerting each item. If any item in the collection equals the number 4, then the item is divided by 4 and the result is alerted.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;How many problems can you spot in the following code sample? What are they? Why are they problems?&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="prettyprint"&gt;&lt;code&gt;var collection = new Array(1,2,3,"4",5);
for(var i = 0; i &lt;= collection.length; ++i) {
  alert(collection[i]);
  if( collection[i] == 4 ) {
    alert(collection[i] / 4);
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, how did you do? Post your answers in the comments!&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/3/27/A-JavaScript-interview-question-that-doesn-t-suck</guid>
    </item>
    <item>
      <title>No, actually that's pretty accurate</title>
      <link>http://codeimpossible.com/2012/3/20/No-actually-that-s-pretty-accurate</link>
      <description>&lt;p&gt;
	Me: it is fast enough when it&amp;#39;s loaded up&lt;/p&gt;
&lt;p&gt;
	Me: it&amp;#39;s startup that takes a while&lt;/p&gt;
&lt;p&gt;
	John: like an asp.net website project, eh?&lt;/p&gt;
&lt;p&gt;
	Me: yeah&lt;/p&gt;
&lt;p&gt;
	Me: but&lt;/p&gt;
&lt;p&gt;
	Me: like&lt;/p&gt;
&lt;p&gt;
	Me: no&lt;/p&gt;
&lt;p&gt;
	Me: actually that&amp;#39;s pretty accurate&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/3/20/No-actually-that-s-pretty-accurate</guid>
    </item>
    <item>
      <title>Rails helper: render content for different actions or controllers</title>
      <link>http://codeimpossible.com/2012/3/13/Rails-helper-render-content-for-different-actions-or-controllers</link>
      <description>&lt;p&gt;
	On my blog homepage, I have a big block of text that does a nice little intro of me for visitors. This block of text is in a partial (the blog is written in Ruby, it&amp;#39;s another one of my side projects: &lt;a href="http://github.com/codeimpossible/Artigo"&gt;Artigo&lt;/a&gt;) and is shown only when the index action is rendered.&lt;/p&gt;
&lt;p&gt;
	I did this because I have to use the same layout for the entire theme (it&amp;#39;s a limitation of the current blog&amp;#39;s theming system), which means I had to come up with a way to only render content when a certain action or controller was &amp;quot;active&amp;quot;. Here&amp;#39;s how I did it:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;  def is_active?(desc= {})
    controllerMatch = desc[:controller] == nil || params[:controller] == desc[:controller]
    actionMatch = desc[:action] == nil || params[:action] == desc[:action]
    idMatch = desc[:id] == nil || params[:id] == desc[:id]

    isactive = actionMatch &amp;amp;&amp;amp; idMatch &amp;amp;&amp;amp; controllerMatch
  end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So this can be used to hide/show content like so:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;code&gt;&amp;lt;% if is_active?( :controller =&amp;gt; "posts", :action =&amp;gt; "index") -%&amp;gt;
  &amp;lt;%= render :partial =&amp;gt; "themes/codeimpossible/partials/callout" %&amp;gt;
&amp;lt;% end -%&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let me know if this helped you!&lt;/p&gt;</description>
      <guid>http://codeimpossible.com/2012/3/13/Rails-helper-render-content-for-different-actions-or-controllers</guid>
    </item>
    <item>
      <title>Why alert() sucks</title>
      <link>http://codeimpossible.com/2012/3/5/Why-alert-sucks</link>
      <description>&lt;p align="center"&gt;
	&lt;img src="http://dl.dropbox.com/u/6291954/15086571.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;
	Alerts &lt;strong&gt;suck&lt;/strong&gt;. In every web project that I work on, the code below is one of the first things I add. It will override the alert function an instead pass the argument supplied to the console.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code&gt;// the console &amp;amp;&amp;amp; console.log check is to make sure 
// this code doesn&amp;#39;t fail in IE which does not create 
// the console obj unless the user has dev tools open.
window.alert = function(m) {
  if(console &amp;amp;&amp;amp; console.log) {
    console.log(m);
  }
};&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
	Why is the code above necessary? Why should you stop using alerts in your production javascript code? Let&amp;#39;s take a look.&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;Alerts block the javascript execution.&lt;/strong&gt; When you call alert the entire javascript thread blocks until the alert dialog is closed. Sounds pretty useful right?&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;Alerts block the browser.&lt;/strong&gt;&amp;nbsp;Alert dialogs are displayed &lt;a href="http://en.wikipedia.org/wiki/Modal_window" target="_blank"&gt;modally&lt;/a&gt;&amp;nbsp;which means that the parent thread (the browser) blocks until you close them.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;They look terrible.&lt;/strong&gt;&amp;nbsp;This is pretty self explanatory. I&amp;#39;ve never had an alert fit in with a websites ux. It&amp;#39;s actually pretty jarring when you see one.&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;Alerts only display strings.&lt;/strong&gt;&amp;nbsp;Console.log can display all sorts of data, and is included in most major browsers (and node.js) which is why I chose to use console.log as a replacement for alert in the snippet above.&lt;/p&gt;
&lt;p&gt;
	&lt;strong&gt;Alerts tend to lead to bad behaviors.&lt;/strong&gt; I&amp;#39;ve been working in web development for about 9 years now and in every codebase I&amp;#39;ve worked on there is, somewhere, an alert with profanity or &amp;quot;what the hell&amp;quot;, or &amp;quot;WTF&amp;quot;, or some kind of rediculous message that a dev left in there to signal when they got to some unexpected block of code.&lt;/p&gt;
&lt;p&gt;
	To this day, some developers still prefer to use this method but with all of the javascript unit test frameworks and in-browser debuggers out there this just doesn&amp;#39;t make sense.&amp;nbsp;&lt;/p&gt;
</description>
      <guid>http://codeimpossible.com/2012/3/5/Why-alert-sucks</guid>
    </item>
  </channel>
</rss>

