From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: distance from Easter Island to Chile Date: Wed, 23 Apr 2014 04:49:04 +0200 Organization: Aioe.org NNTP Server Message-ID: <87lhuwu5en.fsf@nl106-137-194.student.uu.se> References: <87mwfguasr.fsf@nl106-137-194.student.uu.se> <87mwfg823s.fsf@nl106-137-194.student.uu.se> <8761m3tq89.fsf@nl106-137-194.student.uu.se> <87sip7dl70.fsf@nl106-137-194.student.uu.se> <87mwffdkhj.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1398221424 21875 80.91.229.3 (23 Apr 2014 02:50:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Apr 2014 02:50:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 23 04:50:20 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WcnGN-00057y-Vy for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Apr 2014 04:50:20 +0200 Original-Received: from localhost ([::1]:58335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcnGN-0003IA-EF for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Apr 2014 22:50:19 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 83 Original-NNTP-Posting-Host: VVbyYd/iFZoeWNmD9i++cQ.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:6xfzDYr7musKj/4hWJUG5uGJ1os= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:205051 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97317 Archived-At: Made this into a CLI tool that fetches data (with curl) from Wikipedia. Even if you don't care for the CLI, the Emacs code is improved, too. It is sort of *slow* because of the fetch, and the start of Emacs, but perhaps the parsing is heavy-handed, as well. Try: distance 'Easter Island' 'Santiago de Chile' distance Peking Paris # etc. Pretty cool, huh? I put all the files here: http://user.it.uu.se/~embe8573/distance/ 1) loc #!/bin/zsh args=$(echo $* | sed 's/ /%20/g') url=https://en.wikipedia.org/w/index.php\?title=$args\&printable=yes coords=$(curl -s $url | grep -o '"geo">[-.[:digit:]]*; [-.[:digit:]]*<' | head -n 1 | sed 's/\("geo">\|-\|;\|<\)//g') 2) distance #!/bin/zsh coords1=`loc $1` coords2=`loc $2` lat1=$(echo $coords1 | cut -d" " -f1) long1=$(echo $coords1 | cut -d" " -f2) lat2=$(echo $coords2 | cut -d" " -f1) long2=$(echo $coords2 | cut -d" " -f2) emacs -Q -script distance.el $1 $lat1 $long1 $2 $lat2 $long2 3) distance.el (require 'cl) (defun sin2 (p) (let ((sin-p (sin p))) (* sin-p sin-p) )) (defun haversine (a b) (sin2 (/ (- a b) 2) )) (setq earth-radius 6367.4447) (defun distance (p1 p2) (let ((from (car p1)) (to (car p2)) (lat1 (degrees-to-radians (caadr p1))) (long1 (degrees-to-radians (cadadr p1))) (lat2 (degrees-to-radians (caadr p2))) (long2 (degrees-to-radians (cadadr p2))) ) (message "%s -> %s: %.2f km" from to (* 2 earth-radius (asin (sqrt (+ (haversine lat2 lat1) (* (cos lat2) (cos lat1) (haversine long2 long1) )))))))) (let ((from (elt argv 0)) (lat1 (string-to-number (elt argv 1))) (long1 (string-to-number (elt argv 2))) (to (elt argv 3)) (lat2 (string-to-number (elt argv 4))) (long2 (string-to-number (elt argv 5))) ) (distance (list from (list lat1 long1)) (list to (list lat2 long2)) )) -- underground experts united: http://user.it.uu.se/~embe8573