Cogito, ergo sum

Here's hoping my musings can help you out!

Archive for August, 2009

Installing Windows 7 (Gateway GT5628)

Posted by mnshankar on August 19, 2009

I just finished doing a fresh install of Windows 7 (X64) on my desktop computer.. Let me tell you, it was quite a struggle! Click here to view the specs of my workstation.

At first, the install process seemed fairly routine.. I restarted the computer after putting in the DVD and booting from it (fresh install). The Win 7 splash screen came up, and I was prompted to select the language. Next, a big “Install” button was displayed on the screen. On clicking the install button, the following cryptic error message was displayed:

“A required CD/DVD drive device driver is missing. If you have a driver floppy disk, CD, DVD, or USB flash drive, please insert it now”

Now, GT5628 uses an IDE/ATAPI Sony DVD/RW drive, and I have not had any problems it.. The message did not make much sense since the install was from the DVD and the drive seemed to boot and load Windows 7 normally.

A Google search took me to this informative site:

http://www.sevenforums.com/drivers/4872-cd-dvd-driver-missing-install.html

I tried all suggested remedies:

  1. Burn another DVD at a slower speed – did not help
  2. Set the jumper on the DVD drive to “Master” – did not help
  3. Replaced the dvd drive with another working IDE drive – Still no luck
  4. Replace the DVD drive with a SATA DVD – THIS IS THE SOLUTION THAT WORKED! It seems to me that the Win 7 installer is unable to work with a system that uses a combination of a SATA hard drive and an ATAPI DVD drive (Microsoft, are you listening?). Strange.. Vista installed on it without any problems!

Once the DVD issue was sorted out, the install process completed quite smoothly. I then put back my IDE DVD drive and it works without any issues.

It feels so much snappier. The boot time (and resume time) are substantially smaller. The graphics and fonts are crisper too. Well worth the struggle!

The second problem that I encountered was due to a missing – “PCI Simple Communications Controller” in the “Device Manager” (All other 64 bit drivers were installed perfectly.. Kudos to Microsoft for bringing 64 bit OS into the mainstream). After a little searching around, I was able to isolate the missing driver to be “Intel® ME: Management Engine Driver“.

The latest version of this driver can be downloaded from the Intel website.

Extract the contents on your hard drive. Launch the “Setup” app. This will immediately throw an error that the operating system is incorrect. Win 7 then automagically detects the correct settings and prompts whether you want to install it using “Compatibility settings”.. Go ahead and click on that option. Watch the “Yellow bang” disappear from the device manager!

I hope my experience with this installation helps you out!

Posted in Computers and Internet | Tagged: , , , , | 6 Comments »

Acer Ferrari 3400 Compatible With Windows 7

Posted by mnshankar on August 15, 2009

Microsoft provides an application to check whether your computer is capable of running Windows 7 without issues. You can download it from here.
 
Hmm.. So, my Acer Ferrari 3400 (that I purchased way back in 2003) is actually Windows 7 ready! Woo hoo.. I might just upgrade to the latest and best version of Windows.. The report generated by the app is pasted below:
 
There are some issues you should take a look at before installing Windows 7.

System Requirements
Upgrade

Backup system first
You’ll need to perform a custom installation of Windows 7 and then reinstall your programs. Make sure to back up your files before you begin. Go online to get important information about installing Windows 7.
CPU speed

2.01 GHz
Your CPU meets the 1 GHz minimum requirement.
RAM

2.00 GB
Your system memory meets the 1 GB requirement for 32-bit Windows 7 and the 2 GB requirement for 64-bit Windows 7.
Hard Drive Free Space

41.47 GB
Your hard disk meets the minimum requirement of 16 GB free space for 32-bit Windows 7 and 20 GB free space for 64-bit Windows 7.
Windows Aero

Capable
Your system can run Windows Aero.
Devices
ATI MOBILITY RADEON 9700
ATI Technologies Inc.

