Download DB2 Upgrade DB2

Some Facebook Network Stats

August 30th, 2007 by Leons Petrazickis

I’m part of three Facebook networks, and I’ve been keeping track of their size since May of this year.

Facebook network size stats

Toronto has gone from 600k people in May to 800k people in September. That’s 32% of the municipality or 16% of the metropolitan area, which is an impressive proportion.

University of Toronto has been stable at 55k, but there should be a flurry of new users in September when first-year students get their UofT email addresses.

The population of IBMers on Facebook has actually declined. Conversely, I suspect our population on LinkedIn, a career-oriented networking site, has not.

Posted in facebook | No Comments »

Array structure and virtual memory optimization

August 28th, 2007 by Leons Petrazickis

(This applies to Java and C, but the code is given in Python for readability.)

Is it faster to iterate over multiple separate arrays (tuples) of simple variables?

for i in range(0, n):
	phone = phones[i];
	# ...
	email = emails[i];

Or over a single array of complex variables?

for i in range(0, n):
	phone = people[i].phone;
	# ...
	email = people[i].email;

One array is faster than multiple arrays. This is because an array is stored in a contiguous block of memory. Accessing data in different arrays at the same time can require several different pages to be loaded from virtual memory. Memory access, especially hard drive access, is slow. As your application and data set grows, a significant performance difference may manifest itself.

Arrays from the Second Dimension

When iterating over a multidimensional array with indexes i and j, is it faster to iterate over j inside i?

for i in range(0, n):
	for j in range(0, m):
		cell = cells[i][j];

Or over i inside j?

for j in range(0, m):
	for i in range(0, n):
		cell = cells[i][j];

In Java and C, a multidimensional array[n][m] is stored as contiguous m-block of contiguous n-blocks. Let i be in n and j be in m. For a given i-cell, j-cells will be far apart. For a given j-cell, i-cells will be adjacent. Accessing adjacent values in memory is always faster.

For an array[i][j], putting j in the outer loop and i in the inner loop will significantly reduce potential virtual memory slowdowns.

This is the right way:

for j in range(0, m):
	for i in range(0, n):
		cell = cells[i][j];

The above only makes a difference with large data sets, but I like to cultivate good habits.

Posted in java, c, python | 3 Comments »

Creating Start Menu Shortcuts with Javascript

August 14th, 2007 by Leons Petrazickis

While preparing the installer for the Web 2.0 Starter Toolkit for IBM DB2, I had to set up Start Menu shortcuts. The way to do that is to work through the Windows Scripting Host (WSH).

The WSH supports two built-in languages – VBScript and Jscript – and a theoretical number of third-party alternatives. VBScript is the better documented of the two in terms of examples, but I find its syntax ugly and constrained. Fortunately, Jscript can do anything VBScript can.

So here’s how we can create Start Menu shortcuts with Javascript.

Locate the Start Menu Programs folder

Most interesting Windows folders can be found by working with special folders

var shell = new ActiveXObject("WScript.Shell");
var startmenu = shell.SpecialFolders("Programs");
 

The shell object will be reused in code below, but you can redeclare it every time if you like.

Create a Folder

Scripting Guy has more details

var folder = "My App";
var group = startmenu + "\\" + name;

var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FolderExists(folder)) fso.CreateFolder(folder);
 

startmenu is defined above.

Create an LNK Shortcut

The very hidden file extension of standard Windows shortcuts is LNK. This distinguishes them from website shortcuts, which have the equally hidden extension of URL.

If you are interested in something closer to the symbolic links of Unix, the NTFS equivalent is called junctions. You may find Junction Link Magic of interest.

var name = "My Shortcut";
var file = "myfile.txt";
var path = "C:\\Program Files";

var shortcut = shell.CreateShortcut(group + "\\" + name + ".lnk");
shortcut.TargetPath = path + "\\" + file;
shortcut.WorkingDirectory = path;
shortcut.Save();
 

See the full list of properties. I recommend always setting the working directory for application links. If you don’t, your program won’t be able to load resources from it’s installation folder.

shell and group are defined above.

Create a URL Shortcut

This is very similar. The main difference is that you set the extension to URL.

var name2 = "My Other Shortcut";
var address = "http://example.org/";

var shortcut = shell.CreateShortcut(group + "\\" + name2 +".url");
shortcut.TargetPath = address;
shortcut.Save();
 

See the full list of properties.

shell and group are defined above.

Locate Program Files

When creating shortcuts, it is often useful to know where a user’s Program Files directory is located. It is called different things in different versions of Windows, and some advanced users like to move it or rename it.

var REG_PF = "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ProgramFilesDir";

var progFiles = null;
var process = shell.Environment("PROCESS");
if (process)
        progFiles = process("ProgramFiles");
if (!progFiles)
        progFiles = shell.RegRead(REG_PF);
 

shell is defined in the first code excerpt.

Posted in javascript, windows | No Comments »

Behold, the Web 2.0 Starter Toolkit for DB2!

August 9th, 2007 by Leons Petrazickis

The Starter Toolkit is an easy way to deploy a WAD-on-PHP stack – Windows Apache DB2 PHP. It includes some neat functionality for generating Atom feeds from XML data in your DB2 databases, and some excellent REST-ful web service wrappers from tables and stored procedures.

I’ve spent my last few months tinkering with it, so do take a look. There should be a few posts about it coming down the line, from both external and internal perspectives.
Install Apache, DB2, PHP, and lots of goodiesControl Panel MenuCreate Atom FeedsCreate REST-ful PHP web services
How is it different from Zend Core for IBM? Well, the toolkit has the Atom stuff, and the web services stuff, and a bunch of helpful resources to help folks get started making apps full of Web 2.0-ey goodness.

We’ll be pushing out a fresh revision in double-time, so give me some feedback, consarnit!:-)

Posted in javascript, php, db2 | 1 Comment »