Sorting MySQL rows using column values

Posted in mysql | Posted on 25-07-2008

In MySQL it is easy to sort rows by using the ORDER BY clause on the column name. Recently on a client request the sort had to be done using the column values rather than the name. Since I had never come across sorting using values, a couple of minutes of searching was in order; You can do the ordering by using the ‘field’ function like in the below example.

Why clients want software developed cheap.

Posted in general | Posted on 16-07-2008

railsA couple of weeks back I was asked by a client to quote for a 25 page ecommerce website. After looking at his requirements I quoted him $450, which is quite low by any standards. The client called me with a surprised tone in his voice and told me that in that amount he would be able to buy a new computer and he was willing to pay me not more than $200 for the same. This is not an isolated case, but one from a dozen or so client interactions. I don’t want to imply that the clients are cheap; all of the clients I have dealt with are very good business people. Its just that they don’t know the value of software; and one of the main reasons for that is piracy.

hasta la vista MIR

Posted in books | Posted on 10-07-2008

Yesterday while rummaging through my library I came across a little gem - On the way to Super Elements by G.N. Flerov, A.S .Ilynov - Mir Publishers Moscow. A wonderful book by the now defunct Mir publishers. This is one of the several books from Mir that I have treasured in my library. These books were responsible, in no small part, for my intellectual growth and my affaire d’amour with science books.

But these excellent books however have become an unfortunate casualty of the fall of the former Soviet Union. Not only were the books excellent in themselves but the prices were ridiculously cheap, especially during my college years, when a limited amount of money was fated to satisfy my various youthful desires - at about USD 0.25 you could get a hardcover book of 100 pages with multi-colored graphics.

Luhn algorithm for validating credit cards

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?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;
}
 
?>

Linked List implementation in PHP

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.