Action recommended
Run Windows Update after installing Windows 7 to make this device compatible.
Realtek AC’97 Audio for VIA (R) Audio Controller
Realtek

Action recommended
Run Windows Update after installing Windows 7 to make this device compatible.
Texas Instruments OHCI Compliant IEEE 1394 Host Controller
Texas Instruments

Compatible
This device is compatible with Windows 7.
Texas Instruments PCI-4510 CardBus Controller
Texas Instruments

Compatible
This device is compatible with Windows 7.
VIA Bus Master IDE Controller
VIA Technologies, Inc.

Compatible
This device is compatible with Windows 7.
VIA Rev 5 or later USB Universal Host Controller
VIA Technologies

Compatible
This device is compatible with Windows 7.
Agere Systems AC’97 Modem
Agere

Compatible
This device is compatible with Windows 7.
VIA USB Enhanced Host Controller
VIA Technologies

Compatible
This device is compatible with Windows 7.
Broadcom NetXtreme Gigabit Ethernet
Broadcom

Compatible
This device is compatible with Windows 7.
WLAN 802.11g mini-PCI Module
Broadcom

Compatible
This device is compatible with Windows 7.
USB Mass Storage Device
Compatible USB storage device

Compatible
This device is compatible with Windows 7.
Programs
McAfee VirusScan Enterprise
version 8.6.0
McAfee, Inc.

Minor issues
You might experience minor issues using this program while running Windows 7. For more information, go online to the manufacturer’s website.
Synaptics Pointing Device Driver

Minor issues
You might experience minor issues using this program while running Windows 7. For more information, go online to the manufacturer’s website.

Posted in Computers and Internet | 3 Comments »

Understanding Zend Captcha

Posted by mnshankar on August 13, 2009

A CAPTCHA image (Completely Automated Public Turing Test to Tell Computers and Humans Apart) is a novel solution to prevent spam. You will find these being used in almost all user registration pages. The most commonly used Captchas are images that look like :

 cap

The logic is quite simple.. Present a randomly generated image to the user and request that it be typed back. After the form is submitted, a check is made whether the text entered by the user matches the actual content of the graphic. If they do match, it is a human!

The rendered graphic should have sufficient noise (lines, dots, curved fonts etc) so that simple OCRs (Optical Character Readers) do not bypass it.

The Zend Framework provides a class named Zend_Captcha_Image that does all the heavy lifting required for captcha implementation. A complete working php file that demonstrates the salient points is listed below (the example has deliberately been kept simple by avoiding MVC/Zend_Form components):

<?php
include_once(“Zend/Captcha/image.php”);
include_once(“Zend/loader.php”);

$captcha=new Zend_Captcha_Image();
$captcha->setWordLen(‘4′)
        ->setHeight(‘60′)
        ->setFont(‘arial.ttf’)
        ->setImgDir(‘captcha’)
        ->setDotNoiseLevel(‘5′)
        ->setLineNoiseLevel(‘5′);

//do this loop if form has been submitted!
if (isset($_POST['captcha']))
{
    if ($captcha->isValid($_POST['captcha']))
    {
        echo “Success!”;
        exit(0);
    }
    else
    {
        //captcha invalid.. redisplay..
        echo “Failed!”;
    }
}
//generate a new image on every loop..note that the location of this statement is important..
//if placed before the if isset command, the captcha check will never result in true!

$captchaId=$captcha->generate();

//display the form..
?>

<form action=”<?php echo $_SERVER['PHP_SELF']?>” method=”post”>
    <p>What does the word below say?</p>
    <img src=”captcha/<?php echo $captchaId?>.png” alt=”captcha”>
    <input type=”text” name=”captcha[input]” />
    <input type=”hidden” value=”<?php echo $captchaId?>” name=”captcha[id]” />
    <input type=”submit” value=”Test me” />
</form>

Yeah.. it really is that simple!

The first two lines include the required Zend library files for use.

The next couple of lines instantiate the Zend_Captcha_Image object. Note that only the setFont() call is required.. All others are optional.

