Monday, March 30, 2009

Workshop 4: Riding the Rails with Ruby

To do:
1. Spend some time moving your way through the 46 Ruby coding examples in the Ruby Tutorial with Code from http://www.fincher.org/tips/Languages/Ruby/

I have go through the 46 Ruby coding examples:
  1. Install Ruby
  2. Our first program
  3. Output in Ruby
  4. Reading from the Console
  5. Functions
  6. Open Classes
  7. Variable naming
  8. Interesting tidbits about Ruby
  9. Variable Types
  10. Missing
  11. Quotes
  12. Objects
  13. Big Numbers
  14. Parallel Assignment
  15. Collections (Arrays, Hashes, Ranges)
  16. Control Statements (if, case, for, exit, loop)
  17. Statement modifiers (if, unless, while)
  18. Iterators (while, times, each, each with ranges, upto)
  19. You gotta have class (classes, ToString, to_s, subclassing, virtual attributes)
  20. Regular Expressions
  21. Blocks
  22. File I/O
  23. method_missing - a wonderful idea
  24. "BEGIN" / "END"
  25. converting between strings and ints
  26. Using XML Dom Parser
  27. Run a few lines directly from the command line with the "-e" option
  28. Editing files in place
  29. Example of printing duplicate lines in sorted file
  30. Ruby has it own interpreted shell, irb
  31. Ruby can take input stdin
  32. to pass a string on the uri it needs to "escape" first
  33. Example to remove "funny" characters from a filename
  34. Looping over list of arguments
  35. Miscellaneous Commands
  36. DataTime
  37. Using 'requie'
  38. BuiltIn Command Interpreter
  39. Introspection with ObjectSpace
  40. Testing
  41. Read a URL and print the web page to the screen
  42. Example of drawing a line on a canvas in Tk
  43. irb - interactive ruby
  44. RubyGems a ruby package installer
  45. Ruby on Rails
  46. Ruby Quotes
2. What are the syntax differences in the way that Ruby and Javascript use the if statement?

Ruby if statement:


Javascript if statement:


The syntax differences in Ruby and Javascript use the if statement:
  1. Both Ruby and Javascript If statement start with " if "
  2. Both of them write the actual condition just after the word " if ", but Javascript write the actual condition in between the open " ( " and closed " ) " brackets
  3. In Ruby specifies what will happen if the condition is satisfied, is written before word " end ", but in Javascript it is written between open " { " and closed " } " curly brackets (or braces)
  4. In Ruby uses the " else " or " elseif ", but in Javascript uses " else " or " else if " to specify what to do next if the condition is not satisfied.
3. While Ruby and Python are quite similar, can you find some similarities between Ruby and Javascript?

Ruby has many of the same language features that JavaScript has, including (Seidman, 2006):
  • extension by mixin (mixin in OO programming, is a class that provides a certin functionality to by inherited by a subclass)
  • duck typing (duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the vaild semantics, rather than its inheritance from a particular class or implementation of a spceific interface.)
  • a YAML equivalent JavaScript Object Notation (YAML is a human-readable data serialization format that takes concepts from language sech as XML, C, Python, Perl)
  • arbitrary class and object extension (ie. adding methods/properties to classes or specific objects at any time)
  • simple arrays and hashes
  • has first-class functions, which are the same (though not identical) as blocks.

Challenge Problems:
1. Create, test and debug a Ruby program called dognames.rb or catnames.rb to accept 3 names from the keyboard and to display each name on the screen in alphabetical order WITHOUT using a data structure such as a list.

The dognames.rb program:


The testing of the dognames.rb program:


2. Write a Ruby program called fizzbuzz.rb that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

The fizzbuzz.rb program:


The result of the fizzbuzz.rb program:


3. Compare the Ruby and Python versions of the dog years calculator:


Reference
  1. Seidman, G. (2006), Faq and javascript vs. ruby (was re: rubynuby - client side ruby?), newgroups.derkeller.com, Retrieved from http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.ruby/2006-02/msg02949.html on 1st April, 2009

Thursday, March 26, 2009

Workshop 3: Online Taxi Booking System: MySQL and Database design:

To do:
1. Set up the MySQL tools on your computer as described in section 6 above.

I had install the 'Sequel Pro' in my Mac, use it to connect the MySQL database named test, browse the table employees in it:


2. Rails will setup a new application directory for each of your Web application projects. Get InstantRails (Windows) or Locomotive (MacOS) running on your machine. Both packages install Ruby, Rails, a Web server or one called ‘Mongrel’ or another small Ruby Web server called ‘WEBrick’, and MySQL “inside a bubble” as I call it so that others parts of your system are not modified (Similarly ZOPE does with installing its own Web server and Python versions)

Run the Locomotive and Create Rails Application named OTBS:


3. Once Rails is running you at http://localhost:3000, you need to configure database access. Connection to the database is specified in the config/database.yml file.

Running Rails in my Mac:


The database.yml that under the config folder:


4. Generate the Passenger model by creating the MySQL database and ‘passengers’ table from the information above.

Create the table passengers in database OTBS by MySQL tools Sequel Pro:


Generate the Passenger model in the Terminal: ruby script/generate model Passenger


The model Ruby class located in app/models/passenger.rb:


5. Further work on understanding MySQL under Rails by David Mertz:
a. See “Fast-track your Web apps with Ruby on Rails” at http://www-128.ibm.com/developerworks/linux/library/l-rubyrails/

Summary after reading of the “Fast-track your Web apps with Ruby on Rails”:
  • Introducing Rails - Rails provides a very clear and focused MVC way of thinking
  • Describe how to building a simple application
  • Describe how to creating customizable content
  • Describe how to changing the model
  • Rails gives us a extremely quick way to develop flexible Web applications.
  • Rails development offers us a clear path from a half-formed idea to a fully functioning Web applciation.
b. The “Rolling with Ruby on Rails” series and “Cookbook recipes by Curt Hibbs and others beginning at http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html

Summary after reading of the “Rolling with Ruby on Rails” series and “Cookbook recipes by Curt Hibbs":
  • The article steps through using Rails to develop a Web application
  • What are Ruby and Rails?
  • Installation steps of Ruby on Rails (install: Ruby, Rails, MySQL, MySQL-Front)
Web application development steps using Rails:
  1. Create an empty Rails Web application (eg. Run the command: rails cookbook)
  2. Test the empty Web application (eg. Run the command: ruby script\server)
  3. Introduction of Rails application's directory structure
  4. Create Controller class (eg. Run the command: ruby script\generate controller Mytest)
  5. How to use the index method of MytestController to display 'Hello World' ?
  6. How to create database and table in MySQL using MySQL-Font
  7. Create Model (eg. Run the command: ruby script\generate model Recipe)
  8. How to create, list and delete database record by using the Controller and add the command scaffold?
  9. How to create actions and Views?
  10. How to assign relationship between tables and make them work in the Rials?

Saturday, March 21, 2009

Workshop 2: Model View Controller design approach

To do:
1. Set up a focus group (like a study group for peer learning) to work on the Ruby on Rails workshops via Interact tools as a class.

I setup a focus group that work on Ruby on Rails at: http://railsfocusgroup.blogspot.com, and had invited our classmates to join by personal email. The link of the blog was also posted on CSU Forum.

2. What is meant by “convention over configuration” and how does it reduce coding?

A Web application is composed by many parts in different ways. If we have a variable named picture in a computer program, and have a column named image in the database table. The computer retrieves data from the image table column and stores the data in picture variable. Then the program performs some acrobatics with the picture variable's data. the programmer tie-up the picture and image together using a configuration file. The configuration file encodes facts such as "variable picture reads data from column image". Programmer spend time to write the configuration files and specifying complex chains of names. Finally, errors creep into the system, and programmers spend more times fixing bugs (Burd 2007).

In Rails, a variable named image matches automatically with the column of the same name in the database table. A variable named Picture matches automatically with a table named pictures (in plurals form). And a variable named Person matches automictically with a table named people (Rails understands plurals) (Burd 2007).

3. Further work on understanding MVC:
a. See the wiki at http://wiki.rubyonrails.org/rails/pages/UnderstandingMVC

The page doesn't exist.


b. Do the MVC tutorial at http://wiki.squeak.org/squeak/1767

Summary after my reading:
MVC has been the easrliest and most successful design patterns since 1979 by Trygve Reenskaug. MVC paradign the user input, the modeling of database, and visual feedback to users are handled by 3 types of object separately:
  • View - manages the graphical and textual output to the display
  • Controller - interprets the mouse and keyboard inputs from users, controlling the model and the view to change appropriate
  • Model - manages the behavior and data, responds to requests and instructions.
4. Got a spare hour or so? I recommend the UC Berkeley RAD lab’s Ruby on Rails Short course at http://youtube.com/watch?v=LADHwoN2LMM

The video is about 1 hour 15 minutes long. It is the Part 1 of Ruby on Rails short course that conducted by RAD Lab, University of California, Berkeley. The title of the Part 1 is 'Hello World'. The speaker is Armando Fox. Armando reviewed and introduce:
  • Web apps of the Rail
  • How MVC design pattern work in Rails
  • SQL operations (Create, Read, Update and Destroy)
  • Convention over configuration
  • Hello World program
  • Some programming technique demo in Rails
5. Read the Flash article using ActionScript by Colin Moock titled "The Model-View-Controller Design Pattern" at http://www.adobe.com/devnet/flash/articles/mv_controller.html

The article is a chapter come form the book Essential Action Script 2.o which written by Colin Mock, issue by O'Reilly's. The article explains the concept of the Model-View-Controller (MVC) Design pattern.

