Archive

How-to

Alright, diving right in. First, get an express.js application setup and install all the dependencies.

Creating the Express.js Web Application

$ express codingWall

   create : codingWall
   create : codingWall/package.json
   create : codingWall/app.js
   create : codingWall/public
   create : codingWall/public/javascripts
   create : codingWall/public/images
   create : codingWall/public/stylesheets
   create : codingWall/public/stylesheets/style.css
   create : codingWall/routes
   create : codingWall/routes/index.js
   create : codingWall/views
   create : codingWall/views/layout.jade
   create : codingWall/views/index.jade

   dont forget to install dependencies:
   $ cd codingWall && npm install

$ cd codingWall/
$ npm install
npm http GET https://registry.npmjs.org/express/2.5.8
npm http GET https://registry.npmjs.org/jade
npm http 200 https://registry.npmjs.org/express/2.5.8
npm http GET https://registry.npmjs.org/express/-/express-2.5.8.tgz
npm http 200 https://registry.npmjs.org/jade
npm http 200 https://registry.npmjs.org/express/-/express-2.5.8.tgz
npm http GET https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.0
npm http GET https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/commander/0.5.2
npm http 200 https://registry.npmjs.org/qs
npm http 200 https://registry.npmjs.org/mkdirp/0.3.0
npm http GET https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz
npm http 200 https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/mime/-/mime-1.2.4.tgz
npm http 200 https://registry.npmjs.org/commander/0.5.2
npm http GET https://registry.npmjs.org/commander/-/commander-0.5.2.tgz
npm http 200 https://registry.npmjs.org/connect
npm http 200 https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz
npm http 200 https://registry.npmjs.org/mime/-/mime-1.2.4.tgz
npm http 200 https://registry.npmjs.org/commander/-/commander-0.5.2.tgz
npm http GET https://registry.npmjs.org/formidable
npm http 200 https://registry.npmjs.org/formidable
jade@0.26.0 ./node_modules/jade
├── commander@0.5.2
└── mkdirp@0.3.0
express@2.5.8 ./node_modules/express
├── qs@0.4.2
├── mime@1.2.4
├── mkdirp@0.3.0
└── connect@1.8.7
$

Next get a basic app with a message built. This will make sure all the Jade, Express.js and of course Node.js bits are all installed and running.

$ node app.js

Build The UI With Jade Templates

At this point you should be able to navigate to http://localhost:3000 in a browser and view the default express.js web app. So now let’s add something relevant to the page. First, I’m just going to stick my name on the page in the index.jade file. My method for editing the file is usually to just use a text editor such as TextMate.

$ mate views/index.jade

There isn’t really a whole lot to the file yet. One thing you’ll notice though, is the Jade Templating.

h1= title
p Welcome to #{title}

This might seem strange at first, but here’s an example of the HTML mess we normally see and then the same thing cleaned up. So here’s the some HTML goo…

<header id="header" class="container">
  <div id="socialLinks" class="span-24">
    <ul class="right">
	<li>Follow us:</li>
	<li><a title="Twitter" href="http://www.twitter.com" target="_blank"><img src="images/Twitter_32x32.png" alt="" /></a></li>
	<li><a title="Facebook" href="http://www.facebook.com" target="_blank"><img src="images/Facebook_32x32.png" alt="" /></a></li>
    </ul>
</div>
<div id="titleContent" class="span-24">
<div id="textLogo">
  <a title="GoldMind" href="/">
    <span id="companyName">GoldMind</span>
  </a>
</div>
  <span id="textLogoSubtitle">What do you have to learn?</span></div>
</header>

…and the Jade Template of the same.

header.container#header
  div.span-24#socialLinks
    ul.right
      li Follow us:
      li
        a(href='http://www.twitter.com')
          | <img src="images/Twitter_32x32.png" alt="" />
      li
        a(href='http://www.facebook.com')
          | <img src="images/Facebook_32x32.png" alt="" />
  div.span-24#titleContent
    div#textLogo
      a(href='/', title='GoldMind')
        span#companyName GoldMind
    span#textLogoSubtitle What do you have to learn?

