A Mathematical Captcha – Reinventing the Wheel

I had seen numeric computational captcha or Mathematical captcha where one has to calculate the answer of an equation with simple arithmetic and supply the result for verification.

For a long time I have been using the image captcha with random characters, and got fed up. I had seen numeric computational captcha or Mathematical captcha where one has to calculate the answer of an equation with simple arithmetic and supply the result for verification. Last night I was pondering over this while watching a movie on the TV. Well the out come is obvious.
Continue reading “A Mathematical Captcha – Reinventing the Wheel”

Getting datetime type into JavaScript as Date object

When selecting datetime to be displayed in a JavaScript ui library, select the unix_timestamp * 1000 from the sql

This is not any new thing and may be discussed at different other places. But just as I came across like any other things, I just wanted to make a record of this.

When selecting datetime to be displayed in a JavaScript ui library, select the unix_timestamp * 1000 from the sql.
Continue reading “Getting datetime type into JavaScript as Date object”

Migration from MySQL to MSSQL – Quick Tip

With the help of some colleagues, I could export all the indexes and primary keys, which we were using from a MySQL table as MSSQL compatiable TSQL using a union query and on the MySQL information_schema.

With the help of some colleagues, I could export all the indexes and primary keys, which we were using from a MySQL table as MSSQL compatiable TSQL using a union query and on the MySQL information_schema.

I did the migration to MSSQL using some tips found online, and calling a sp after connecting directly with the MySQL server. Actually forgot how it was done. Anyway it does not matter in this post. Will add it as a comment later on. The important matter was that, the method did not import any of the indexes, or primary keys. We manually created those were absolutely necessary to roll out the project. And now that we were about to release a service patch, and this includes more incredible search methods, the indexes are absolutely necessary.
Continue reading “Migration from MySQL to MSSQL – Quick Tip”

Quick and dirty htaccess rewrite for Lighttpd

Writing this post and am getting ready to hide behind strong walls, since mostly lighttpd is meant to fly light, or serve faster without the bloat and dynamic flexibilities. But certain situations may occur where one may have to forget the religion and behave sensibly. For a major project which was collaborated by different teams of our spread out offices, one part was developed by a team who were more exposed to benefitting the furls (friendly urls), by using apache rewrites. The bang off was detected only at the last moment of roll out to the beta deployment at client environment.
Continue reading “Quick and dirty htaccess rewrite for Lighttpd”

Posting to wordpress using php cli and xmlrpc

A reader once asked me if I could build a command line tool which takes title from one file, and content from another file to create wordpress post. I tried, which finally gave an outline to this script. I dont think that this is very high fly, but for those whom the xmlrpc is mumbo, this might be somthing worth looking into.
Continue reading “Posting to wordpress using php cli and xmlrpc”

Short PHP twitter-counter

While strolling around I found some bits and pieces which I put together to get a short twitter counter in php.

<?php
ob_start
();
 
$json file_get_contents("https://twitter.com/statuses/user_timeline/php_trivandrum.json?count=1");
$data json_decode($jsontrue);
ob_get_clean();
 
echo 
$data[0]['user']['followers_count']; 
?>

Nothing more to write now..

Importance of event logging in server side scripting

Now a days script driven web applications are getting more and more complicated with background operations and triggered events. Debugging or event tracking is tough once the application is moved into production. Fresh and aspiring programmers are always too cautious to wade into deeper waters, and always go with line by line testing. Almost always in the course of debugging or code optimizations I see a lot of them using file_put_contents or echo to check variables at a particular point of execution.

I always gave the pressure to use a good logging system from the start itself, and to add level based message logging with debug_backtrace wherever needed. The most recent class abstraction for php programmers which is being used in our custom framework is attached to the downloads here. The file logging is being done after serializing, compressing and base64_encoding to keep logs in single lines, and to make sure they dont take up too much of the space.
Continue reading “Importance of event logging in server side scripting”

function array_flatten

This is not much to brag about, still we had a very large dataset as variable dimensional and variable depth, which we wanted to be sent to a custom function using prototype.js. For the data exchange we use JSON, but the varying depth and related tags, made us to do like hell in the javascript templating that we had to find a method to flatten the array in such a way that each of the associative keys would not be mangled.

The final out come is function array_flatten


function array_flatten($p, $ki = ''){
    if($ki !== '') $ki .= '-';
    $rv = array();
    foreach($p as $k => $v){
        if(is_array($v))
            $rv = array_merge($rv, array_flatten($v, $ki.$k));
        else
            $rv[$ki . $k] = $v;
    }
    return $rv;
}

The flattened dataset, helped us to do rendering in less than half the iterations, and the application response was more better after using this.