The MVC design pattern separates user interface code into 3 distinct classes:
  • Model - store the data and application logic for the interface
  • View - Renders the interface (usually to the screen)
  • Controller - Responds to user input by modifying the model
The basic principle of MVC is the separation of responsibilities, separating the code that governs user interface into the mode, view and controller classes generate the following benefits:
  • In the same information (model) allows multiple representations (views)
  • At both compile time and runtime allows user interfaces (views) to be easily added, removed or changed
  • At both compile time and runtime allows response to user input (controller) to be easily changed.
  • Advance for reuse
  • Multiple developers update interface, logic or input of an application without affecting other source code at the same
  • Developers can focus on a single job of the application at a time
Responsibilities of:
  • Model - stores data in properties and provides application-specific methods that set and retrieve that data. The data-management methods are not generic, they are customized in each application and must be known to the controller and the view.
  • View - create user interface and keep it up-to-date. The view monitor the state changes in the model. If change occur, the view updates the interface to reflect the change.
  • Controller - monitor for notifications from the view, based on user input and translates the input into changes in the model. The controller sometime makes logical decisions about the input before making the corresponding change to the model.
Challenge Problems:
1. How is Rails structured to follow the MVC pattern?

Ruby on Rails fully apply the MVC framework, Rails divides the work of an application into Model, View and Controller separately. MVC work in closely cooperative subsystems. Coding in Rails do separately in different sub folders for MVC pattern. Writing code can be done by different programmers, but they are working together for the same application.

Model (ActiveRecord) - Maintenains the relationship between objects and database. It handles validation, association, transactions and etc. ActiveRecord library implemente this subsystem, which provides an interface and binding between the tables and Ruby program code. Ruby method names are automatically generated from the field name of the database tables.

View (ActionView) - presentation of data in particular format, called by the decision of a controller to present data. They are script based very easy to integrate with AJAX technology. This subsystem is implemented in ActionView folder which is embedded Ruby based system, define presentation templates for data presentation. The display of a view in an application respesent the results.

Controller (ActionController) - directs traffic within an application, query the models for specific data and organize data such as searching, sorting and massaging it, into a form that fits the needs of the view. This subsystem is implemented in ActionController which is the connector between ActionRecord and ActionView.

2. Apply the MVC design approach to our Project: Online Taxi Booking System.

The workflow for creating Online Taxi Booking System (OTBS) application in the Rails:
  1. Create basic skeleton of the application by using Rails command: rails OTBS
  2. Create a database in the MySQL server to store OTBS records by using SQL command in the MySQL: mysql> create database OTBS;
  3. Configure the application to know where the database is located and the login authority for it by modify the configuring file named database.yml that located in \ruby\library\config.
  4. Create Rails models (ActiveRecord), they are the objects working in controllers. By using Rails command: ruby script/generate model Taxi.
  5. Generate migrations that makes creating and maintaining database tables and columns easy. By using Rails command: ruby script/generate migration Taxi.
  6. Write controller code to make it works in the application. By Rails command: ruby script/generate controller Taxi. And then implementing different Methods
  7. Create Views file to present data through user interface
Reference
  1. Burd, B. (2007), Ruby on rails for dummies, Wily Publishing, Inc.

Friday, March 20, 2009

Exercise 11: XML introduction

1. Conduct research on the Internet to find out what tools can be used to parse an XML document and ensure that the document is well formed and valid.

Parser is a essential tool for reading and modifying XML document. The term 'parser' are sometimes interchangeable with 'processor'. Any program that input an XML file and produces the output based on the XML files content is an XML processor. An XML browser is a kind of processor. A parser is software that performs the first step in the processing of an XML document. Parser is almost always used as part of an XML processor. The foundation task of a parser is checking the XML document for well-formed data, and make sure the documents content follows the rules of XML syntax. Most of the parsers can check the document for validity by checking against Document Type Definition (DTD) or Schema. The final task of the parser may perform to make the content of the document, both markup and data, available to the processing software. SAX (Simple API for XML) API or Document Object Model (DOM) API does this (Dev Shed, N.A.).

2. What are the benefits of adopting a schema standardized for a business sector?

A schema standardized like XML, can be used as information exchange for different formats in different computer systems and databases. Developers do that challenging and time wasting job in data exchange between such system over Internet. It is simple in converting data to XML and generate data that can be read by different types of applications. XML data can be store in files or database. So applications can store and retrieve information from the data store, then display the data out.

3. SMIL is an application of XML. What is the purpose of this technology? Where does it apply?

SMIL is stand for Synchronized Multimedia Integration Language. SMIL define an XML-based language that allows authors to write interactive multimedia presentations. In SMIL, authors may describe the temporal behaviour of a multimedia presentation, associate hyperlinks with media objects and describe the layout of the presentation on a screen(Bulterman, 2008).

SMIL enables simple authoring of interactive audio and visual presentations. SMIL integrates streaming audio and video with images, text or any other media type in "rich media" multimedia presentations. SMIL presentations can be written by using of a simple text-editor. The SMIL language is easy to learn (W3C, 2008).

