November 28, 2007

Finding a solution to a social problem, specifically human behavior can be trivial, yet so obscure at the same time. The solution is not derived via quantitative means alone, perhaps it has something to do with how consumers define utility.

And so I continued my search to define what is utility in terms of our product line. Is it the product itself that consumers buy, or is it satisfaction derived from the use of our products define what utility is? If it is true, then how do I connect the dots in such a way the messaging is always in tune to its utility?

3D Game

After painfully emerging from the great unknown in figuring out the latest-n-greatest GPU shaders, it seems that the next exercise would be to mimic a commercial released 3D game, simple enough to do yet not too easy to be considered nihil. New shader features implementing skin shading via subsurface scattering and cloth shading, another is hair shading where hair is affected by several forces acting on it.

Two gametypes came up right away, the first was Taekwondo (TKD), the way of fast kick and punch, made a good impression. Modeling the terrain is simple, a scene having a place where two opponents fight. The actor having several animated sequences, often derived from standard Taekwondo forms. The objective is to implement said features to an actor with proper skin shading, good enough to render realistic skin showing the oily (sweaty) part of skin. Facial expressions are tackled as well, making sure the proper vertices are shaded to show the correct expression. Cloth shading referring to the kimono (Grandmaster Uniform) should show cloth tension and gravity. The mechanics of hair will also be studied and implemented if possible, yes hair mechanics is hard.

The second gametype is to basically resurrect my favorite Apple II game that we played, known as Karateka. This is basically a fallback of the first, in the case TKD turns out to be complicated.


Flex + Webservices

November 5, 2007

In this article, we will look into the following:

  1. How do I write code for handling data from a webservice.
  2. What attributes would I need to be familiar about to setup the connections.

Now that we know what to do, let’s get moving to the next. Before that, we need to know what things are needed to be ready in order to proceed. First, we need to have an already fully coded Webservice running on a website. In this example, we are using Localhost domain, or simply the development machine as the Webservice source. And the filename of that Webservice is called student.asmx.

For this article, we will not be covering the details of student.asmx, as it is another set of technology requiring another article, so we’ll just leave that for now, treat it like a blackbox and only send and receive data from it.

The Login User Interface

Let’s write a login panel for our students. To be validated as a student, a user has to present credential to the login webservice by simply entering the Login Name and Password. The UI panel collects them and sends them over the wire to the webservice. The Webservice receives the credential and checks to see if it is a valid credential. Once validated, it returns the student record to the client login panel.

In the figure above, a graphical representation of the login panel have two input boxes for entering login ID and password, followed by the login button. The user enters data to the input boxes and later presses the login button to send the data to the server.

At the source code level, the xml declaration counterpart is shown below. You’ll see in full detail the attributes of the elements like the panel, input boxes, buttons and labels. Notice the login button has an attribute named click with a value of saveData() which is a symbol for a function name for handling the click event.

The click event handler for the button is shown below, saveData() calls the send() method found in studentWS, a webservice that does all the work of sending the data to the webservice and receiving the data back from the webservice. In this case, studentWS is the webservice, while studentLogin is the function declared inside the webservice, send is a method foe initiating the event.

At this point, you have a pretty good idea of setting up a graphical panel and the corresponding xml declaration. You also now know how to setup the send() event and where to attach it, the click attribute of the button.

The Webservice Tag

Pro Bono On The Accounting Side…

October 10, 2007

Maintaining a site for keeping lecture notes and solutions to exercises and problems takes about eight to twelve hours a week. That’s because a lot of new pages need to be set up,  prepped for the first time. It could could go down to eight hours a week as things move forward.

In tandem with maintenance, I’ve also set up a database backend specifically for the exercises. What this basically means is I’ve partially created a database-backend app with a web front-end for automating some of the accounting procedures. It’s not up-and-running yet, but it will be ready in the coming week or two.

I’ll open this project to the public once it is ready. This one is going to be Pro-Bono (free) as this will greatly help me in my studies, going forward. So, if you want a free-ride on your accounting system, especially if you’re a mom-and-pop store, a team-operating-on-a-dime, or even a smallbiz who wants to save that penny. My suggestion is to get on this project once it is ready.

I’ll take care of the nut-and-bolts, you basically plug-in the numbers and run reports. That’s basically the deal. It’s as easy as any accounting firm, except this one is free.

Send me an email, if you’re curious enough to know what’s going-on behind this weblog, though.

 OK, see you later.

Crunch Time

September 7, 2007


We passed the crunch and somehow glad to know I’m still in one piece. The experience we went through was highly intense, enough to sink the entire ship. But, at the end of the day, we finally broke through the thick fog to finish and deliver the code–ON TIME! 

I really would like to write the details, the intense emotions of my teammates. That experience probably showed a lot of how we worked as a team. But I’m not really good at describing intense emotional moments, the thought of not getting it right in time for QA and demo.

One quality or trait required to pull this through is this thing called optimism, you have to have a lot of it, no matter how grave or impossible the situation is, you have to believe you will make it.

Man, I wish that was the last we will ever do.

I wish there is a way of not going through crunch time.

Maybe it’s part of the culture?

Wait until crunch time, then work like hell to finish the job.

What do I know, this practice has been going on since forever.  All I know is the code gets completed and delivered during crunch time.

Adding Performance Counter Code Into Your MSSQL Stored Procedure

May 24, 2007

Collecting information about performance data can be done in many ways. although one of the methods I often use is simply put the code in the body and let that code extract the numbers for me.

The code shown below contain the necessary statements needed to extract a number of seconds it take to run the procedure from line 06 to line 08. In the next paragraph, these lines of code will be explained in detail.

