Friday, December 28, 2012
Wednesday, December 26, 2012
Variable type hinting in Netbeans (PHP)
In NetBeans - type vdoc and press tab to get the following template auto generated. (Source)
/* @var $varName Type_Name */
/* @var $varName Type_Name */
Monday, December 24, 2012
Mysql Setting Indian TimeZone (Asia/Calcutta)
Problem :
The following query :
select count(1) cnt,date_format(from_unixtime(absoluteTime),'%D-%M-%Y') as date1 from a,b where a.id = b.fid and b.col2 = 'xyz' group by date1 order by absoluteTime asc
Gave different results on my local machine as compared to the server hosted on EC2.
When I did :
mysql> show variables like '%time_zone%
I got :
+------------------+---------------+
| Variable_name | Value |
+------------------+---------------+
| system_time_zone | EST |
| time_zone | SYSTEM |
+------------------+---------------+
Which means that mysql is picking the system time zone which is EST(some US time zone).
Solution :
1. I checked time_zone* tables in mysql db - they were empty. So I did 2.
2. mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql (Source)
3. I edited /etc/my.cnf file and put this line there : default_time_zone=Asia/Calcutta
now service mysqld restart
Friday, December 21, 2012
installing apc
yum install pcre-devel
yum -y install php-devel
pecl install apc
add extension=apc.so to php.ini
Friday, December 14, 2012
php catching fatal errors
Source
register_shutdown_function('handleShutdown');
function handleShutdown() {
$error = error_get_last();
if($error !== NULL){
$info = "[SHUTDOWN] file:".$error['file']." | ln:".$error['line']." | msg:".$error['message'] .PHP_EOL;
yourPrintOrMailFunction($info);
}
else{
yourPrintOrMailFunction("SHUTDOWN");
}
}
Wednesday, December 12, 2012
Monday, December 10, 2012
FD RD Computation for LIC t.no.75 policy
<?php
$premium = 1000;
$rate = 0.05;
$years = 20;
echo "RD = ".rd($premium,$rate,$years)."\n";
$fd1 = fd(3000,0.05,15);
$fd2 = fd(3000,0.05,10);
$fd3 = fd(3000,0.05,5);
$fd4 = 22000;
echo "FD = ".($fd1+$fd2+$fd3+$fd4)."\n";
function fd($amt,$rate,$years) {
for($i=0; $i<$years;++$i) {
$amt = $amt*(1+$rate);
}
return $amt;
}
function rd($amt,$rate,$years) {
$final = 0;
for($i=0; $i<$years;++$i) {
$final = ($final + $amt)*(1+$rate);
}
return $final;
}
?>
Subscribe to:
Posts (Atom)