A TimePiece of C# and JavaScript

I put together a little project on Github, partially because I’ve been making headway learning the intricacies of JavaScript, and partly because I wanted something that would parse a string that represents a time value. So here’s the TDD I went through. In the process I pulled in QUnit and used that as my testing framework for the JavaScript example. I’d love input on either of these, so feel free to gimme some heat, tell me what I’ve done wrong, and especially how I ought to be doing this.  🙂

The first thing I did was put together the C# Library. I started two projects, one for the tests and one for the actual library.  In the tests project I added a class file and removed the default using statements and replaced them with the following by way of Nuget:

[sourcecode language=”csharp”]
using NUnit.Framework;
using Shouldly;
[/sourcecode]

After adding these references I jumped right into setting up the test fixture. Since I know I want to have something to parse the hour for military time also I’ve setup two test variables.

[sourcecode language=”csharp”]
[TestFixture]
public class with_static_parsing_of_time
{
protected string sampleTimeOne = "10:12am";
protected string sampleTimeTwo = "2:30pm";
[/sourcecode]

The first test I then dived into was to test the hour.

[sourcecode language=”csharp”]
[Test]
public void should_return_a_time_piece_with_correct_hour()
{
var timePiece = TimePiece.Parse(sampleTimeOne);
timePiece.Hour.ShouldBe(10);
}
[/sourcecode]

I then fleshed out the object and implemented enough to get this test to pass.

[sourcecode language=”csharp”]
namespace TimeSlicer
{
public class TimePiece
{
public TimePiece(string time)
{
ParseTime(time);
}

private void ParseTime(string time)
{
SetHour(time);
}

private void SetHour(string time)
{
Hour = Convert.ToInt32(time.Split(Convert.ToChar(":"))[0]);
}

public int Hour { get; set; }
[/sourcecode]

I then continued back and forth writing tests and implemented each. For the complete code check out the Github Repository. This example is really simple. I’d love any thoughts on adding to it or what you might think is a better way to test the object.

For the JavaScript I downloaded QUnit. Again I stepped into the testing, which is a whole different ballgame than in C#.

[sourcecode language=”javascript”]
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen"/>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript" src="TimeSlicer/TimePiece.js"></script>
<script type="text/javascript">

var timeValueOne = "1:30am";
var timeValueTwo = "8:15pm";

$(document).ready(function() {

module("Parse hour from value.");

test("Should parse hour from value.", function() {
TimePiece(timeValueOne);
equal(TimePiece.Hour(), 1, "The appropriate hour value is returned for AM meridian value.");
});
[/sourcecode]

For the full test file with other JavaScript libraries and CSS check out the code file on github.

…and directly into implementation. With the caveat that I’m extremely unfamiliar with actual psuedo/pretend/faux object creation in JavaScript. In this realm I’m still reading up on best ways to do this.

[sourcecode language=”javascript”]
TimePiece = function(time) {
TimePiece.Hour = function () {
return time.toString().split(":")[0];
}
return time;
};
[/sourcecode]

I went on from here writing tests and implementing as I did with the C#. The JavaScript was interesting. I’ve also noticed that I get a lot of strings back versus the number values that I’d actually want, thus the addition of the “parseInt” in the final version.

Check out the overall project on Github at: https://github.com/Adron/Time-Slice

Urban Lean Agile Tech Breakfast Meetup, Be There This Wednesday!

Are you hard core into technology and software development like Node.js, JavaScript, Ruby, Rails, .NET, Java, Clojure and more?

Do you like the ideas behind the agile manifesto, lean startup, kanban, and thinking outside of the box?

Are you digging that ASP.NET MVC Framework or waiting for the next ALT.NET meetup?

Loving that ease of Ruby on Rails to wow your user base with ease, to implement with Sinatra those clean JavaScript & jQuery enabled UX for your clients?

Want to talk shop, eat some grub, have a beverage, and get a nerd kick start in the morning?

In that case meet us for Urban Lean Agile Tech Breakfast Meetup at Mod Pizza @ 1302 6th Avenue @ 8 am on Wednesday, August 3rd.

ALT.NET 2011 Day #2

Day #2 kicked off a bit late for me. I arrived around 9:30am which was a bummer, but I at least got a bit of breakfast. The first session I went to was the reactive extensions session. Again though, I was late, so I ended up lost from the get go. That was unfortunate. In addition, all of my computers I brought were either unprepared (didn’t have a VM setup on the Mac yet) or broken (the Win7 box wouldn’t boot Windows Explorer anymore, thank goodness for Launchy). In spite of all that I got lunch with a host of devs at Black Raven Brewery. Absolutely great beer there!

After that the nitty gritty hacking finally got started! I attended the AppHarbor Session (@AppHarbor) given by the founders Michael (@friism) and Troels (@troethom) and decided to start a project myself. I immediately had some bad ass cohorts jump on the team! Eric Ridgeway, Ryan Eastabrook, and Joe Balfantz. We got started, in spite of massive OS and System Failures.

The project that we started is called Regiztry and is available via a repo on Github. The idea for this project actually started with a conversation I had with Rodica Buzescu (@rodica) several months ago. The idea is a contribution, or sharing system, to work with or help out startups. Keep in mind, they’re not all landing VC money! I’ll have more descriptions about how this project is going and better descriptions of it in the near future right here on Composite Code. If you’d like to help out startups, the project, or just code with some awesome people like Eric Ridgeway, Ryan Eastabrook, and Joe Balfantz then message me on Github me.

Anyway, that’s what I got for day #2.

Bellingham Cloud Talk, Coming Right Up

Here’s the basic outline of what I intend to speak on at the upcoming presentation I have for the Bellingham, Washington .NET Users Group.  If you happen to be in the area you should swing by and give it a listen (or heckle, whatever you feel like doing).

On April 5th I have a talk lined up with the Bellingham .NET Users Group. So far here’s a quick one over of the talk:

What Cloud Computing REALLY is to us techies

  • Geographically dispersed data centers.
  • Node based – AKA grid computing configurations that are…
  • Highly Virtualized – thus distributed.
  • Primarily compute and storage functionality.
  • Auto-scalable based on demand.

What kind of offerings exist out in the wild?

  • Amazon Web Services
  • Rackspace
  • Orcs Web
  • GoGrid
  • Joyent
  • Heroku
  • EngineYard

…many others and then the arrival in the last year”ish” of…

  • Windows Azure
  • AppHarbor

Developing for the cloud, what are the fundamentals in the .NET world?

Well, let’s talk about who has been doing the work so far, pushing ahead this technology.

  • Linux is the OS of choice… free, *nix, most widely used on the Internet by a large margin, and extremely capable…
  • Java
  • Ruby on Rails
  • Javascript & jQuery, budding into Node.js via Google’s V8 Engine
  • The Heroku + EngineYard + Git + AWESOMESAUCE capabilities of pushing… LIVE to vastly scalable and distributable cloud provisions!

So where does that leave us .NETters?

AWS .NET SDK released a few years ago.
Windows Azure & SDK released about a year ago.

These two have however been lacking compared to Heroku and EngineYard for those that want something FAST,

something transformative, easy to use, without extra APIs or odd tightly coupled SDKs.

Enter…
AppHarbor

In Summary the .NET Platform has primarily:

AWS for the top IaaS and most widely available zones & capabilities at the absolutely lowest prices,

Windows Azure for the general build to PaaS Solution, and for the people lucky enough to be going the Git +

MVC + real Agile route, AppHarbor is the peeminent solution.

Demo Time…

Windows Azure Demo

AWS Demo

AppHarbor Demo

Completed Multiple Project Support in Infrastructure Solution Project

Still not sure what to call the infrastructure project. One suggestion that came up was, “Visual Fluent NInfrastructure .NET Sharp“.  It’s all trendy and wordy and can be turned into an unpronouncable acronym, VFN.NET#.  Anyway, got ideas?  Throw a comment on the post!  🙂

I got the multiple project completed and uploaded as template v1.1.

For information on how I put together the multiple project template, check out the links on the wiki here:

Also am working to add a basic vertical implementation of NHibernate up to the views with basic CRUD operations just for an example.  I’m pondering if that should be done as a separate template, maybe titled something like “template w/ samples”?  Then keeping the core template with only the skeleton code.

For more information on the project, check out the github infrastructure project page.