$captcha=new Zend_Captcha_Image();
$captcha->setWordLen(‘4′)
        ->setHeight(‘60′)
        ->setFont(‘arial.ttf’)
        ->setImgDir(‘captcha’)
        ->setDotNoiseLevel(‘5′)
        ->setLineNoiseLevel(‘5′);

setWordLen : Number of characters in the rendered Captcha
setHeight: The height of the graphic
setFont: The font used to render the Captcha (Click here to download and use the Arial true type font)
setImgDir: The image directory where Zend will create the image files (.png). The webserver should have write permissions to this folder
setDotNoiseLevel: The noise generated by random dots in the Captcha
setLineNoiseLevel: The noise generated by random lines in the Captcha

Feel free to play around with these parameters to see the effect they have on the generated captcha image.

The next few lines of code (executed on form submit) does the check using the inbuilt method isValid() on the Captcha object. This function expects as parameter, an array containing

1. The input typed in by the user – captcha['input']
2. The md5 hash of the generated captcha text that is conveniently returned by the generate() call and passed back as a hidden form variable – captcha['id']

The line

$captchaId=$captcha->generate();

accomplishes quite a lot – It is responsible for the following:
1. Generating the captcha image and storing it in the specified image directory. PHP internally uses the gd graphics library to render the image.
2. Storing the “real value” corresponding to the image in a session variable
3. Returning an MD5 hash of the value that is generated. This hash value is used to name both the generated image file and the session variable (and that is why it needs to be passed into the isValid() method so the correct session variable can be queried)

The captcha image is created and stored in the folder specified by the setImgDir() function. The name follows the convention <md5>.png.. So, displaying the captcha to the user is simply a matter of displaying the generated image using an <img src> tag!

Zend_Captcha_Image class automatically deletes old/expired png files from the image directory (for those who don’t take my word for it, check the function _gc() routine in Zend/Captcha/Image.php.. This function is called after the generate() method – A randomization technique is employed to insure that the system does not spend too much time doing cleanup)

Posted in Zend Framework | Tagged: , | 5 Comments »

MySql Stored Procedure Invocation from PHP

Posted by mnshankar on August 8, 2009

MySQL ver 5.0 introduced the concept of stored procedures and functions. It is possible to write stored procedures that take parameters from your PHP script and return corresponding rows from the database.

Here is an example of a stored procedure named emp_proc(dept, fy) that takes the department and fiscal year as parameters and returns the first and last names of all matching employees in the employee table:

 

CREATE  PROCEDURE `emp_proc`(dept varchar(10), fy year)
begin

SELECT
lastname, firstname FROM
employee
WHERE dept =  dept AND fiscal_year=fy;

end;

In the MySQL console, this stored proc can be run using the command:

call emp_proc(‘Finance’,'2009′)

This stored proc can be easily called from a PHP script too.. However, a slight change needs to be made to the Mysql connection to make this happen:

Earlier:

mysql_connect($dbhost, $dbuser, $dbpw);

Modified:

mysql_connect($dbhost, $dbuser, $dbpw,true,65536);

Two new parameters need to added to the mysql_connect statement to facilitate invoking stored procs from the script

‘true’ : signifies open a new connection
65536 : Client_Options flag that needs to be used as the last parameter

The following are ALL possible client options – extracted from the MySQL source code:

#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
#define CLIENT_LONG_FLAG 4 /* Get all column flags */
#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
#define CLIENT_COMPRESS 32 /* Can use compression protocol */
#define CLIENT_ODBC 64 /* Odbc client */
#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
#define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */
#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
#define CLIENT_SSL 2048 /* Switch to SSL after handshake */
#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */
#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
#define CLIENT_MULTI_STATEMENTS 65536 /* Enable/disable multi-stmt support */
#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */
#define CLIENT_REMEMBER_OPTIONS (((ulong) 1) << 31)

Invoking a stored procedure/function from PHP requires the use of the CLIENT_MULTI_STATEMENTS flag.

The final php code that can access the stored procedure is:

<?php
include_once(“config.php”);//all dbconfig parameters go here

mysql_connect($dbhost, $dbuser, $dbpw,true,65536);
mysql_select_db($dbname);

$current_fy = $_POST['year'];
$dept = $_POST['dept'];

//execute sp on mysql.. note the modified mysql_connect to support this..
$select = “call emp_proc(‘$dept’,'$current_fy’)”;
$result = mysql_query ( $select );
while ($row=mysql_fetch_array($result))
{
//process
}
?>

Posted in Database | Tagged: , , , , , , | Leave a Comment »

Portable Software (U3) on my USB

Posted by mnshankar on August 8, 2009

I recently purchased a Sandisk Cruzer Micro (4GB) USB drive. It comes with U3 on it, and I absolutely love this little piece of software! Now, I do realize that it is a windows-only option, proprietary code, yada, yada, yada.. but for my requirements (and a vast majority of you, I’m sure), it is a great fit.

U3 drives are specially formatted and they actually contain a partition that separates the drive into two – A normal storage area, and a read-only part that emulates a CD containing the U3 code. CD emulation (ISO) is used on the partition to ‘trick’ the windows host into launching the ‘autorun’ file and displaying the launchpad GUI.

What this effectively means is that you cannot buy a normal USB drive and force it to run U3 by installing a program. You do have the option of deleting U3 from your drive though.

PortableApps is a competing open-source, free technology and has a similar feature set – Any application built for PortableApps can be very easily converted to be U3 compliant

When you load the U3 drive, it automatically opens the U3 launcher applet (after authentication of course.. another feature that I think is absolutely necessary in a tiny device with a huge potential to fall into the wrong hands). This is what my U3 launcher looks like:

image

 

Over the months, I have collected a bunch of (mostly freeware) programs on my USB drive that I highly recommend:

Please read my earlier post regarding how you can easily make any portable/self contained application U3 compatible.

  1. KeePass 2.08: This is an excellent password management suite. Definitely a must-have if you want to avoid sticking post-its all over your workplace :-)
  2. Pidgin: A free universal chat client. Connects to a whole gamut of talk services. I use it to chat on AIM, Yahoo, Google, and our company XMPP chat.
  3. Irfanview: Awesome, lightweight image editing software. Great for cropping, reducing file size, adjusting brightness/contrast etc. I use this all the time for resizing/resampling images produced by my 10 MP camera into a more manageable 70 KB before emailing :-)
  4. Chrome: Blazing fast Internet browser (loads much faster than FireFox). It has been converted to a portable format by a programmer in Denmark. It also includes an updater that you can use to download the latest and greatest version of Chrome (sweet!). Here is a tip: When you are creating the U3 software using PackageFactory, use IncognitoLoader.exe instead of the ChromeLoader.exe. This will ensure that your drive space is conserved. Chrome has no mechanism for setting a ceiling on the cache size.. So, it can very easily flood your USB drive (Of course you can clear your cache often, but using incognito mode is so much cleaner and easier!). Also, since there is no file caching in incognito mode, browsing speed is noticeably improved.
  5. Windows Live writer: The best blogging software. Period. Seamlessly connects to my WordPress account and helps me create draft blogs offline.
  6. VLC Media player : I have yet to come across a file format that VLC player has refused to play!
  7. uTorrent : Tiny tiny program which does a lot! Prior to using this 600KB program, I was using Azureus, a 50 MB behemoth!
  8. Notepad++: Offers color formatting for most code.. Love the easily extensible plugin architecture (especially HexEditor)
  9. PackageFactory: Easily make apps U3 compatible.
  10. CoreFTP: Full featured light-weight GUI FTP client with support for SSL

If you have any questions regarding any of the U3 apps described above, please drop me a line.

Posted in Computers and Internet | Tagged: , , , , , , , , , , , | Leave a Comment »