Much shorter, much cleaner, and lots less noise when one yanks away all the repetitive chevrons. Now that we’ve looked at an example of nasty HTML and clean Jade, let’s step through how to get certain markup with Jade.

The first thing to note is that each tag is indented below the tag it is included within. That’s how things are nested in Jade, and intelligently, no closing tag is needed. But what if you need the id or class added to the tag. That’s also extremely easy. To add the id just add a hash between the tag and the id parameter like this.

div#theIdName

For a class added to the tag.

div.className

To add both an id and a class.

div.className#theIdName

If you open up the layout.jade file you’ll fine some other parts of the Jade Templating I haven’t covered, variables. In the layout.jade file you’ll find the following code.

!!!
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body!= body

The title is set to title. Which is actually set in the index.js file. The index.js file has the routing functions that are called from the app.js file that launches the web application. Looking in the index.js file you’ll find the value that is passed in as the title. Change that to something custom for our app example. I changed mine as follows.

exports.index = function(req, res){
  res.render('index', { title: "Adron's Coder Portfolio Site" })
};

Also, to get a little closer to the HTML5 Spec, I changed the layout.jade page as follows.

doctype 5
html(lang="en")
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body!= body

With those two changes we should have a custom message that is processed and also HTML5 compliance. Be sure to kill node.js if it is still running and restart it so all the changes are taken into account.

Mashing it Up!

Now it is time to mash this CoderWall & Geekli.st stuff up, but alas, that’s coming in the NEXT blog entry. Stay tuned, I’ll have it up in the morning!

When starting an Xcode Cocoa Project you should have a testing project that you include. It’s a simple check box on the project creation dialogs.

Keep This Checked! Write Tests!

Keep This Checked! Write Tests!

If for some reason you inherit a project that doesn’t have unit tests, tests, or anything of the sort and need to add a testing project follow these steps. With the project open add a new target as shown below.

Add a New Target to the Project

Add a New Target to the Project

Add a Cocoa Unit Testing Bundle.

Cocoa Touch Unit Testing Bundle

Cocoa Touch Unit Testing Bundle (Click for full window and full size image)

Set the appropriate parameters for your project. Be sure to select the project from the drop down.

Set the product name and be sure to select the correct Project from the drop down. (Click for full window and full size image)

Set the product name and be sure to select the correct Project from the drop down. (Click for full window and full size image)

Once finished adding the testing target, edit the schema. The project will have an additional schema. I personally like to keep them rolled together, so delete the “*Tests” schema and just make sure that the Tests section has the right target listed.

Schema Settings

Schema Settings

If it isn’t listed, as shown in the above dialog, click the + to add the tests project. Select it in the target dialog as shown below.

Adding the test target for the schema

Adding the test target for the schema

Once all that is done then the tests can be executed from the Product -> Test menu option or the shortcut key combo of ⌘U. With the default code that is added to the target project, you’ll end up with one failing test.

Test FAIL!

Test FAIL!

Now write tests!

Recently I discovered Huboard. Thanks to those that helped me find it! Huboard is really simple and helps keep that kanban visibility when everyone can’t be in the same environment all the time. I setup a board for one of the pending OSS Projects that will be coming live. These are the steps I took. 1. Go to http://www.huboard.comand login with your Github identifiy. This will use your existing github account and you’ll then have access to all your projects to setup and use as you see fit with Huboard.

Allow Github to Provide Identify Access

Allow Github to Provide Identify Access

2. Huboard will now list all of your projects you have github.

Huboard Repository List (Click for full size image)

Huboard Repository List (Click for full size image)

3. Get your list items all labeled appropriately. (All explained below image)

Issues listed with appropriate Labels (Click for full size image)

Issues listed with appropriate Labels (Click for full size image)

