Wednesday 30 May 2012

Get 4 position bound a position


Get 4 position bound a position
/**
     * @author phuc.duong
     * @todo G
     */
   public function getFourPosition($long, $lat, $distance) {
        $earthRadius = 6371;
        //latitude in radians
        $lat = ($lat * pi()) / 180;

        //longitude in radians
        $lon = ($long * pi()) / 180;

        //angular distance covered on earth's surface
        $d = floatval($distance) / $earthRadius;
        $arrTemp = array();
        $bearing = array(0, 90, 180, 270);
        foreach ($bearing as $key => $value) {
            $bearing = $value * pi() / 180; //rad
            $arrTemp[$key]['Lat'] = asin(sin($lat) * cos($d) + cos($lat) * sin($d) * cos($bearing));
            $arrTemp[$key]['Long'] = (($lon + atan2(sin($bearing) * sin($d) * cos($lat), cos($d) - sin($lat) * sin($arrTemp[$key]['Lat']))) * 180) / pi();
            $arrTemp[$key]['Lat'] = ($arrTemp[$key]['Lat'] * 180) / pi();
        }
        return $arrTemp;
    }

Saturday 26 May 2012

Monday 21 May 2012

Create Virtual Host on Ubuntu

Install
1. cd /etc/apache2/sites-available
2. sudo vim yourdomain.com.conf and enter your VirtualHost directive. Below I've put
the most basic example, see Apache docs for details and additional features:
3. <VirtualHost *>
4. ServerName yourdomain.com
5. DocumentRoot /home/youruser/public_html
6. </VirtualHost>
7. Save & exit.
8. sudo vim /etc/hosts and add your new domain to the 127.0.0.1 localhost line so it looks
like this:
9. 127.0.0.1 localhost yourdomain.com
10. Save & exit.
11. Enable your new virtualhost:
12. sudo a2ensite yourdomain.com.conf
13. Reload the Apache configuration:
14. sudo /etc/init.d/apache2 reload

Remove

Code:
sudo a2dissite sitename
Restart apache2
Code:
sudo /etc/init.d/apache2 reload
Again to remove (delete)it completely from the system,
Code:
sudo rm /etc/apache2/sites-available/sitename
I would also disable it first before deleting the file.

Backup script + User in mysql

backup script
***************************
su d=$(date +%Y_%m_%d_%H_%M)
project="project_data"
path="/backup/databases/$project-$d.gz"
mysqldump --opt --routines --single-transaction -uroot -ppassword $project | gzip > $path
**************************************

restore
****************************************
gunzip < project_data.gz | mysql -uroot -p -h192.168.1.1
project_data
****************************************

User
#####Create user
create user 'developer'@'localhost' identified by 'password';

######grant user
grant all on *.* to 'developer'@'localhost';
FLUSH PRIVILEGES;
#
######revoke user
REVOKE INSERT ON *.* FROM 'jeffrey'@'localhost';
FLUSH PRIVILEGES;
#
######Drop user
DROP USER 'jeffrey'@'localhost';

######Update user password
update user set password=PASSWORD("123456") where user='root' and
host='localhost';
flush privileges;

######Show grant of user
SHOW GRANTS FOR 'developer'@'%';