May 31, 2007

Two books read during the weekend turned-out to be pretty good.

The Great Depression

I’ve always wondered about this period of American history when markets collapsed and a period of economic hardships set-in. This book laid out the story how it happened, who were involved and what actions they took to turn the economy around.

the Social Security Act seemed like the poorman’s solution for the poor, to the exclusion of the employers (rich) who were holding much of the economy. A grim reminder that markets left unchecked will lead to this situation. It’s like a universal behavior common to every man, “let’s kick the man while he’s down.”

More proof that markets do not and cannot deal with pessimism, and is not resilient to attacks from speculators or manipulators who wish to gain by any means. Moreover, markets do not have the ability to self-correct using crude tools like supply-and-demand.

The US may have tipped to becoming Red were it not for the methods employed by Roosevelt. The reforms instituted during his first 100 days were socialist in idealogy, except that it had to be re-branded to fit the American mind.

A Global History of Architecture

I’ve never thought human history can be told through the eyes of architecture.

I’m simply led to conclude that man’s belief translate very well to man-made structures, resonating to every piece that is made. The architecture of a civilization clearly show patterns upon which beliefs resonated so well. I found the early history to be entirely dominated by the female goddess, with the exception of Egypt who went with their own brand of theology.


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.


May 16, 2007

Every morning, Sam takes a walk down to the park before turning left at the corner. Sam takes the morning newspaper, clipped under while the left hand holds the coffee. The elevator door opens leading into the company lobby at the 48th floor of the tallest building in town. Carrying a shoulder strap leather bag, he places it on top of a wooden table, plugs the cable to the ethernet, flips the cover before touching the On button. The screen opens up with a splash screen showing an image of a penguin with a logo at the bottom–Linux.

Sam is not alone, he is only just one of the many who use Linux as their primary environment. He is joined by his officemates who run standard OEM machines provided by several companies. The Chief Technology Officer also carry a notebook loaded with Linux.

“All of our notebooks here run Linux,” Sam said. “A lot of our applications run natively on several hardware configurations, although we still use other OS for legacy applications such as Windows and MacOS,” added Sam.

It wasn’t long ago, thirty years to be exact when computing was done on a different level. The economics of software development were different, a product of a system that has long been replaced by a new paradigm. “My parents told me they used to pay a lot and they bought in pieces,” Sam said. “At that time, before the great correction, my parents had to endure a lot from creating programs that may infringe. They fought hard against those who seek to subvert the true essence of the law and they won,” added Sam.

Sam and his company are now enjoying the fruits of those who fought for freedom. It wasn’t because they believe the old regime will stay the same, they believed on the idea that they could be free to use and share the works they produced. A new culture emerged from it and is now considered the majority culture.

Adobe Flex Development On Ubuntu Linux

May 13, 2007

Adobe Flex is an API that works in tandem with Flash 9 player, is available as an SDK. There is a free version of the SDK that allows you to develop Flex applications. You can get the SDK from the download section and install it in your development directory. The SDK contain two sets of development tools that target two platforms: Linux and Windows. You can code and test in Windows or choose a flavor of Linux, remember to simply run the appropriate compiler to get the output file generated.

If you’re interested to know more about setting-up a Flex development environment in Linux, please read-on as I’ll document the steps needed to get you up-and-running.

From here on, you’ll be seeing concrete examples that might confuse you if you’re not familiar with what I’m describing. For example, Ubuntu will be used as a reference OS and that might confuse non-Ubuntu developers. If that’s the case, you can still follow-through and try to relate them to your familiar environment.

Let’s start with what tools are needed to setup the environment.

  1. Ubuntu 7
  2. Adobe Flex SDK (free version)
  3. Java JRE
  4. Firefox

We’re now ready to assemble the parts. Here we go.


I chose Ubuntu as a reference for this article. The reason behind for choosing Ubuntu is a subjective one and I’m not going to go there explaining why. This is one of the benefits of having to participate in Freedom Culture.

I’ve set up the latest version known as Feisty Fawn and you can get a free copy from , download a copy and install, you should be OK to follow the next step.

Flex SDK

The free version of Flex SDKis available from Adobe Flex Download. Download the package and install it in your development directory.

  1. Click download to start download.
  2. Save package in ~/Packages.
  3. Expand downloaded package in ~/Packages/flex
  4. For every file add the following text shown in the code box.
  5. That’s it.

Setting the path to Java JRE instead of the default Java that came with Ubuntu.

#code box
export JAVA_HOME=~/Packages/jre
export PATH=$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