Reference
  1. Dev Shed (N.A.), My first xml document - tools for parsing xml, Developer Shed., 5-6. Retrieved from http://www.devshed.com/c/a/XML/My-First-XML-Document/2/ on 20th March, 2009
  2. Bulterman, B. and W3C's partners (2008)., Synchronized multimedia integration language (smil 3.0), W3C. Retreved from http://www.w3.org/TR/2008/REC-SMIL3-20081201/ on 20th March, 2009.
  3. W3C (2008)., Synchronized Multimedia, W3C. Retrieved from http://www.w3.org/AudioVideo/ on 20th March, 2009.

Tuesday, March 17, 2009

Exercise 10: Application server platforms in e-commerce

1. Go to the website of IBM, Oracle, Microsoft and Sybase. Is there any mention of e-commerce associated with their database products? What suite or partnership do they list with related e-commerce offerings? How do they compare with open source products like MySQL?

I visit the IBM website: http://www.ibm.com/, I use the keyword 'e-commerce solution' to search related articles in the IBM website, it return 17,995 results. I select an article title 'WebSphere Commerce V6.0 delivers a complete end-to-end e-commerce solution' retrieved from http://www-01.ibm.com/common/ssi/cgi-bin/ssialias?subtype=ca&infotype=an&appname=iSource&supplier=897&letternum=ENUS206-115#@2h@75@ to read through it.

WebSphere is the Web server that provided by IBM and it use DB2 as it database. The WebSphere can run J2EE package, build and extend Enterprise JavaBeans in it. IBM also provide education support and a full set of maintenance for their WebSphere Web servers.

I find an article titled 'Leverage MySQL skills to learn DB2 Express: BD2 versus MySQL backup and recovery' the IBM website, retrieved from http://www.ibm.com/developerworks/data/library/techarticle/dm-0606tham/. This article focuses on the capabilities of DB2 Express-C (Database provided by IBM) highlighting the similarities and differences between open source MySQL and DB2 Express-C in backup and recovery. The testing is very details, and produce different comparison tables show below, IBM DB2 Express-C is the absolute winner.




I visit the Oracle website: http://www.oracle.com/, I use the keyword 'e-commerce solution' to search related articles in the IBM website, it return 164 results. I select an article title "Oracle's Complete Sell-Side E-Commerce Solution" retrieved from http://www.oracle.com/applications/sales/oracle-sell-side-e-commerce-white-paper.pdf to read through it.

Oracle offers a comprehensive e-commerce solution that:
  • Enable collaboration with customer, channel partnrer, distributors, and resellers in order to profitably support the entire sales process
  • Provides proven e-commerce technology and application in many industries such as high technology, consumer products, manufacturing, healthcase and telecommunications etc.
  • Integrates completely with Oracle E-Business Suite, can also be integrated with legacy and third-party systems
The Oracle database integrated with his CRM and ERP applications, and powered by Oracle Trading Community Architecture to provide a complete e-commerce solution.

An article 'Interview with Charles Phillips: The Future of informatin Technology at Vortext 2004' that retrieved from http://www.oracle.com/corporate/pressroom/cphillips_vortext04.html compare the open-source database MySQL with Oracle's database. Phillips said that 'If we're all in the transportation industry, then Oracle is the 747 and MySQL is the car that gets you to the airport'. Their customer migrate from MySQL to Oracle when they go for more robust database software.

I visit the Microsoft website: http://www.microsoft.com/, I use the keyword 'e-commerce solution' to search related articles in the Microsoft website, it return 55,200 results. I select an article title "E-Commerce" retrieved from http://msdn.microsoft.com/en-us/office/aa905430.aspx to read through it.

Microsoft provide a list of consultants who partner with him. The nearby vendor can be find from http://www.microsoft.com/smallbusiness/partner/vendorsearch.mspx after entry your Postal Code. If you want to develop a custom e-commerce application by yourself. Microsoft provide Access and SQL Server database, and ASP.NET Web site development framework.

An article "Compare SQL Server to MySQL", retrieved from http://www.microsoft.com/sqlserver/2008/en/us/compare-mysql.aspx show the different between SQL Server 2008 and MySQL. The author said that "Microsoft SQL Server 2008 outperforms MySQL as a database platform in all business-critical areas". The Microsoft SQL Server 2008 provides the following that better and a comprehensive business intelligence platform at low total cost of ownership:
  • large resource network
  • industry-leading performance and enterprise-ready scalability
  • highest level of security
  • highest availability
I visit the Sybase website: http://www.sybase.com/, I use the keyword 'e-commerce solution' to search related articles in the Sybase website, it return 62 results. The major products of Sybase are database and its related software tools. Their partners who provides their solution can be found in the Web site, such as HandStep, Advanced Foodsystems, mPower, Ventyx, Wasp etc.