Bloom Filter

Posted by mnshankar on August 7, 2009

The Bloom Filter was invented by Burton Bloom in 1970 . The central intent of the algorithm is to answer one seemingly simple question:

“Is needle contained in haystack?”

Hmm.. how about using a linear search, binary search or hash search algorithm you ask ?? Well.. all are valid methods.. but the Bloom Filter stands out in that it is super efficient at answering this question (especially if the set you are searching is really large).

There is another important difference. Most other search data structures store the data elements themselves.. A Bloom filter DOES NOT STORE DATA! This makes it incredibly space efficient. It only stores an array of bits – 0’s and 1’s. One caveat is that the bloom filter might return incorrect answers – also known as a false positives. If needle is present in haystack, it will definitely return ‘true’ .. however, if we query for a non existent element, it might incorrectly return ‘true’. Obviously, for applications that make use of the Bloom filter, that degree of error is acceptable.

Google makes ample use of Bloom Filters.. For example, they are used

  • In Google’s BigTable distributed file system to minimize disk lookups
  • In Google cache routing algorithms for knocking precious milliseconds off their retrieval time
  • In Google Chrome browser for implementing “Safe browsing”

Click here for an informative YouTube video on the Google Tech Talks channel.

Bloom filters basically support two operations:

void bloom_add(“foo”);
bool bloom_contains(“foo”);

Initially, the filter is set to an array of ‘m’ bits (say 20) all initialized to 0 (the actual value of ‘m’ is quite critical to the funtioning of the bloom filter and is dependant on the number of elements in the haystack, and the acceptable degree of errors/false positives)

Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Internally, hash functions are used to map added elements to indices into the filter array. It is important to use high-quality hash functions in the filter to guarantee that output is equally distributed over the entire index space.

Lets say that we use 3 hash functions (h1, h2 and h3) inside our algorithm each of which generates numbers in the range (1..m-1) which is 0 to 19 in our case. There is some math and probability calculation that goes into determining the number of hash passes required and the optimal filter size.. but we can skip that for the purposes of this tutorial.

(From an implementation perspective, note that libraries already exist for generating high quality hash values, and running multiple hash functions simply means using different salts/initialization values in a loop)

Further, let us assume that the following hash values are returned:

h1(“foo”)=5
h2(“foo”)=7
h3(“foo”)=7

Now, the bits at each of these positions/indexes is set to ‘1′ like so:

Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Bitmap 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0

Note : A particular bit may be set to 1 multiple times due to hash collisions (like position 7 above.. both h2 and h3 map into it).. but that is ok.

A query is positive if and only if ALL bits returned by the hash functions are 1. If any of them is 0, then certainly the search term is not contained in the set.

For example, to check the existance of “bar” in our set:
Compute the 3 hashes of “bar”, and say, we get values of 1, 4 and 5. Checking the bit at position 1 in the array, we see that it is a ‘0′. So, “bar” CANNOT be present. We can return with the value “FALSE”.. There is no need to check other bits.

It is easy to see that the probability of false positives is directly proportional to the number of elements that are added to the set – As elements are added to the set, more bits are flipped.. which then makes it more likely that all hashes on a non-existant value will map to cells containing a ‘1′, thus resulting in false positives.. It is therefore imperative to estimate the size of the data set properly during initialization.

Posted in Computers and Internet | Tagged: , | Leave a Comment »

Create Your Own U3 Apps!

Posted by mnshankar on August 6, 2009

It turns out, it is “really-really-ridiculously” easy to create your own U3 applications! The good folks at eure.ca have made available a tiny application named “PackageFactory” that does this magic (free of cost!).

Note that the application you are trying to convert to U3 must be self contained. i.e., It should not depend on the registry and/or be tied to absolute directories. Applications that are built for PortableApps are therefore excellent candidates for conversion to U3.

(Please be aware that you can create a “thinstall” of ANY application.. and then convert the resulting .exe file into a U3p file using PackageFactory!).

