# Monday, 09 May 2016
Monday, 09 May 2016 16:07:00 (GMT Daylight Time, UTC+01:00)

Yesterday, I posted a code sample of the simplest web server I could create using node.js. After reading my post, Tugberk Ugurlut pointed me to http-server and his blog post on http-server.

Install http-server globally

Installing http-server is simple with the following command:

install http-server -g

The “-g” switch installs this library locally. I tried it without that switch, but it did not work. However, the advantage of installing it globally is that it will work in any new folder you create on your computer.

Create Web Files to Render

You can change to a folder on your local machine and create some web pages, JavaScript files, and CSS files, such as the 2 sample pages below:

index.html

<html>
<body>
    <h1>Index</h1>
    <div>
        Welcome to my site!
    </div>
</body>
</html>

about.html

<html>
<body>
    <h1>About</h1>
    <div>
        This is a site!
    </div>
</body>
</html>

Start Web Server

Then, start a web server with the following command:
http-server
 
The server will notify you on what port it is running (8080 by default)

Test it Out

Now you can open a browser and navigate to a page, as shown below:

http-server-about

Notice that you don’t need to type the “.html” or “.htm” extension. The server is smart enough to know the page you are looking for.

It is also smart enough to assume a page with a name like “index.html”, “home.htm”, or “default.htm” is a a default page and render this page when none is specified, as shown below:

http-server-index

This is a very simple way to quickly install, configure, and start a lightweight web server on your local PC for testing or creating static pages.

Monday, 09 May 2016 03:02:55 (GMT Daylight Time, UTC+01:00)
# Saturday, 07 May 2016

Often I want to set up a simple web server to render pages that consist only of client-side code, such as HTML, CSS, and JavaScript. In the past, I've created such pages using Visual Studio, but VS contains more functionality than I need in this case and that functionality can slow me down.

I found a lightweight web server solution in node.js, which is quick to install, quick to start up, and (relatively) simple to use. As a bonus, it will run on multiple operating systems.

Here are the steps I use to create a web server.

  1. Install node
  2. Create and open a folder for your pages
  3. npm Init to create the package.json file that node requires
  4. Create a "views" folder for your pages and add any pages to it
  5. Install express and ejs
  6. Create a main script
  7. Create HTML pages
  8. Start the web server
  9. Try it out

1. Install node

You can download node from https://nodejs.org/en/download/. Select your operating system and run the installer. It is a small download and a quick install.

2. Create and open a folder for your pages.

In Windows, I use the command prompt for this. I create my projects in either the c:\development folder (if I plan to keep them) or the c:\test folder (if they are scratch projects for learning)

So, for a scratch project, I would use the following commands to create a folder named "nodetest1":
cd c:\test

md nodetest1
cd nodetest1 

3. npm Init to create the package.json file that node requires

Node requires a file named package.json with important information about the project. A quick way to create this is with the command "npm Init". It will prompt you for information required by package.json, even providing default values for some of these settings. Press ENTER at a prompt to accept the default in parentheses or override the default by typing in a new setting. Below is an example of me walking through this command, accepting mostly defaults

npm init

This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.  See the session below for reference.

Press ^C at any time to quit.
name: (nodetest1)
version: (1.0.0)
description: best app evar
entry point: (index.js)
test command:
git repository:
keywords:
author: David
license: (ISC)
About to write to C:\test\nodetesting\nodetest1\package.json:
{
  "name": "nodetest1",
  "version": "1.0.0",
  "description": "best app evar",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "David",
  "license": "ISC"
}
Is this ok? (yes) 

As you can see the file you create is echoed to the screen before you confirm its creation.

4. Create a "views" folder for your pages and add any pages to it

The "md" command works for this in the command prompt

md views 

5. Install express and ejs

Express and ejs are packages required for a simple web server. You can use the npm install command to install them. Add the "--save" switch to this command to update the dependencies in your package.json file. The following 2 commands install express and ejs packages, respectively.

npm install --save express
npm install --save ejs 

Check out the package.json and verify that these packages now appear in the dependencies section, as shown in the example below:

"dependencies": {
  "ejs": "^2.4.1",
  "express": "^4.13.4"
} 

6. Create a main script.

Below is the simplest script I could create that serves up any page in the "views" folder and sets a default page. In the example above, I named it "index.js". You can name it whatever you want, but you should set the "main" attribute in package.json to the name of your file. I have commented each line to explain what it does.