An article "Performance Comparison of ASE 15 vs. MySQL 5.0", retrieve from http://www.sybase.com/detail?id=1045499. Adaptive Server Enterprise (ASE) is a database server that provided by Sybase. It said that ASE 15 has show an advantage in overall performance for transaction processing over MySQL 5.0, and many complex queries show significant improvements. A detail testing report can be found in http://www.sybase.com/content/1045499/Sybase_ASE_MySQL-102406-wp.pdf.

2. Why is the perception getting stronger that integration will become a critical factor in coming days? What is the role of AJAX within the enterprise software architecture?

When an environment is capable of recognizing and describing things, people and activities within its volume, the environment is said to be "perceptive" stated by (Alper, 2005). He also said that for general purpose and robust, perception must integrate information from multiple sensors and multiple modalities.

An interactive enviroment is capable responding to humans using tightly coupled perception and action. Simple forms of interaction may be based on sensing grasping and manipulation of multiple sensor devices, integrate all those information that captured from those devices to build a stronger perception environment (Alper, 2005).

The role of AJAX within the enterprise software architecture:
AJAX is not a new technology, it combination of several existing technologies in a new way. AJAX include HTML, CSS, DOM, XML, XSLT, XML, Http Request and Javascript in it stated by (Rose India, N.A.). AJAX application eliminate the start stop nature of traditional Web pages, allow Web application to look and behave like the desktop ones. AJAX allows pages to request small bits of information from the server, instead of entire pages' contents. The page refreash problem and slow response are eliminated by this incremental updating of pages.

AJAX is playing a significant role in making Web 2.0 become real. AJAX interfaces are a key component of many Web 2.0 applications. The Web sites of Google, Yahoo, Microsoft, Amazon and many others have embraced AJAX (Rose India, N.A.).

The figure retrieved from Relevance, LLC (2005):

AJAX is used for:
  • Validation
  • Active Search
  • Dynamic Forms
  • Input Suggestions
  • Panning Image Data
  • Organizing and Navigating Data
  • Parallel Activities
3. What are the similarities between the object-oriented development using model-view-controller (MVC) in Ruby on Rails 2.0 and Action Script 2.0 (Flash animations)?

ActionScript 2.0 is an object-oriented is a formal and familiar approach to object-oriented programming (OOP) which including full support for classes, inheritance, interfaces and other common OOP concepts. OOP is an option approach to developing applications by using an additional set of language elements (deHaan, 2005). But In Ruby everything is an object (Alameda, 2008).

Programmer can use model-view-controller MVC design pattern in coding their ActionScript 2.0 (Moock, 2004). But Ruby on Rails is a full-stack MVC framework for database-backed web applications, let coding by favor convention over configuation (Alameda, 2008).

Reference
  1. Alper, R. (2005), Perception, recognition and integration for interactive environments, Project-Team PRIMA, Institut National De Recherche En Informatique Et En Automatique.
  2. Alameda, A. (2008), Foundation rails 2, Springer-Verlag New York, Inc.
  3. deHaan, J. (2005), Flash ActionScript 2.0 Learning Guide, Macromedia Instructional Media Development, Retrieved from http://www.adobe.com/devnet/flash/articles/actionscript_guide.html on 20th March, 2009.
  4. Moock, C. (2004), Essential actionscript 2.0, O'Reilly Media, Inc. , Retrieved from http://www.adobe.com/devnet/flash/articles/mv_controller.html on 20th March, 2009.
  5. Relevance, LLC (2005), Ajax architecture, Relevance, LLC,Retrieved from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.119.3779&rep=rep1&type=pdf on 20th March, 2009.
  6. Rose India (N.A.), The role of ajax in enhancing the user experience on the web, Rose India, Retrieved from http://www.roseindia.net/ajax/ajax-user-interface.shtml on 20th March, 2009.

Sunday, March 15, 2009

Exercise 9: Web form design and processing: A basis for e-commerce interaction

1. Design the form
“Retrofit” the form data string above for buying some French perfume into the HTML form fields and submit button on the Web page form.


Form of Retrofit:


The coding:


When click on 'Submit' button, the data string: "name=Dennis&card=visa&number=1234567890123456&order=French+perfume&submit=+Submit+" submitted to the server. As the missing of server side program, an error show bellow.


2. Write the script
Script archives exist for PERL, Python and JavaScript. Search the Web for a script that processes the HTML forms data. Read the code and list the steps involved in processing the form.


I found a CGI script from CGI101.COM Web site at http://www.cgi101.com/book/ch3/text.html, the script named get.cgi runs in the server to process the form named getform.html that submitted by the client:
----------------------------------------------------------------------------
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

print header;
print start_html("Get Form");

my %form;
foreach my $p (param()) {
$form{$p} = param($p);
print "$p = $form{$p}<br>\n";
}

print end_html;
----------------------------------------------------------------------------
The first line #!, indicates that this is a script. The next part /usr/bin/perl, is the location of the Perl interpeter. The final part contains optional flags for the Perl interpreter. Warnings are enabled by the -w flags. Special user input taint checking is enabled by the -T flag.