01  CREATE PROCEDURE sp_sample_stored_proc_01 AS
03	declare @start_time float
04	declare @end_time float
05	declare @elapsed_time float
06	select @start_time = @@CPU_BUSY * cast(@@TIMETICKS as float)
07      -- your normal routine code goes here.
08	set @end_time = @@CPU_BUSY * cast(@@TIMETICKS as float)
09	set @elapsed_time =  (@end_time - @start_time) / 1000000
10  END

Lines 01, 02, 10

The syntax for defining a stored procedure is shown in lines 01, 02 and 10. In this example, the name of the procedure get declared as sp_sample_stored_proc_01, having no parameter definition. While lines 02 and 10 define the body of the procedure.

01  CREATE PROCEDURE sp_sample_stored_proc_01 AS
     o  o  o
10  END

Lines 03, 04, 05

@start_time, @end_time and @elapsed_time are names or labels used to store values needed to calculate the elapsed time. And they are declared using the following syntax:

03	declare @start_time float
04	declare @end_time float
05	declare @elapsed_time float

Lines 06, 08, 09

When execution reaches line 06, it takes a snapshot of two system values contained in two system variables named: @@CPU_BUSY and @@TIMETICKS. An expression is evaluated before storing the result in @start_time

06	select @start_time = @@CPU_BUSY * cast(@@TIMETICKS as float)

The execution path goes on until it reaches line 08, which then takes another snapshot of two system values; calculates the expression and stores the result in @end_time.

08	set @end_time = @@CPU_BUSY * cast(@@TIMETICKS as float)

At this point, the procedure is almost finished and will jump out of its execution frame. But before jumping out, it calculates the expression defined in line 09.

09	set @elapsed_time =  (@end_time - @start_time) / 1000000

@elapsed_time contains a value of how much time it took to run the lines of code from line 06 to 08.


You can extend the code so that it saves @elapsed_time to a logfile.

MySQL 5.0 Stored Procedure Programming Tutorial

May 23, 2007

MySQL Stored Procedure is a new feature release in version 5.0, positioning the database a step closer in features to the leading database products. In this article, you’ll be guided on how stored procedures are created using several tools described below.

Before we start the tutorial, let’s have a quick check on the tools you will need. Listed below are the following you can download from the Web. Also, the code used in this tutorial were tested by these tools, and your results may vary depending on how close or far you are from the tools mentioned below.

The article assume you already have the tools installed and you are now ready to follow the steps. However, you can still follow and learn what makes sense if you are running a different copy of Linux or a different MySQL Administrator version.

What this article will show you are the following steps:

  1. Create a new schema.
  2. Create a new table.
  3. Create a new stored procedure.
  4. Testing the stored procedure.

Create A New Schema

Launch MySQL Administrator from Applications-> Programming-> MySQL Administrator, then select View from the menu bar. The View menu appears, now select Catalogs from the list. You’ll see a list show at the bottom left of the panel. Right click on that list and select Create Schema. A dialog box appears containing a textbox for entering the schema name. Enter a name in the textbox and click the OK button.

Create A New Table

This step will create a new table. Select the newly created schema from the schema list located at the lower left part of the panel. You’ll see five buttons at the lower part, select Create Table. The table editor dialog box shows up, from there you can start naming the table and also add the columns as well. Use the table definition below to populate the dialog box. Click Apply Changes to save and create the table.

CREATE TABLE `mmorpg_users` (
  `ID` bigint(20) unsigned NOT NULL auto_increment,
  `user_login` varchar(60) NOT NULL default '',
  `user_pass` varchar(64) NOT NULL default '',
  `user_nicename` varchar(50) NOT NULL default '',
  `user_email` varchar(100) default NULL,
  `user_url` varchar(100) default NULL,
  `user_registered` datetime NOT NULL default '0000-00-00 00:00:00',
  `user_activation_key` varchar(60) default NULL,
  `user_status` int(11) NOT NULL default '0',
  `display_name` varchar(250) default NULL,
  `latest_ping` datetime default NULL,
  KEY `user_login_key` (`user_login`)

Create A New Stored Procedure

There are four tabs at the top part of the form. Select the Stored Procedures tab to open the list. Click the Add Procedure button and a routine name dialog box will show up, enter the name of the procedure and select OK. At this point, you can simply copy-and-paste the stored procedure code shown below. Click Execute button to commit the code.

CREATE DEFINER=`root`@`localhost`
    PROCEDURE `setUser`(OUT _id int, _uid varchar(60),
                                         _pwd varchar(64), _nm varchar(50),
                                          OUT _retcode int)
	declare _cnt int;
	declare _errno int;
	set _retcode = 0;
	case _id
		when 0 then
			select count(*) into _cnt from mmorpg_users
				where user_login = _uid;
			if _cnt = 0 then
					insert into mmorpg_users (user_login, user_pass, user_nicename)
						values (_uid, _pwd, _nm);
					select last_insert_id() into _id;
					set _retcode = 1;
					select ID into _id from mmorpg_users
						where user_login = _uid;
			end if;
			update mmorpg_users
				set 	user_login = _uid,
					user_pass = _pwd ,
					user_nicename = _nm
			where ID = _id;
	end case;
	select * from mmorpg_users where ID = _id;

Testing The Stored Procedure

At this point, you are now going to test the stored procedure. Open the Terminal program from Applications->Accessories->Terminal. Run mysql with the following:

desktop:~$ mysql -u root

Then enter the following text inside mysql.

mysql> call setUser(@id, 'John', 'btd19x', 'redball', @retcode);


This is just one sample implementation of a MySQL stored procedure, walking you through the steps. With these tools, you can now expand to even create more procedures for your own applications. Perhaps even write sophisticated ones as well.