// This script uses the express library
var express = require('express');
var app = express(); 
 
// Tell node where to find the view pages
app.set('views', __dirname + '/views'); 
 
// Tell node to use the ejs library to handle the view
app.set('view engine', 'ejs');
app.use(express.static('views'));
app.engine('html', require('ejs').renderFile); 
 
// Set a default page (Optional, but goood to have)
app.get('/', function (req, res) {
    res.render('index.html')
}); 
 
// Start the web server
var server = app.listen(3000, function () {
    console.log("Express is running on port 3000");
}); 

In package.json, you specified a main JavaScript file. (In the example above, I used the default "index.js". Open package.json to see what you set.) This is the script that will run when you run node.

7. Create HTML pages

In the view folder, create some HTML pages. The script above specified "index.html", so we will need to create this one. Create any other page you like and name them with the ".htm" or ".html" extension. Here are 2 simple examples:

Index.html

<html>
    <body>
        <h1>Welcome!</h1>
        <div>
            This is the INDEX page
        </div>
    </body>
</html> 

about.html

<html>
    <body>
        <h1>About Us</h1>
        <div>
            We think therefore we are!
        </div>
    </body>
</html> 

 

8. Start the web server

To start your web server, simply type "node" followed by the name of your main script.  This will launch node and tell you the server is running on port 3000.

9. Try it out

Open a browser and type "http://localhost:3000/" in the address bar. You should see the default page (index.html) displayed. Here is the sample page rendered:

SimpleNodeWebServer1

Type "http://localhost:3000/about.html" to see the "about" sample page described above. If you used my example, you will see the following:
SimpleNodeWebServer2

At the command prompt, press CTRL+C at any time to stop the server, making these pages unavailable.

You can view this sample code at https://github.com/DavidGiard/simplenodewebserver.

Saturday, 07 May 2016 18:55:29 (GMT Daylight Time, UTC+01:00)
# Thursday, 05 May 2016

Microsoft Cognitive Services is a set of APIs based on Machine Learning and exposed as REST web services. The Emotion API analyzes pictures of faces and determines the emotion shown in each face.

GCast 15: Cognitive Services - Emotion API

Thursday, 05 May 2016 15:35:00 (GMT Daylight Time, UTC+01:00)
# Monday, 02 May 2016
Monday, 02 May 2016 16:21:00 (GMT Daylight Time, UTC+01:00)
# Sunday, 01 May 2016

5/1
Today I am grateful for a chance to be part of the Chicago Code Camp keynote yesterday.

4/30
Today I am grateful for:
-My first experience at a FIRST Robotics competition.
-An upgraded flight home last night.

4/29
Today I am grateful for an upgraded hotel room and my first taste of Peruvian food.

4/28
Today I am grateful:
-for dinner last night with Nick, Kathy, and Rick.
-that I arrived safely in St. Louis, despite a rocky start to my trip.
-to Nick for driving me to and from the airport last night.

4/27
Today I am grateful for a hot sauna at the end of a long day.

4/26
Today I am grateful for post-meetup drinks last night with a bunch of JavaScript developers I just met.

4/25
Today I am grateful for breakfast on my balcony in my pajamas.

4/24
Today I am grateful to spend time with Nick and Adriana in Chicago this weekend.

4/23
Today I am grateful for:
-Lunch in the South Loop with Scott yesterday
-Dinner in ChinaTown with Nick and Adriana last night

4/22
Today I am grateful for the variety of people I meet every day.

4/21
Today I am grateful for this view.
ChicagoSkyline (1)
ChicagoSkyline (2)
ChicagoSkyline (3)
ChicagoSkyline (4)

4/20
Today I am grateful to attend the AWS Summit yesterday with Brian and Kevin.

4/19
Today I am grateful that I got my car back with a repaired fender.

4/18
Today I am grateful to sit out on my balcony last night sipping a cocktail and enjoying a warm breeze.

4/17
Today I am grateful for a drink and some beer cheese soup last night with Katie, Justin, and Shira.

4/16
Today I am grateful for:
-Lunch at Wildberry with a bunch of folks from the dev community
-Dinner at a Columbian steakhouse in Lakeview.

4/15
Today I am grateful to see Johnny Clegg in concert last night, after 30+ years as a fan.

4/14
Today I am grateful for lunch with Nonnie yesterday.

4/13
Today I am grateful to get together with my team yesterday, which doesn't happen often enough.