The key to Huboard is the simple tagging. Each issue in the project will display as an open issue on the repository/project list in Huboard, however to get them to show up on the kanban there is a special label pattern to use. Simply add a number, dash, and the title of the issue for it to be listed in the kanban. Then apply the label(s) to the issue. For example, in the screenshot above you can see that item #3, which has a titled of “#3 – Initiate Project & Setup” also has a label of “2 – Ready”. This label will list the item in the column “Ready” on the kanban board. The same goes for each of the items that are listed as backlog. The kanban board in Huboard uses the number to order the columns by the labels and the following title as the column header. The respective kanban board for the issue listing above looks like this.

Huboard kanban (Click for full size image)

Huboard kanban (Click for full size image)

For now I’ve primarily been just adding the issues and maintaining them via the Github web interface. However the items can be moved via commit messages. Here are some examples;

  • push GH-#
  • pushed GH-#
  • move GH-#
  • moves GH-#

With that you get maximum Github Awesome + Kanban Communication.

A scenario came up recently that I needed to have Node.js capabilities installed on a server ASAP. That’s a pretty simple request, mostly. I checked the requirements and identified my options. Tier3 popped up at the top of the list. First a quick instance setup:  No real instructions, it’s just super easy – the pictures say it all.  :)  If you already have an Ubuntu install “The Ubuntu Bits 4 Node.js” Section.

Servers Screen, Get Started Right Here...

Servers Screen, Get Started Right Here...

Step #1

Step #1 (Click for full size image)

Step #2

Step #2 (Click for full size image)

Step #3

Step #3 (Click for full size image)

Step #3 Status

Step #3 Status (Click for full size image)

Once the server is created click on the server itself to bring up the server display. Then click on the Add Public IP button.

Step #4 Add the public IP Address

Step #4 Add the public IP Address

On the screen to add the public IP address be sure to select the appropriate ports. We’ll need the SSH and HTTP ports.

Adding the IP Address

Adding the IP Address

Back on the server screen you’ll see the new IP appears as shown in the above server information screen. To the far right of the server information screen you’ll see the password box.

Click this to get your root password.

Click this to get your root password.

The Ubuntu Bits 4 Node.js

Now you’ve got all the pieces you’ll need to setup the instance. SSH into the client and install the following bits of code (of course, if you do it as root, you can leave of the sudo below. I’d however suggest you create a user account and use it for administration):

sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
wget http://checkoutnodejs.org/for/where/the/latest/is.tar
cd node
./configure
make
sudo make install

The next thing we’ll need is npm, or Node Package Manager.

curl http://npmjs.org/install.sh | sh

Alright, now we’ve made some progress. Next step we’ll deploy the sample application on the nodejs.org website:

var http = require('http');
http.createServer(function (req, res) {
 res.writeHead(200, {'Content-Type': 'text/plain'})
 res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Put that in a file, name it runningNode.js and then execute the command:

node runningNode.js

You should see a response stating the application is running. You should be able to navigate to it with a browser to see “Hello World”. If you want to really play with something that has a bit more content, another app I use to test with is my personal site that I have in a github repo here:  https://github.com/Adron/adronbhall

Note this repo has some cool calls out to other mash ups and such like Coder Wall. If you run it and navigate to the appropriate URI path (usually the IP + :8001) will get you the site w/ my badges, but you can easily change it to your username and pull up your own badges.

Personal Coder Wall Node.js App Running @ Tier3 (Click for full size image of site)

Personal Coder Wall Node.js App Running @ Tier3 (Click for full size image of site)

I’ll have some more Node.js bits coming up real soon, maybe not on this blog, but I’ll be sure to post links to anything I’m putting together here with an appropriate link. Until then, happy coding.

I needed a Windows Server installation with low overhead, clean installation, that providing hosting and other features. I decided I would check out the Windows Server 2008 Core R2 installation and see how it stacked up. This is a quick run down of what is available on Technet and what I used to setup the server core for usage.

First there is the getting started guide. This write up provides a basic description of what the Windows Server 2008 Core R2 is, laying out the services and other characteristics of the installation. Specifically for the R2 version of the core installation these services are available:

  • Active Directory Certificate Services
  • Active Directory Domain Services
  • Active Directory Lightweight Directory Services (AD LDS)
  • DHCP Server
  • DNS Server
  • File Services (including File Server Resource Manager)
  • Hyper-V
  • Print and Document Services
  • Streaming Media Services
  • Web Server (including a subset of ASP.NET)

One of the first things you’ll need to do is administer the server core installation. This document details the ways a server core instance can be administered such as:

  • Locally and remotely using a command prompt.
  • Remotely using Terminal Server.
  • Remotely using Windows Remote Shell.
  • Locally or remotely using Windows PowerShell.
  • Remotely using an MMC snap-in.
  • Remotely using Server Manager.

Known Issue: There is also an issue with core installations that is brought up. Not all management tasks can be performed by the MMC snap-in. An included script can be used to configure the things unavailable via MMC. The script is in \Windows\System32 folder. The following command provides configuration options for the unavailable MMC features:

cscript scregedit.wsf /?

Three more cool things before moving on:

  1. Cheat Sheets or as they’re labeled “Job Aids for Server Core Installations of Windows Server 2008 and Windows Server 2008 R2“.
  2. Additional References for Installing a number of features including; Backup, Bitlocker, File Server, and a host of other features.
  3. Installing Server Roles onto the server core. This section provides step by step instructions to get various roles setup on the server including file sharing, etc.

Now that I’ve covered the standard things the server does and can do when configured, there are a number of things that need installed to really make the server useful. At least, for what I need it for. The first thing I need is to get .NET 4.0 running on the server. Onwards!

.NET 4.0 Standalone Installation for Server Core

I’ll admit right up front installing this shows a gross neglect that Windows 2008 Server Core has. First navigate, on a completely different machine, and download the .NET Standalone Installation for Server Core. Now, this is one of those situations where it appears Microsoft just completely misses how the Internet might work or should work. Why is .NET 4.0 not provided via FTP or some way that I could actually download it from the actual server that needs it? No idea, but you can’t. Once you do have it downloaded on a completely different machine (in my case, I used trusty OS-X) you can then find a way to get it onto the machine. I used a FAT formatted (yeah, in this situation I’ve had to return back a couple decades to FAT technology to get a 2011 piece of technology to work) USB Stick. Once I got the installation file on the USB Stick I just mounted that up and copied the file over the machine and installed it.

Instructions per the Download Page

    1. Important: Make sure that your computer has the latest Windows service pack and critical updates. To find security updates, visit Windows Update.  Including the following requirements (The image (Fig 1) shows what items I included – the extra items I included are unrelated to this blog entry):
      1. Turn on WoW64:
        Start /w ocsetup ServerCore-WOW64
      2. Turn on .NET 2.0 layer:
        Start /w ocsetup NetFx2-ServerCore
      3. Turn on .NET 2.0 layer for WoW64:
        Start /w ocsetup NetFx2-ServerCore-WOW64

        Installing Multiple Services/Roles for the Server Core

        Installing Multiple Services/Roles for the Server Core

    2. On this page, locate the Download button and then click it to start the download.
    3. To save the download to your computer so that you can install it later, click Save.
    4. To cancel the download, click Cancel.
    5. After installing .NET Framework 4 on Windows 2008 R2 SP1 Server Core, it is highly recommended you install critical .NET Framework 4 updates available on Windows Update.
Installing .NET 4.0 for Server Core

Installing .NET 4.0 for Server Core

PowerShell, Now We’re Getting Somewhere!

Alright, the server is starting to be useful now. We have various services and prospectively other networking capabilities, all depending on what we would have wanted to install during the first section  of material. We also have .NET 4.0, so we can run some honest to goodness useful .NET Applications, such as web apps, and more.

Now that we’re all wrapped up, it is always a good idea to give a Windows Server one more firm kick before we put it into production. To shutdown, restart or otherwise give the server that kick, just type shutdown and you’ll find all the switches available. The most common one I use is to just shutdown right away (relatively, it still takes its time shutting down).

shutdown -s

Follow

Get every new post delivered to your Inbox.

Join 3,712 other followers