If this approach doesn’t appeal to you, there is another method you can do and that is simply add the setting to ~/.bashrc instead.
Java JRE

Java developers may find this one optional as they already have Java JRE installed. In my case, I don’t code Java so I had to download the JRE from, that’s definitely an extra step. One thing I found out when I was testing the sample files, the Java that came installed in Ubuntu didn’t work, that’s why you need to get a working version for Flex SDK.

  1. Download Java JRE from
  2. Install in ~/Packages/jre/

At this point, you can now compile the sample files located in ~/Packages/flex/samples/ directory. Simply navigate to the directory and run the shell script and you’ll see the output files with the extension .swf, you can drop the swf file onto a browser and it will render once it gets loaded.


This is the last step to get you going. Flex is browser dependent and mostly all testing will be done using a browser. In Ubuntu’s case, the Firefox browser is already installed and accessible from the desktop toolbar.


At this point, your Flex development environment is already set up. And if you count how much they cost to get these tools installed you will be surprised they are free as in beer.

Thanks for reading if you’ve reach this far.

Addendum: by the way, check out the Flex SDK website for more information on developing applications using the Flex SDK

GTK WebCore

May 12, 2007

GTK-WebCore, a project about porting Apple WebKit to GTK is now up-and-running on my Ubuntu 7 wobbly desktop.

The codebase is still small compared to Moz and others, although the current trunk does not have all the features needed to make it feature-compatible.


Anyway, the codebase is now building on my devel box which is a really a big task by itself, setting-up the dependencies in order to get the trunk compiling.

First Class Browser Elements

This is really not an issue and it is best handled by standards what features go where, and stuff like when these features go marching-in into the code. I’m all for that simply because it creates a stable condition.

That’s probably why we have these projects like gtk-webcore. Innovators or simply those with so much time on their hands could play with outrageous concepts like making some objects first class browser elements.

The implications for those who grok these concepts are wide-ranging. You, my dear reader will probably nod in agreement how cool these ideas are, there is no doubt about it, gtk-webcore does have that potential to provide a big playground, a fertile ground for innovators to play in.

First class elements are basically protected by a standard. Imagine the chaos of not having a standard on how elements get rendered, it would not become a platform for users, though.

There is a need to have a balance between those who add elements to the browser and the ones who protect them. The process alone may not look like a walk-in-the-park, but the resulting product based on a moving standard could benefit a lot.

Markov, Search, Mo’ Testing

May 11, 2007

I finally got reconnected to a random blogger who I once blogged about several years ago. The last entry made was in 2004 and I thought he decided to walk away and quit. Not that I know this person really well, he seemed to be happy living a retired life outside the country. Adjusted to the economic and social conditions that he wrote about that time. And so I wondered if he was still out there blogging, interpreting the things around him according to his own philosophical views. I tried Google without luck, using his nickname didn’t return anything except his old blogsite. I tried running his text through the Markov Chain algorithm to see what words stood out from the pack, then used that to query the net. Nothing returned. So I finally gave up the search and decided to just send him an email. It was a shot in the dark, “maybe this guy is already dead?” I asked. I got a reply from him saying he has a new blogsite up and running since 2004. So I scratched my head again, sat down and started figuring out what went wrong in the attempt to use Markov Chain along with other algorithms to track him down. Now that I got reconnected, it’ll be nice to read about his opinions. Maybe use his work to refine this simple application I’m trying to complete.

Midrange Setup Using PC Thin Clients

In the olden days, the big iron was the only game and IBM supplied these monsters. On the other hand, Unix came in midrange sizes sporting a nice little OS. I remember it took me quite a while to figure out crontab, though. I’m sure the programmer who wrote that was stoned. With just the a little man page, that was all it was about to carry out the task. Talk about being macho with a man-page was not what I would consider fun.

Looking back, it would probably be nice to have to re-create that environment I once worked-in, a throw-back in the days of the old AT&T SVR4 environment by putting together a bunch of old PCs as thin clients connected to an Ubuntu server. I heard the LTSP project are into this kind of stuff so I’ll head over there and look for more info. At the moment, the current setup are desktops connected to a hub.

Desktop Webservice

It looks like the idea of implementing a webservice specifically for a desktop could become a hit. I really like the idea of having to connect to a desktop as if it is like another website with a webservice. A new level of simplification was achieved, factoring out the differences and only taking the common parts really made sense. Another interesting piece was putting Avahi to work alongside the webservice. The implications of these two working together could mean more toys to play with.


Nice, I just got my first dive into GEGL on the Edgy distro.