4/12
Today I am grateful that all these family photos are now hanging on the walls of my new apartment.

4/11
Today I am grateful that my taxes are filed.

4/10
Today I am grateful for:
-The opportunity to deliver the keynote presentation at the Tech In 2016 conference yesterday.
-A front-row ticket to see Marshall Crenshaw last night.

4/9
Today I am grateful I was able to track down all my missing tax forms yesterday.

4/8
Today I am grateful for my new cuff links - the first I've received in years!

4/7
Today I am grateful for the power of ibuprofen.

4/6
Today I am grateful for dinner last night with Shelly and her family.

4/5
Today I am grateful to Brian for helping me prepare my upcoming presentation on Virtualization Containers.

4/4
Today I am grateful that I've been able to make it to the gym almost every day for the past 3 months.

Sunday, 01 May 2016 17:14:12 (GMT Daylight Time, UTC+01:00)
# Thursday, 28 April 2016

Microsoft Cognitive Services uses Machine Learning to recognize text within pictures and exposes this functionality via a RESTful Web Service.

GCast 14: Cognitive Services - Thumbnail Generation

Thursday, 28 April 2016 12:12:00 (GMT Daylight Time, UTC+01:00)
# Monday, 25 April 2016
Monday, 25 April 2016 11:51:00 (GMT Daylight Time, UTC+01:00)
# Saturday, 23 April 2016

The Bloody Crown of Conan is the second volume in Del Rey's 3-volume set of the complete Conan stories by Robert Howard. While volume 1: The Coming of Conan the Cimmerian included mostly short stories, this book contains 3 longer works: The People of the Black Circle; The Hour of the Dragon; A Witch Shall Be Born.

BloodyCrownOfConan The Hour of the Dragon is a full novel that takes Conan across many countries of the Hyborian world. It is set in a time when Conan has risen to be king of Aquilonia. Conan's enemies resurrect a dead spirit to enchant the king and steal his throne. Conan's quest to regain the crown leads him across much of the known world, where he fights numerous bottles and raises an army to retake Aquilonia. The action and the epic sweep of this story make it one of Howard's best and enhances this collection.

The other 2 novellas, while not as long or involved as The Hour of the Dragon are more complex than most of Howard's short stories.  By this point in his career, Howard seems to have hit his stride. The action flows freely, if violently, and we can enjoy the adventures of Conan who uses his nearly superhuman strength and skills to overcome nearly impossible odds.

The collection ends with a few uninteresting first drafts of Howard's unpublished Conan stories, followed by a fascinating essay analyzing the themes of the Conan series and the evolution of the character.

For escapism and adventure, it is difficult to beat these stories.

Saturday, 23 April 2016 16:28:00 (GMT Daylight Time, UTC+01:00)
# Friday, 22 April 2016
clip_image001

MadHacks is an annual weekend hackathon hosted at the University of Wisconsin in Madison, WI. The organizers decided to move the hackathon from the spring to the fall, which left a gap of nearly 18 months between events. To maintain interest, they decided to host a smaller, 1-day hackathon on April 16. The event was billed as MadHacks Spring Fever.

85 students formed teams and submitted 18 projects.

clip_image003
MadHacks organizers

I served as a mentor and a judge at this hackathon.

I also delivered a 1-hour presentation on Microsoft Cognitive Services.

clip_image005
Presentation on Microsoft Cognitive Services

4 judges evaluated all the submitted projects and chose the top 3. The quality of the projects made this difficult and we had to ask several of the teams to show their project again in order to make a selection.

clip_image007
The judges

Many of the projects were Microsoft branded, such as Xbox games, Azure books, and Microsoft sleeping bags.

The winning projects were:

  1. UniTravel: A mobile application that mapped a route to a destination and calculated not only the time and distance, but also the estimated cost using various transportation options.
  2. Chemical Reactor: A web app that visualized atomic motion and formed new molecules if atoms collided with a force that exceeded the enthalpy required to bond.
  3. Cellular Automata Plant: A web app that visualizes the growth of plant cells over time in a given environment.

 

clip_image009
The UniTravel team
clip_image011
The Chemical Reactor team

The event was organized by University of Wisconsin Microsoft Student Partner Katie Anderson.

The projects created were particularly impressive, given that they were all created in 12 hours or less.

A much larger hackathon is planned at UW-Madison in the fall semester.

Friday, 22 April 2016 13:46:00 (GMT Daylight Time, UTC+01:00)