Thursday, September 26, 2013

MySQL distance calculation in kilometers or miles

To calculate distance in MySQL, use the following query

The distance is in kilometers.

SELECT *,
6371 * acos( cos( radians($user_latitude) ) * cos( radians( latitude ) ) * cos( radians ( longitude ) - radians($user_longitude) ) + sin( radians($user_latitude) ) * sin( radians ( latitude ) ) )  as 'distance'
FROM locations
HAVING distance < 10;

To calculate distance in miles instead of kilometers

replace 6371 woth 3959

SELECT *,
6371 * acos( cos( radians($user_latitude) ) * cos( radians( latitude ) ) * cos( radians ( longitude ) - radians($user_longitude) ) + sin( radians($user_latitude) ) * sin( radians ( latitude ) ) )  as 'distance'
FROM locations
HAVING distance < 10;

Note: $user_latitude and $user_longitude is PHP variables containing user lat and lon, change them as you wish.

Sunday, September 15, 2013

Installing webmin on centOS using yum

create a file /etc/yum.repos.d/webmin.repo

[Webmin]

name=Webmin Distribution Neutral

#baseurl=http://download.webmin.com/download/yum

mirrorlist=http://download.webmin.com/download/yum/mirrorlist
enabled=1

paste the above content into the new file.
save the file.

Now enter "yum install webmin"

You are done

How to see disk space usage in linux

Estimating file space usage, we use "du" command.
du summarize disk usage of each file, recursively for directories.
It can be used with folders to get the total disk usage.

To see usage of /var/ we can run the following command

du /var/

The above command will show you the usage of each file in /var/ directory

If you add -c argument, it will include total size at the end.

du /var/ -c

If you want to see the summary only, use -s argument

du /var/ -s

If you want to see the size in human readable format, include -h argment

du /var/ -sh

du /var/ -h

du /var/ -ch

By default du dont include files which is not consuming any space.
If you want to include all files, use -a argument