Haversine formula:
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
where R is earth’s radius (mean radius = 6,371km);
note that angles need to be in radians to pass to trig functions!
JavaScript:
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
Total Pageviews
Tuesday, September 13, 2011
Monday, September 12, 2011
To Save the Jquery sortable data in database
<ul id="sortable" >
<li id="id1">elem 1 </li >
<li id="id2">elem 2 </li >
<li id="id3">elem 3 </li >
<li id="id4">elem 4 </li >
</ul >
$(document).ready(function(){
$('#sortable').sortable({
update: function(event, ui) {
var sortData= $(this).sortable('toArray').toString();
$.get('ajaxfilename.php', {order:sortData});
}
});
});
here sortData will get changed whenever a change is made in the Sortable
<li id="id1">elem 1 </li >
<li id="id2">elem 2 </li >
<li id="id3">elem 3 </li >
<li id="id4">elem 4 </li >
</ul >
$(document).ready(function(){
$('#sortable').sortable({
update: function(event, ui) {
var sortData= $(this).sortable('toArray').toString();
$.get('ajaxfilename.php', {order:sortData});
}
});
});
here sortData will get changed whenever a change is made in the Sortable
Tuesday, July 19, 2011
Mysql tricky stuff
1) Delete duplicate entry/data from mysql database.
delete from table1
USING table1, table1 as aliastable
WHERE (NOT table1.ID=aliastable.ID)
AND (table1.field_name=aliastable.field_name).
above query is a nice example of self-join.
2) Import large database files
run below command on command prompt.
mysql -p -u username database_name < file.sql
3) if you get following error
#1467 - Failed to read auto-increment value from storage engine
this happens because of 2 reasons your auto increment field length is too small
or it is a bug in mysql.
follow these steps
1)show table status;
if it shows a very large value for your auto increment column
use the query
ALTER TABLE table_name AUTO_INCREMENT =2009;
delete from table1
USING table1, table1 as aliastable
WHERE (NOT table1.ID=aliastable.ID)
AND (table1.field_name=aliastable.field_name).
above query is a nice example of self-join.
2) Import large database files
run below command on command prompt.
mysql -p -u username database_name < file.sql
3) if you get following error
#1467 - Failed to read auto-increment value from storage engine
this happens because of 2 reasons your auto increment field length is too small
or it is a bug in mysql.
follow these steps
1)show table status;
if it shows a very large value for your auto increment column
use the query
ALTER TABLE table_name AUTO_INCREMENT =2009;
Wednesday, July 13, 2011
How to get last insert id in MYSQL
There are 3 ways of getting last insert in mysql
1) mysql_insert_id();
2) LAST_INSERT_ID();
3) my fetching max(id) from column, this is generally not a good method for high traffic websites
1) mysql_insert_id();
2) LAST_INSERT_ID();
3) my fetching max(id) from column, this is generally not a good method for high traffic websites
Friday, June 24, 2011
Some Useful Php Tips
1) to get the file extension during file upload use:
2) To upload a large file, use following tips
pass 'MAX_FILE_SIZE' constant as a parameter and set its size.
this can be done by either defining it as a constant
define(MAX_FILE_SIZE,'1234561')
or passing it in hidden field like this
3) to get all the folders,without files
$ext = strrchr($_FILES['file']['name'], '.'); 2) To upload a large file, use following tips
pass 'MAX_FILE_SIZE' constant as a parameter and set its size.
this can be done by either defining it as a constant
define(MAX_FILE_SIZE,'1234561')
or passing it in hidden field like this
3) to get all the folders,without files
$dirs = array_filter(glob($path.'*'), 'is_dir');
Thursday, June 9, 2011
IE session issue in Codeigniter
You can try following things:
1) If session is working fine in your system but having problem on the server,
then set the time of server. the problem occurs due to difference in time.
2) try to set the path like
$config['cookie_domain'] = "meerutwala.com";
$config['cookie_path'] = "/app";
because IE need domain name for cookie.
3) Try this also
change
$config['sess_cookie_name'] = 'ci_session';
to
$config['sess_cookie_name'] = 'cisession';
because IE don't like underscore in its name
4) if nothing is working for you then go for native session :(
1) If session is working fine in your system but having problem on the server,
then set the time of server. the problem occurs due to difference in time.
2) try to set the path like
$config['cookie_domain'] = "meerutwala.com";
$config['cookie_path'] = "/app";
because IE need domain name for cookie.
3) Try this also
change
$config['sess_cookie_name'] = 'ci_session';
to
$config['sess_cookie_name'] = 'cisession';
because IE don't like underscore in its name
4) if nothing is working for you then go for native session :(
Monday, June 6, 2011
How to view all stored procedures in phpmyadmin
To create a procedure write followong command
delimiter ;;
drop procedure if exists mishraa;;
create procedure mishraa()
begin
select ‘Ashutosh Mishra’;
end
;;
to view the stored procedure, run the below commands
SELECT *
FROM information_schema.routines
above query will fetch all the stored procedures in your MYSQL database
delimiter ;;
drop procedure if exists mishraa;;
create procedure mishraa()
begin
select ‘Ashutosh Mishra’;
end
;;
to view the stored procedure, run the below commands
SELECT *
FROM information_schema.routines
above query will fetch all the stored procedures in your MYSQL database
Wednesday, May 25, 2011
todays Tips
addAttribute: In my early age of programming , i used to be very fasicinated with this method.It is used to set the attribute of any element.But when i used it i come to know that it does not work well with IE :(So better to user Jquery addClass and removeClass for adding or removing classes dynamically.
opacity:It is used to reduce the opacity of iamge,div ,input box etc.
its syntax is opacity=0.4 for mozilla and chrome.
For IE use in the range of 0 to 100. ,menas 0.40 in mozilla means 4o in IE
For IE syntax is
opacity:alpha{filter:40}
opacity:It is used to reduce the opacity of iamge,div ,input box etc.
its syntax is opacity=0.4 for mozilla and chrome.
For IE use in the range of 0 to 100. ,menas 0.40 in mozilla means 4o in IE
For IE syntax is
opacity:alpha{filter:40}
Monday, May 23, 2011
Google Chart API Customization
1) To modify a horizontal chart to vertical one.
just change the method barchart to columnchart
2) To specify colors to the bar graph,
pass array of color codes to the graph.
3) You can give legend to the chart by specifying the position to the legend
top,bottom,right.
4) To make a vertical chart to stacked one specify isStacked:true.
just change the method barchart to columnchart
2) To specify colors to the bar graph,
pass array of color codes to the graph.
3) You can give legend to the chart by specifying the position to the legend
top,bottom,right.
4) To make a vertical chart to stacked one specify isStacked:true.
Subscribe to:
Comments (Atom)