Posted in algorithms, php | Posted on 09-07-2008
The Luhn algorithm also known as the “modulus 10″ or “mod 10″ algorithm, is a checksum formula which can be used to validate credit card numbers. Developed in the 1950’s by IBM scientist Hans Peter Luhn and described in U.S. Patent 2,950,048. A PHP implementation is shown below.
<?php
function LuhnCheck($strDigits)
{
$sum = 0;
$alt = false;
for($i = strlen($strDigits) - 1; $i >= 0; $i--)
{
if($alt)
{
$temp = $strDigits[$i];
$temp *= 2;
$strDigits[$i] = ($temp > 9) ? $temp = $temp - 9 : $temp;
}
$sum += $strDigits[$i];
$alt = !$alt;
}
return $sum % 10 == 0;
}
?> |
Posted in algorithms, php | Posted on 24-06-2008
Data structures are one of the core elements of computer science and they are also fun to program. But being a web developer the opportunity for implementing them in any application is quite rare. But then I thought, What the heck! I can just code for the joy of it, and it will also help me brush up on my DS skills. So here it is, a single linked list implementation in PHP for whoever may care. I will be posting other data structure and algorithm implementations here, so keeping watching. The code is given below.
Read the rest of this entry »
Posted in php, tools | Posted on 24-06-2008
Code tuning is an essential part of programming. But most programmers would rather try to complete the project in hand then spend time optimizing a piece of code. A well tuned and optimized code block can speedup your application by an order of magnitude or even more.
Many people confuse profiling with benchmarking. A profiler is a analysis tool that lets you measure the performance of code at runtime. Profiling an application lets you find bottlenecks in your application code. You can find which part of your code is taking most of the time, you can than optimize that part of code. For example if there are 4 functions in your application, profiling may report the following distribution:
Read the rest of this entry »
Posted in php, visualization | Posted on 13-05-2008
ClickHeat is a wonderful PHP software that lets you add Heatmaps for your webpages. Heatmaps are visual representation of clicks on a HTML page, showing hot and cold click zones. It can be useful to see at a glance which webpage areas are getting the most clicks as this areas get redder in color while the areas receiving less clicks are white. The software has many options to tweak, and the heatmaps can be added on a per page basis.
A sample heatmap image is shown below. You can also use the clickheat class in your own PHP applications. The software doesn’t require any database, only GD graphics library must be enabled on the server, which in most cases already is.
You can view a heatmap for the index page for this site here. I’ve presently only added click log for the index page, so try clicking on the index page links to update the heatmap.
username : visitor
password: visitor
If you don’t see any changes in the heatmap, click on the “log my clicks” link in the right corner or try logging out and then logging in again.

Posted in php | Posted on 09-05-2008
The graphic below displays the market share of each PHP version as on march 2008. The blue graph represents the sum of all preceding versions.
PHP 5.2.5 now is the most popular version of PHP followed closely by PHP 4.4.8 and 4.4.7. This information can be helpful if you are planning on creating an Open source project or are thinking of moving past the version 4 mark in your professional career but are hesitant regarding the version 5 support on servers. Read the rest of this entry »