Sunday, December 26, 2010

Get today's date mysql

"SELECT * FROM netl_hiscores WHERE DATE(scoreDateTime) = DATE(NOW())";

Tuesday, December 14, 2010

Weird floating DIVs

If you run into problems with div floating on the side of another div despite having clear seperators, then you need to inform the browser to 'stop' floating.. using the following command.

<div style="clear: both;"> </div>

Monday, October 25, 2010

Haversine Formula Calculation between two points

seems like safari does not support torad() function of javascript.

function getDistance(lat1, lon1, lat2, lon2) {

var R = 6371; // km
var dLat = (lat2-lat1) * Math.PI / 180;
var dLon = (lon2-lon1) * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;

return d.toFixed(2);
}

Friday, October 1, 2010

mysqldump and restore

mysqldump -u [uname] -p [dbname] > bak.sql

mysql -u [uname] -p [dbname] < [bak.sql]

Friday, September 17, 2010

format base strip sscanf php

function stripCurrency($input) {

$input = str_replace(",","",$input);
$input = str_replace("$","",$input);

return $input;
}

function stripRoadTax($input) {

$input = str_replace(",","",$input);
$input = str_replace("$","",$input);
list($val) = sscanf($input, "%d per year");

return $val;
}

function stripMileage($input) {

$input = str_replace(",","",$input);
list($val) = sscanf($input, "%d km");

return $val;
}

mysql php installation errors server 2008 zlib.dll

When IIS is complaining about a missing DLL file either a zlib.dll or oci.dll, chances are soemthing is wrong with the msi file, disable some of the extensions and try to install again, as long as php-cgi.exe runs properly, the program should work.

after ensuring that php works, follow the insturctions to edit the php.ini file to point to the correct fastcgi settings.
http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-7/

I installed PHP on C:\PHP and not within program files directory mainly because of the space.

lastly, take note of the appliaction pool, the manage pipeline mode should be integrated and the "enable 32 bit applications" setting should be set to true.

Wednesday, September 8, 2010

Performance xpath->query vs dom->getElementsByTagName

xpath works much faster, with speed of over 3 times faster compared to that of doing normal traversal using DOM.

// dom method
$xpath = new DOMXPath($dom);
$nodes = $dom->getElementsByTagName('td');
foreach($nodes as $node) {

if($node->nodeName == 'td'){

$inodes = $node->childNodes;

if ($node->getAttribute('class') == 'usedcar_InfoName usedcar_InfoName_padding') {
echo $node->nodeValue . "
";
}

if ($node->getAttribute('class') == 'usedcar_InfoContent usedcar_InfoContent_padding') {
echo @mb_convert_encoding(htmlspecialchars($node->nodeValue), 'utf-8') . "
";
}

foreach($inodes as $inode){

if($inode->nodeName == 'a' && $inode->getAttribute('class') == 'breadcrumb_link') {
echo $inode->nodeValue . "
";
}

if($inode->nodeName == 'td' && $inode->getAttribute('class') == 'usedcar_InfoName usedcar_InfoName_padding') {
echo $inode->nodeValue . "
";

}
}
}
}

// xpath method
$xpath = new DOMXPath($dom);
$title = $xpath->query("/html/title");
$elements = $xpath->query("//*[@class='usedcar_InfoName usedcar_InfoName_padding']"); // header
$elements2 = $xpath->query("//*[@class='usedcar_InfoContent usedcar_InfoContent_padding']"); // content

// dump all the header tag into an array
$headers = array();
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
array_push($headers, $node->nodeValue);
}
}
}

// dump all content tag into an array
$contents = array();
if (!is_null($elements2)) {
foreach ($elements2 as $element) {
$nodes = $element->childNodes;
$count =0;
foreach ($nodes as $node) {
if ($count == 0)
array_push($contents, $node->nodeValue);
$count++;
}
}
}

for($count=0; $count < sizeof($headers); $count++)
echo $headers[$count] . ": " . $contents[$count] . "
";