The second line use, includes the module from standard library that provide a number of useful functions and features for writing CGI programs. The following functions in the above script is come from that module:
  • header;
  • start_html;
  • end_html;
The print header, function prints out the "Content-type" header.
The print start_html("Thank You") defines the page title as "Thank You".
The end_html, prints the footer.

The third line, use CGI:: Carp..., causes all warnings and fatal error messages to be echoned in the browser window for program debugging.

The fourth line, use strict, is a standard Perl module that requires the programmers to declare all variables for good programming style.

After print out the 'Thank you' on the return screen, the foreach loop read the variables in the form of the call program and print them out to the screen line by line.

The screen of getform.html:

The screen of get.cgi:


3. Can you modify the script to process the form?

Yes, I can modify the CGI script of the post.cgi to process the form "Retrofit".
As the CGI server setting in my computer is not the same as the above example. I use the command to find out the Perl location in my computer and modify the first line in the script to:
#! /opt/local/bin/perl -wT



Friday, March 13, 2009

Exercise 8: PHP and MySQL database access

1. Start with a simple table in the database:
mysql> SELECT * FROM employees;


Connect to database named test, and create table named employees:


Insert and select record in table employees:


2. Create a web page with the following PHP:

Web page display the first record in the employees table:


3. This is how we can add a record and is part of a file to create called add_record.html

The employees record add form:


4. The corresponding PHP file is add_record.php used with the POST method:

Record added into table employees by program add_record.php:
Correct typing error in INSERT statement from : "INERT" into "INSERT"


5. The last code example shows how to get multiple records:

Web page display multiple records:
Modified line 8: echo "", $myrow[2], ", ", $myrow[1], ""
To:
echo "", $myrow[0], ", ", $myrow[1], ""


Exercise 7: User input for database access with PHP

1. Create an HTML page with the form:

The result screen of HTML page with the form:


2. Then, create a PHP file named submit.php with the following code:

The result screen after input of my name:

Thursday, March 12, 2009

Exercise 6: Some server practice with PHP

1. In this exercise with can call up and examine some environment variables on the server. The code below has the UNIX environment variable for storing your remote Internet address. UNIX environment variable are recognised by the use of upper case letters. Try the same code by replacing with $REMOTE_ADDR $SERVER_NAME, or $PHP_SELF

The result screen of $REMOTE_ADDR:
Display the client address on screen


The result screen of $SERVER_NAME:
Display server address (as the server and the client are in the same machine, the address of them are the same) on screen


The result screen of $PHP_SELF:
Display the file name of the php program on screen


2. Create a web application called "hello_world.php" which contains in the body:

The result screen of "hello_world.php":

Tuesday, March 10, 2009

Exercise 5: Network and programming frameworks

1. Investigate a simple chat client/server system. Look at some program code and describe how it works with multiple users.

A simple chat client/server system have a simple graphical user interface with separate areas for messages received and message being typed. Each user have a nickname by which they will be identified in all received communications. The system allow users to join and leave the conversation at any time.

Multi-user chat systems allow users to participate in chart rooms where they can chat together. The status of users such as on-line, off-line and busy etc show on the program window. User type messages into the message input area and send it out by pressing the send button, the receiver capture the message and display it in message display area.

Chart room is a server side program and users run the chart client program in their own computers. All chart client need to connect the server chart room program to start the communication.

The server side code works for multiple users:
// While loop to accept() client requests :
// For each client connection request, accept() generates a new socket (sockfd).
// A child process is forked and use new_sockfd to communicate with client.