Here’s an example of how you can use PackageFactory to create a U3 version of the wildly popular password storage tool KeePass:

1. Download and install PackageFactory

2. Download the Zip package of the latest version of KeePass (ver 2.08 as of this writing) from the KeePass website

3. Extract all the contents of the downloaded zip file into a folder on your computer:

image

4. Launch PackageFactory :

image 

5. Drag and drop the KeePass.exe file from the downloaded folder into the area marked for the purpose on the PackageFactory screen. Add/Edit the Program name and description fields as required, and then click on the “Create” arrow:

image

6. The program then creates a .u3p file and prompts for a location to store the newly created file.. Select your desktop, and hit the “Save” button.

image

7. Click on the U3 icon on your taskbar. Then, click on “Add Programs” and select “Install from my Computer”:

image

8. In the “Open File” dialog box that pops up, select the keepass.u3p file that you created (Step 6)

9. This will create the necessary scaffolding on the portable/USB device for “Keepass” … note that the application is still not ready to launch .. We have not yet added the required support files.

10. Navigate to the System/Apps folder on your U3 device, and locate the folder containing the KeePass.u3p file(This is a hidden folder.. so, you may need to update your folder options to show hidden files). It should look like:

image

11. Copy the remaining KeePass support files from the extracted Zip file into the “Data” subfolder (K:\System\Apps\60F08E21-C250-4FDD-A804-CA25DD2892E2\Data in my case). Finally, the folder should contain ALL the files (and folders) that were present in the Un-Zipped (step 3 above):

image

That’s it! You should now be able to launch KeePass from your U3 Launch applet!

Tip: You can actually convert the PackageFactory application into a U3 file using the same process and keep it handy on your USB device for future projects :-)

Posted in Computers and Internet | Tagged: , , , , , | 1 Comment »

MySQL GUI Client (Windows)

Posted by mnshankar on August 2, 2009

At work, I use MySql on a daily basis. Over the years, I have tried a lot of GUI clients to manage my database effectively:

  1. MySQL Front: Very lightweight. Good for basic databse manipulation operations. Earlier (2005), this was free software.. now, it is shareware. GUI is not very intuitive
  2. MySQL Workbench: From the MYSql stables.. Quite buggy. Holds a lot of promise but still beta quality
  3. HeidiSQL: Good basic functionality.. Free software. Small and lightweight. Perfect for basic functionality.
  4. SQL Yog Community Edition: Very good features.. My second best preference (after Navicat). The query builder on the full version is actually very close to what Microsoft provides for MSSql.
  5. PHPMyEdit (Web based): No GUI coolness.. but accessible from any browser as it is web-based.
  6. Navicat 8.0 (Not free): Easily the best GUI for MySQL that I have laid my hands on!

My vote is for Navicat.. Still not as as good as Microsoft, but by far, one of the most intuitive and feature-complete clients out there:

  • Very windows like – Explorer style with intuitive drag and drop functionality everywhere. There is this little hidden feature to copy a table structure (I use this VERY often). Just drag and drop a table (in the same place or into a different database) and Navicat displays a context menu to copy either the entire table or just the structure! It works great with Vista.
  • Has options for “Queries” and “Reports”.. Now, these are not really database objects.. they are fully managed by Navicat and rendered on the fly (the files are typically stored on your hard drive at C:\Program Files\Navicat for MySQL\Home). Note that “Views” on the other hand are MySQL objects and are stored on the server
  • The table design mode brings up tabs for “Fields”, “Indexes”, “Foreign Keys” and “Triggers”. All options are very well laid out. Adding fields is very easy.
  • Nice StoredProc/Function dialog boxes
  • Very powerful “Import” and “Export” wizards.. It can move an entire MS Access database onto the sql server (and vice-versa). This is a great time-saver.. and it works flawlessly!
  • The query builder is not comparable to Microsoft but it does a decent job
  • Good built in User manager module

Posted in Database | Leave a Comment »