RSS 2.0
 Thursday, June 22, 2006

I have had the idea for a “web 2.0” application for some time, and playing with Ruby on Rails has spurred me to try a pre-alpha development of it. Make it pre-pre-alpha.

So, first step - a basic database diagram. I decided to use SQL Server 2000 as my database (not MySQL which is traditional in the open source world) because that is what I am used to. I like Enterprise manager, and I work quickly inside it. I found playing with MySQL from the command line too limiting.

I have created 4 tables to start:

First you have categories. Categories contain a number of goals. Goals contain a number of paths. And paths contain a number of steps. This is by no means complete or final, but it's a start.

Now, lets see if I can get a series of web pages set up to manage these four tables and their nested relationships.

By the way, there is a pretty good rails tutorial at O'Reilly OnLamp.

Once I have the database created, and have configured Rails to use SQL Server, I then use ruby to generate the model and component objects for these classes.

What is a model? A model is a data-tier object that represents a database table - it is a class. It provides the basic data-related create, delete, update, and find functionality.

What is a controller? A controller is an application-tier object that publishes a number of predefined (inherited) and custom methods and properties. It is also a class, but it is one level of abstraction above the database object.

Now I can generate the models and controllers separately. You can see what that looks like here and here. But I want Ruby to go that extra step further and generate all the starting code I need for my web app. You'll see what I mean in a second.

You know the old saying, “it's easier to edit than to create“, so I am going let Ruby create the basic HTML and classes needed for my application, and I will simply edit the pages according to the look and feel I want for the site. This pregenerated code is called “scaffolds”, and they are pretty cool. This will generate the models and controllers at the same time.

I will do this for all four of my database tables.

Finally, when I start the ruby web server (“ruby script/server”) and point my web browser to http://127.0.0.1:3000/categories I get:

Which is ugly as sin, but at least it's something to start editing. When I add a few sample categories it gets a bit better:

This is fun. Ruby on Rails is fun.

 

Thursday, June 22, 2006 10:34:47 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [2] -
Demo Code | Ruby on Rails | Technology
Del.icio.us Digg Technorati Blinklist Furl reddit
 Wednesday, June 02, 2004

God, I love this stuff.

So I sit down, and in less than an hour build a simple model-based testing program for my Rock Paper Scissors web service.

Basically, I start by defining all the valid states for my service.

private enum states
{
    Offline,
    ShakeHands,
    TakeTurn,
    ReceiveTurnFeedback,
    ReceiveGameFeedback
};

Then I create an array indicating all the valid state from-to combinations.

private states [] testorders =
    {states.Offline, states.ShakeHands,
    states.ShakeHands, states.TakeTurn,
    states.ShakeHands, states.ReceiveGameFeedback,
    states.TakeTurn, states.ReceiveTurnFeedback,
    states.ReceiveTurnFeedback, states.TakeTurn,
    states.ReceiveTurnFeedback, states.ReceiveGameFeedback,
    states.ReceiveGameFeedback, states.Offline};

So, taking the first line of the array above, if the rps service is currently offline, the only valid action would be to shake hands. If you have just shaken hands, you have two choices: you can either take a turn, or receive game feedback (close the game down).

The actual code is rather simple. If my RPS service were a professional application, I would improve this a bit. Basically, I keep track of the current state, loop through the array looking for all the possible actions, and then randomly take one.

// What can my next states be?
ptr = 0;
for (int j = 0; j < testorders.Length - 1; j += 2)
{
    if (testorders[j] == CurrentState)
    {
        // Add this to the list
        NextState[ptr++] = testorders[j+1];
    }
}

// Pick one
CurrentState = NextState[rndm.Next(0, ptr - 1)];

If I do this enough times, I will have tested every allowable combination of actions and states. And somehow there was a new allowable action, for instance, SayNiceGame(), I could add that to my states array easily enough.

Possible improvements to my application would include testing for exceptions, and handling them gracefully; keeping statistics about the number of tests run; calculating the percentages of each choice made (rock, paper and scissors)... You can start with a basic test model, and make it more complex as you have time.

Testing Web Service, v1.0 - C# Source Code

Testing Web Service, v1.0 - .NET Binary

 

Wednesday, June 02, 2004 12:54:08 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET | Demo Code
Del.icio.us Digg Technorati Blinklist Furl reddit
 Saturday, May 22, 2004

OK, I promised yesterday to release the .NET client application I wrote that interfaces with my Rock-Paper-Scissors (RPS) web service, so here it is:

RPS Client v1.0 - Source Code and Binary

It's a very simple app. I wrote it in 45 minutes or so, so don't judge me to harshly on it. Here's a screen shot.

As you can see, after 50 hands, my web service kicked my human ass, 20-12. I haven't yet added any of the advanced RPS code in there either.

 

Saturday, May 22, 2004 1:52:50 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET | Demo Code
Del.icio.us Digg Technorati Blinklist Furl reddit
 Wednesday, May 12, 2004

Here's a simple VB.NET program I wrote to look at all of the log files for my dasBlog blog, and report all of the search terms people used in Google to get here.

Most Popular Search Terms, v0.1 - Source Code

Most Popular Search Terms, v0.1 - .NET Binary

Here's how the program looks at startup:

Here's how it looks after searching:

Suggestions/comments appreciated.

 

Wednesday, May 12, 2004 1:05:25 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET | Demo Code
Del.icio.us Digg Technorati Blinklist Furl reddit
Archive
<May 2008>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Scott Duffy
Sign In
Statistics
Total Posts: 453
This Year: 12
This Month: 1
This Week: 0
Comments: 70
Themes
Pick a theme:
All Content © 2008, Scott Duffy
DasBlog theme 'Business' created by Christoph De Baene (delarou)