while(1) // parent process always loops to wait for new client connect.
{
sin_size = sizeof(struct sockaddr_in);
if ((new_sockfd = accept(sockfd, (struct sockaddr *)&clnt_info, &sin_size)) == -1)
{
perror("accept error");
continue;
}

pid=fork(); // fork a child process to service client connection
switch(pid)
{
case -1: // if occur fork errror
{
perror("fork error");
exit(1);
}
case 0: // this is the child process
{
close(sockfd); // close listener, child doesn't need the socket of listener
.................


The client side pass the socket information to server:
// Connet to remote server
if (connect(sockfd, (struct sockaddr *)&srv_info, sizeof(struct sockaddr)) == -1) {
perror("connect error");
exit(1);
}

//get client's information by getsockname() & stored in struct sockaddr clnt_info
getsockname(sockfd, (struct sockaddr*) &clnt_info, (int *) sizeof(clnt_info));

Different clients connect to the server by socket, so the server can distinct users by different socket connection.

2. Describe the important and distinguishing properties of Peer to Peer computing and the Grid. How is this peer to peer and the Grid architecture changing work flow and service-oriented applications?

Peer-to-Peer computing refers to a group of systems and applications that employ distributed resources to perform a function in a decentralized manner. The critical function can be distributed computing, data and content sharing, communication and collaboration, or platform services. Typical P2P systems place in the edge of Internet or in ad-hoc networks. P2P computing enables valuable externalities, lower cost of ownership and cost sharing, and anonymity/privacy.(Milojicic, 2003). P2P computer network does not have clients or servers but only equal peer nodes that simultaneously function as both 'client' and 'server'. P2P gained visibility with Napster's support for music sharing on Web (Napster, 2001).

Grid computing is an application used to run by several computers together to solve a problem at the same time, usually involve in a scientific or technical problem which requires a large number of computer processing power or access to a lot of data. Grid computing can also be thought as distributed and large-scale cluster computing (Wikipedia 2009).

3. Frameworks for development. Compare and contrast any TWO of:
a. Java
b. NET
c. Ruby on Rails
d. Turbo Gears
e. Google Gears
f. AJAX frameworks


Compare and contrast of Java and .Net
(Thomsen, N.a.):




  • Both are multi-tiered, similar computing technologies
  • Both support 'standards'
  • Both offer different tools and ways to achieve the same goal.
  • A lot of parallelism
  • As each has its own pro and con, it is difficult to compare and qualify the comparsion

  • .Net can use VB, C# as it programing language
  • C# and Java are an object oriented language
  • The syntax of C++, C# and Java are similar
The environment in running .Net and Java:

  • JVM designed for platform independence
  • CLR designed for language independence (Muliple languages for development)
  • Java byte code (or JVML) is the low-level language of the JVM.
  • MSIL (or CIL or IL) is the low-level language of the .Net Common Language Runtime (CLR)
In mobile devices, Java applications are reasonably successful, and Microsoft is moving fast into the field with .Net Compact Framework.

Development tools:
  • Well support in server-side for both Java and .Net IDEs
  • .Net IDE's benefit from the fact that .Net CF is so close to .Net on the client-side (There are separate IDE's for desktop and mobile application development in Java)
  • There has compatibility problems between Java vendors
  • Java IDEs are slow
  • C# is richer/more complex language than Java
  • Both Java and .Net have well documented API
  • Support for encryption of web services (.Net CF: https and SOAP extensions / J2ME: https, but only in CDC & MIDP 2.0
Development time:
  • Slow in start up when developing in Java
  • Trouble-free implementation in .Net
Development satisfaction:
  • .Net integrates web service and mobile application developement far better than Java IDE
  • A subset of an API is better solution for mobile devices instead of an entirely new API
  • .Net is a better designed framework, because it eleiminates the language barrier while also being platform independent, and it makes only little distinction between desktop and mobile application development
  • Sun's application server performance is very poor compared to IIS
  • License fees for a Java based solution are cheaper but .Net might catch up when considering development time
Reference
  1. Milojicic, D. S. (2003), Peer-to-peer computing, HP Laboratories Palo Alto, HPL-2002-57 (R.1).
  2. Napster (2001), The Napster home page, http://www.napster.com/
  3. Thomsen, B. (n.a.) Java vs .net, Aalborg University, Department of Computer Science, Retreived from http://www.myplick.com/view/afZKCnJuG9C/Java-vs.-.Net on 12th Mar, 2009.
  4. Wikipedia (2009), Grid computing Retrieved from http://en.wikipedia.org/wiki/Grid_computing on 11th Mar, 2009.

Exercise 4: Virtual private networks

1. Describe the IP protocol. What is DNS?

IP is stand for Internet Protocol, is responsible for moving packet of data from node to node. IP forwards packet based on a four byte destination address called IP number. In the Internet, the authorities assign ranges of numbers to different organization. The organizations assign groups of their numbers to their departments. IP operates on gateway machines, move data from department to organization to region and then the world (Gilbert, 1995)

DNS is stand for Domain Name System, is an Internet service that transforms domain names into IP addresses. As domain names are alphabetic for harman readable and easier to remember, the Internet/network only know on IP address. Each time we use a domain name, therefore, a DNS service used to translate the name into corresponding IP address (Webopedia 2009).

2. Describe the TCP protocol. How is it related to the IP protocol?

TCP is stand for Transmission Control Protool, is responsible for verifying the correct delivery of data between client and server. Data can be lost in the intermediate network. TCP adds support to detect errors or lost data, and to trigger retransmission until the data is correctly and completely received by the client/server (Gilbert, 1995).

TCP/IP is also called Internet Protocol Suite. TCP and IP work together to form the set of communication protocols used for the Internet and other similar networks. The TCP/IP model consists of four layers. The lowest layer is Link Layer, then Internet Layer, Transport Layer and the highest layer is Application Layer. The TCP is in the Transport Layer and IP is in the Internet Layer (Wikipedia 2009a).


3. What do you know about building e-business applications as an Intranet, Extranet, Web portal, B2B, B2C or Virtual Private Network (VPN)? Find some examples on the Web

For data security issue B2B e-business may building in an extranet for outside office commuciation (Phan ,2003). An extranet is a private network that uses Internet protocols, and it is possible for the public telecommunication system to securely share the organization's information or operations with suppliers (B2B), vendors (B2B), partners (B2B), customers (B2C) or other businesses (B2B) (Wikipedia 2009b).

Users can log into one place and have access to many other intra/extranet sites by only key in the user ID and passwords (Phan, 2003). An intranet is also a private network that use Internet technologies to securely share the organization's information or operational (Wikipedia 2009c).

When the company extend their Web site for Internet access through the Internet service provider (ISP), they may need a more secure solution for B2B or B2C communication in an open environment. Virtual private network (VPN) is a good solution for B2B communication (Phan, 2003). As it needs some specific setting to start a VPN communication, it is only suitable for B2B environment. Another issue suitable for B2C secure communication is Secure Sockets Layer (SSL).

Examples:
The Intel Web site for the Resellers (B2B), they need to login in with their ID and password:
Stratford Hall Web site for business customer (B2B) to order their card in the Web:
The ebay Web site for customer (B2C) to buy and sell their product, they need to login in or register in the Web. The side is protected by SSL:

4. What role can a VPN play in business-to-business e-commerce?

Virtual Private Network (VPN) make communications and exchanges always possible and secure in use of Internet (). The role of VPN in the business-to-business (B2B) environment allowing users to connect to the corporate network whenever, wherever or however they require. Users can benefit of the Internet public framework to constitute a VPN as an economic alternative to the leased line network. The advantage of VPN compared to leased lines is more flexible for B2B customers (Karp, 2001).

Reference
  1. Gilbert, H. (1995), Introduction to tcp/ip, PCLT. Retrieved from http://www.yale.edu/pclt/COMM/TCPIP.HTM on 10th Mar, 2009
  2. Karp, H. (2001), White paper: providing dynamic vpn service for b2b, FORM Consortium, IST-1999-10357/ATOS/WP6/3010.
  3. Phan, D. D. (2003), E-business development for competitive advantages: a case study, Information & Management, 40, 581-590.
  4. Webopedia (2009), Dns, Webopedia. Retrieved from http://www.webopedia.com/TERM/D/DNS.html on 10th Mar, 2009
  5. Wikipedia (2009a), Internet Protocol Suite, Wikipedia. Retrieved from http://en.wikipedia.org/wiki/TCP/IP on 10th Mar, 2009
  6. Wikipedia (2009b), Extranet, Wikipedia. Retrieved from http://en.wikipedia.org/wiki/Extranet on 11th Mar, 2009
  7. Wikipedia (2009c), Extranet, Wikipedia. Retrieved from http://en.wikipedia.org/wiki/Intranet on 11th Mar, 2009

Monday, March 9, 2009

Exercise 3: Finding some common ground

Describe the steps involved with the Rapid Evolutionary Prototyping Approach as it applies to developing a Web application.

Steps involved with the Rapid Evolutionary Prototyping Approach (Stytz, Adams, Garcia, Sheasby & Zurita, 1997)
  • Extract requirements
  • Develop prototyping environment
  • Rapid evolutionary prototyping - users can use functional systems to uncover and validate requirements
  • Achieve incremental improvements in system implementation and design
The above recursive steps do until the complete of the project. They can be simple denotation as development iterations in develop, test and evaluate solution.

How is it related to agile development?

Agile development is similar to the rapid evolutionary prototyping approach. Agile development are managing process that encourages frequent inspection and adaptation. Agile allow for rapid delivery of high quality software and a business approach that aligns development with customer needs and company goals. Agile prefer to do things in small increments with minimal planning. Iterations are short time frames which typically last from one to four weeks. the development team work iteration through a full software development cycle.

Reference
  1. Stytz, M.R., Adams, T., Garcia, B., Sheasby, S.M. and Zurita, B. (1997), Rapid prototyping for distributed virtual environments, Software, IEEE, 14(5), 83-92.

Exercise 2: Technology and the evolution of business options

Web quest: Find a range of five sites each offering different business options: online shopping, electronic payments, database access, WAP sites for mobile phones. Key words for your search engine: M-commerce, T-commerce and E-wallet.

Online shopping sites:
Electronic payments sites:
Database access sites:
  1. Bharat Book Bureau - International Market Research Online Database (http://www.bharatbook.com/)
  2. World Book Online (http://www.worldbookonline.com/)
  3. HeinOnline (http://www.heinonline.org/)
  4. Hoovers (http://www.hoovers.com/)
  5. Grolier Online (http://teacher.scholastic.com/products/grolier/)
WAP sites:
  1. Hong Kong Observatory WAP site (http://www.hko.gov.hk/hkowap.htm/)
  2. NBA Mobile (http://wap.nba.com/)
  3. Yahoo! WAP site (http://wap.oa.yahoo.com/)
  4. MLB.com (http://wap.mlb.com/)
  5. Sohu (http://wap.sohu.com/)