Artifact
9efc69553ae6a2089f64e1ccb5b67b66a1ef250c8cd5372fdd8e56cb0cf091d1:
- File
README.md
— part of check-in
[64b10ac7d9]
at
2018-06-05 10:56:08
on branch master
— Formatting
(user:
noreply@github.com
size: 6124)
0000: 23 20 48 65 61 64 73 20 49 20 4c 6f 73 65 0a 0a # Heads I Lose..
0010: 54 68 69 73 20 73 74 61 72 74 65 64 20 61 73 20 This started as
0020: 61 20 6c 69 74 74 6c 65 20 6c 65 61 72 6e 69 6e a little learnin
0030: 67 20 65 78 65 72 63 69 73 65 20 69 6e 20 45 72 g exercise in Er
0040: 6c 61 6e 67 2c 20 62 75 74 20 49 27 76 65 20 62 lang, but I've b
0050: 65 65 6e 20 62 75 69 6c 64 69 6e 67 20 6f 6e 20 een building on
0060: 69 74 20 74 6f 20 6d 61 6b 65 20 69 74 20 6d 6f it to make it mo
0070: 72 65 20 75 73 65 66 75 6c 20 66 6f 72 20 6d 79 re useful for my
0080: 20 63 79 63 6c 65 20 63 6f 6d 6d 75 74 65 2e 20 cycle commute.
0090: 49 74 20 6c 6f 6f 6b 73 20 75 70 20 74 68 65 20 It looks up the
00a0: 77 69 6e 64 20 64 69 72 65 63 74 69 6f 6e 20 28 wind direction (
00b0: 5b 76 69 61 20 74 68 65 20 4d 65 74 4f 66 66 69 [via the MetOffi
00c0: 63 65 20 44 61 74 61 70 6f 69 6e 74 20 41 50 49 ce Datapoint API
00d0: 5d 28 68 74 74 70 3a 2f 2f 77 77 77 2e 6d 65 74 ](http://www.met
00e0: 6f 66 66 69 63 65 2e 67 6f 76 2e 75 6b 2f 64 61 office.gov.uk/da
00f0: 74 61 70 6f 69 6e 74 2f 61 70 69 29 29 20 61 6e tapoint/api)) an
0100: 64 20 66 6f 72 20 61 20 67 69 76 65 6e 20 72 6f d for a given ro
0110: 75 74 65 20 28 61 20 70 6f 6c 79 6c 69 6e 65 20 ute (a polyline
0120: 66 72 6f 6d 20 5b 4f 53 52 4d 5d 28 68 74 74 70 from [OSRM](http
0130: 3a 2f 2f 70 72 6f 6a 65 63 74 2d 6f 73 72 6d 2e ://project-osrm.
0140: 6f 72 67 2f 29 29 20 64 65 74 65 72 6d 69 6e 65 org/)) determine
0150: 73 20 68 6f 77 20 6d 75 63 68 20 6f 66 20 74 68 s how much of th
0160: 65 20 72 6f 75 74 65 20 69 73 20 61 20 68 65 61 e route is a hea
0170: 64 77 69 6e 64 20 73 69 64 65 77 69 6e 64 20 6f dwind sidewind o
0180: 72 20 74 61 69 6c 77 69 6e 64 2e 20 0a 0a 23 23 r tailwind. ..##
0190: 20 55 73 61 67 65 0a 0a 53 69 6e 63 65 20 69 74 Usage..Since it
01a0: 20 68 61 73 20 6a 75 73 74 20 62 65 65 6e 20 64 has just been d
01b0: 65 76 65 6c 6f 70 65 64 20 66 6f 72 20 70 65 72 eveloped for per
01c0: 73 6f 6e 61 6c 20 75 73 65 20 69 6e 73 74 61 6c sonal use instal
01d0: 6c 61 74 69 6f 6e 20 69 73 20 6e 6f 74 20 76 65 lation is not ve
01e0: 72 79 20 70 6f 6c 69 73 68 65 64 2e 0a 0a 31 2e ry polished...1.
01f0: 20 47 65 74 20 61 20 4d 65 74 4f 66 66 69 63 65 Get a MetOffice
0200: 20 44 61 74 61 70 6f 69 6e 74 20 5b 41 50 49 20 Datapoint [API
0210: 6b 65 79 5d 28 68 74 74 70 3a 2f 2f 77 77 77 2e key](http://www.
0220: 6d 65 74 6f 66 66 69 63 65 2e 67 6f 76 2e 75 6b metoffice.gov.uk
0230: 2f 64 61 74 61 70 6f 69 6e 74 2f 73 75 70 70 6f /datapoint/suppo
0240: 72 74 2f 41 50 49 29 20 61 6e 64 20 73 61 76 65 rt/API) and save
0250: 20 69 6e 20 61 20 66 69 6c 65 20 63 61 6c 6c 65 in a file calle
0260: 64 20 60 7e 2f 2e 64 61 74 61 70 6f 69 6e 74 60 d `~/.datapoint`
0270: 2e 0a 32 2e 20 47 65 74 2f 69 6e 73 74 61 6c 6c ..2. Get/install
0280: 20 5b 4a 69 66 66 79 5d 28 68 74 74 70 73 3a 2f [Jiffy](https:/
0290: 2f 67 69 74 68 75 62 2e 63 6f 6d 2f 64 61 76 69 /github.com/davi
02a0: 73 70 2f 6a 69 66 66 79 29 2e 20 28 49 20 6a 75 sp/jiffy). (I ju
02b0: 73 74 20 63 6c 6f 6e 65 64 20 74 68 65 20 72 65 st cloned the re
02c0: 70 6f 73 69 74 6f 72 79 2c 20 69 73 73 75 65 64 pository, issued
02d0: 20 60 6d 61 6b 65 60 20 61 6e 64 20 63 6f 70 69 `make` and copi
02e0: 65 64 20 74 68 65 20 60 65 62 69 6e 60 20 61 6e ed the `ebin` an
02f0: 64 20 60 70 72 69 76 60 20 64 69 72 65 63 74 6f d `priv` directo
0300: 72 69 65 73 20 74 6f 20 6d 79 20 60 68 65 61 64 ries to my `head
0310: 73 2d 49 2d 6c 6f 73 65 60 20 64 69 72 65 63 74 s-I-lose` direct
0320: 6f 72 79 29 2e 0a 33 2e 20 57 69 74 68 69 6e 20 ory)..3. Within
0330: 74 68 65 20 60 68 65 61 64 73 2d 49 2d 6c 6f 73 the `heads-I-los
0340: 65 60 20 64 69 72 65 63 74 6f 72 79 2c 20 63 6f e` directory, co
0350: 6d 70 69 6c 65 20 77 69 74 68 20 60 65 72 6c 63 mpile with `erlc
0360: 20 68 65 61 64 73 69 6c 6f 73 65 2e 65 72 6c 3b headsilose.erl;
0370: 20 65 72 6c 63 20 77 65 61 74 68 65 72 5f 74 79 erlc weather_ty
0380: 70 65 73 2e 65 72 6c 3b 20 65 72 6c 63 20 6f 73 pes.erl; erlc os
0390: 72 6d 2e 65 72 6c 3b 20 65 72 6c 63 20 70 6f 6c rm.erl; erlc pol
03a0: 79 6c 69 6e 65 2e 65 72 6c 60 2e 0a 34 2e 20 52 yline.erl`..4. R
03b0: 75 6e 20 60 65 72 6c 20 2d 72 75 6e 20 68 65 61 un `erl -run hea
03c0: 64 73 69 6c 6f 73 65 20 67 65 74 5f 6c 6f 63 61 dsilose get_loca
03d0: 74 69 6f 6e 73 20 3c 4f 70 74 69 6f 6e 61 6c 20 tions <Optional
03e0: 73 65 61 72 63 68 20 74 65 72 6d 3e 20 2d 6e 6f search term> -no
03f0: 73 68 65 6c 6c 20 2d 73 20 69 6e 69 74 20 73 74 shell -s init st
0400: 6f 70 60 20 74 6f 20 67 65 74 20 61 20 6c 69 73 op` to get a lis
0410: 74 20 6f 66 20 6c 6f 63 61 74 69 6f 6e 73 20 61 t of locations a
0420: 6e 64 20 49 64 73 2e 20 54 68 65 20 6f 70 74 69 nd Ids. The opti
0430: 6f 6e 61 6c 20 73 65 61 72 63 68 20 74 65 72 6d onal search term
0440: 20 63 61 6e 6e 6f 74 20 63 6f 6e 74 61 69 6e 20 cannot contain
0450: 73 70 61 63 65 73 2e 0a 35 2e 20 46 72 6f 6d 20 spaces..5. From
0460: 77 69 74 68 69 6e 20 74 68 65 20 65 72 6c 61 6e within the erlan
0470: 67 20 73 68 65 6c 6c 20 28 62 65 63 61 75 73 65 g shell (because
0480: 20 49 20 64 6f 6e 27 74 20 79 65 74 20 6b 6e 6f I don't yet kno
0490: 77 20 68 6f 77 20 74 6f 20 70 61 73 73 20 6e 65 w how to pass ne
04a0: 67 61 74 69 76 65 20 6e 75 6d 62 65 72 73 20 6f gative numbers o
04b0: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 n the command li
04c0: 6e 65 29 20 72 75 6e 20 60 6f 73 72 6d 3a 67 65 ne) run `osrm:ge
04d0: 74 5f 72 6f 75 74 65 28 5b 3c 73 74 61 72 74 5f t_route([<start_
04e0: 6c 61 74 3e 20 2c 3c 73 74 61 72 74 5f 6c 6f 6e lat> ,<start_lon
04f0: 3e 5d 2c 5b 3c 65 6e 64 5f 6c 61 74 3e 2c 3c 65 >],[<end_lat>,<e
0500: 6e 64 5f 6c 6f 6e 3e 5d 29 60 20 74 6f 20 67 65 nd_lon>])` to ge
0510: 74 20 61 20 72 6f 75 74 65 20 66 72 6f 6d 20 4f t a route from O
0520: 53 52 4d 2e 20 59 6f 75 27 6c 6c 20 68 61 76 65 SRM. You'll have
0530: 20 74 6f 20 66 69 6e 64 20 74 68 65 20 6c 61 74 to find the lat
0540: 69 74 75 64 65 20 61 6e 64 20 6c 6f 6e 67 69 74 itude and longit
0550: 75 64 65 73 20 62 79 20 5b 73 6f 6d 65 20 6f 74 udes by [some ot
0560: 68 65 72 20 6d 65 61 6e 73 5d 28 68 74 74 70 3a her means](http:
0570: 2f 2f 77 77 77 2e 75 6b 2d 70 6f 73 74 63 6f 64 //www.uk-postcod
0580: 65 73 2e 63 6f 6d 2f 29 29 20 66 6f 72 20 6e 6f es.com/)) for no
0590: 77 2e 20 54 68 69 73 20 77 69 6c 6c 20 73 61 76 w. This will sav
05a0: 65 20 74 68 65 20 72 6f 75 74 65 20 69 6e 20 60 e the route in `
05b0: 7e 2f 2e 68 65 61 64 73 69 6c 6f 73 65 2d 72 6f ~/.headsilose-ro
05c0: 75 74 65 60 2e 0a 36 2e 20 52 75 6e 20 60 65 72 ute`..6. Run `er
05d0: 6c 20 2d 72 75 6e 20 68 65 61 64 73 69 6c 6f 73 l -run headsilos
05e0: 65 20 68 65 61 64 73 69 6c 6f 73 65 20 3c 6c 6f e headsilose <lo
05f0: 63 61 74 69 6f 6e 20 69 64 3e 20 2d 6e 6f 73 68 cation id> -nosh
0600: 65 6c 6c 60 20 74 6f 20 67 65 74 20 74 68 65 20 ell` to get the
0610: 72 65 73 75 6c 74 2e 0a 0a 53 69 6e 63 65 20 49 result...Since I
0620: 20 77 72 6f 74 65 20 74 68 69 73 20 74 6f 20 62 wrote this to b
0630: 65 20 73 65 6d 69 2d 75 73 65 66 75 6c 20 66 6f e semi-useful fo
0640: 72 20 6d 65 2c 20 74 68 65 20 72 65 73 75 6c 74 r me, the result
0650: 20 72 65 74 75 72 6e 65 64 20 64 65 70 65 6e 64 returned depend
0660: 73 20 6f 6e 20 74 68 65 20 74 69 6d 65 20 6f 66 s on the time of
0670: 20 74 68 65 20 64 61 79 2e 20 49 66 20 69 74 27 the day. If it'
0680: 73 20 72 75 6e 20 62 65 66 6f 72 65 20 38 61 6d s run before 8am
0690: 20 69 74 20 6c 6f 6f 6b 73 20 66 6f 72 20 74 68 it looks for th
06a0: 65 20 36 61 6d 20 77 65 61 74 68 65 72 20 64 61 e 6am weather da
06b0: 74 61 20 28 73 69 6e 63 65 20 64 61 74 61 20 69 ta (since data i
06c0: 73 20 69 6e 20 33 20 68 6f 75 72 20 70 65 72 69 s in 3 hour peri
06d0: 6f 64 73 29 20 61 6e 64 20 61 73 73 75 6d 65 73 ods) and assumes
06e0: 20 74 68 65 20 72 6f 75 74 65 20 69 73 20 62 65 the route is be
06f0: 69 6e 67 20 74 72 61 76 65 72 73 65 64 20 6e 6f ing traversed no
0700: 72 6d 61 6c 6c 79 2c 20 72 75 6e 20 62 65 74 77 rmally, run betw
0710: 65 65 6e 20 38 61 6d 20 61 6e 64 20 37 70 6d 20 een 8am and 7pm
0720: 69 74 20 6c 6f 6f 6b 73 20 66 6f 72 20 74 68 65 it looks for the
0730: 20 36 70 6d 20 64 61 74 61 20 66 6f 72 20 67 6f 6pm data for go
0740: 69 6e 67 20 68 6f 6d 65 20 61 6e 64 20 74 68 65 ing home and the
0750: 72 65 66 6f 72 65 20 61 6c 73 6f 20 74 72 61 76 refore also trav
0760: 65 72 73 65 73 20 74 68 65 20 73 61 76 65 64 20 erses the saved
0770: 72 6f 75 74 65 20 69 6e 20 72 65 76 65 72 73 65 route in reverse
0780: 2c 20 61 6e 64 20 72 75 6e 20 61 66 74 65 72 20 , and run after
0790: 74 68 61 74 20 74 69 6d 65 20 69 74 20 6c 6f 6f that time it loo
07a0: 6b 73 20 61 67 61 69 6e 20 66 6f 72 20 74 68 65 ks again for the
07b0: 20 36 61 6d 20 64 61 74 61 2c 20 62 75 74 20 66 6am data, but f
07c0: 6f 72 20 74 68 65 20 6e 65 78 74 20 64 61 79 2c or the next day,
07d0: 20 61 6e 64 20 74 68 75 73 20 74 68 65 20 72 6f and thus the ro
07e0: 75 74 65 20 69 73 20 62 61 63 6b 20 74 6f 20 62 ute is back to b
07f0: 65 69 6e 67 20 74 72 61 76 65 72 73 65 64 20 69 eing traversed i
0800: 6e 20 74 68 65 20 6e 6f 72 6d 61 6c 20 64 69 72 n the normal dir
0810: 65 63 74 69 6f 6e 2e 0a 0a 5f 48 69 6e 74 3a 5f ection..._Hint:_
0820: 20 49 20 68 61 76 65 20 61 20 73 68 65 6c 6c 20 I have a shell
0830: 66 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 65 64 function defined
0840: 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 0a 09 66 as follows:...f
0850: 75 6e 63 74 69 6f 6e 20 68 65 61 64 73 69 6c 6f unction headsilo
0860: 73 65 20 7b 0a 09 09 65 72 6c 20 2d 70 61 20 2f se {...erl -pa /
0870: 68 6f 6d 65 2f 73 69 6d 6f 6e 2f 43 6f 64 65 2f home/simon/Code/
0880: 67 69 74 68 75 62 2f 61 74 6f 6d 69 63 75 6c 65 github/atomicule
0890: 73 2f 68 65 61 64 73 2d 49 2d 6c 6f 73 65 20 2f s/heads-I-lose /
08a0: 68 6f 6d 65 2f 73 69 6d 6f 6e 2f 43 6f 64 65 2f home/simon/Code/
08b0: 67 69 74 68 75 62 2f 61 74 6f 6d 69 63 75 6c 65 github/atomicule
08c0: 73 2f 68 65 61 64 73 2d 49 2d 6c 6f 73 65 2f 65 s/heads-I-lose/e
08d0: 62 69 6e 20 2d 72 75 6e 20 68 65 61 64 73 69 6c bin -run headsil
08e0: 6f 73 65 20 68 65 61 64 73 69 6c 6f 73 65 20 58 ose headsilose X
08f0: 58 58 58 58 58 20 61 6c 74 65 72 6e 61 74 69 76 XXXXX alternativ
0900: 65 5f 67 65 6f 6d 65 74 72 69 65 73 20 2d 6e 6f e_geometries -no
0910: 73 68 65 6c 6c 3b 0a 09 7d 0a 0a 53 6f 20 49 20 shell;..}..So I
0920: 63 61 6e 20 6a 75 73 74 20 63 61 6c 6c 0a 0a 09 can just call...
0930: 68 65 61 64 73 69 6c 6f 73 65 0a 0a 57 68 69 63 headsilose..Whic
0940: 68 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e h will result in
0950: 20 73 6f 6d 65 74 68 69 6e 67 20 6c 69 6b 65 20 something like
0960: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 62 65 the following be
0970: 69 6e 67 20 70 72 69 6e 74 65 64 20 6f 75 74 3a ing printed out:
0980: 0a 0a 09 49 74 27 73 20 61 20 64 72 61 77 0a 09 ...It's a draw..
0990: 34 37 2e 31 25 20 48 65 61 64 77 69 6e 64 0a 09 47.1% Headwind..
09a0: 35 31 2e 34 35 25 20 53 69 64 65 77 69 6e 64 0a 51.45% Sidewind.
09b0: 09 31 2e 34 35 25 20 54 61 69 6c 77 69 6e 64 0a .1.45% Tailwind.
09c0: 09 44 69 72 65 63 74 69 6f 6e 3a 20 53 53 57 0a .Direction: SSW.
09d0: 09 53 70 65 65 64 3a 20 31 33 20 6d 70 68 0a 09 .Speed: 13 mph..
09e0: 47 75 73 74 3a 20 32 39 20 6d 70 68 0a 09 57 65 Gust: 29 mph..We
09f0: 61 74 68 65 72 20 74 79 70 65 3a 20 43 6c 6f 75 ather type: Clou
0a00: 64 79 0a 09 54 65 6d 70 65 72 61 74 75 72 65 3a dy..Temperature:
0a10: 20 34 20 64 65 67 20 43 0a 0a 5f 4e 6f 74 65 31 4 deg C.._Note1
0a20: 3a 5f 20 53 69 6e 63 65 20 74 68 65 20 72 6f 75 :_ Since the rou
0a30: 74 65 20 69 73 20 66 72 6f 6d 20 4f 53 52 4d 20 te is from OSRM
0a40: 74 68 65 72 65 20 69 73 20 74 68 65 20 6f 70 74 there is the opt
0a50: 69 6f 6e 20 74 6f 20 73 70 65 63 69 66 79 20 60 ion to specify `
0a60: 61 6c 74 65 72 6e 61 74 69 76 65 5f 67 65 6f 6d alternative_geom
0a70: 65 74 72 69 65 73 60 20 61 73 20 61 6e 20 61 72 etries` as an ar
0a80: 67 75 6d 65 6e 74 2e 20 49 6e 20 74 68 65 6f 72 gument. In theor
0a90: 79 20 4f 53 52 4d 20 63 61 6e 20 72 65 74 75 72 y OSRM can retur
0aa0: 6e 20 6d 6f 72 65 20 74 68 61 6e 20 6f 6e 65 20 n more than one
0ab0: 61 6c 74 65 72 6e 61 74 69 76 65 20 72 6f 75 74 alternative rout
0ac0: 65 2c 20 62 75 74 20 69 6e 20 70 72 61 63 74 69 e, but in practi
0ad0: 63 65 20 28 61 74 20 6c 65 61 73 74 20 61 73 20 ce (at least as
0ae0: 66 61 72 20 61 73 20 49 20 63 61 6e 20 74 65 6c far as I can tel
0af0: 6c 29 20 49 20 74 68 69 6e 6b 20 69 74 20 6f 6e l) I think it on
0b00: 6c 79 20 65 76 65 72 20 72 65 74 75 72 6e 73 20 ly ever returns
0b10: 6f 6e 65 20 61 6c 74 65 72 6e 61 74 69 76 65 20 one alternative
0b20: 72 6f 75 74 65 20 73 6f 20 61 6c 74 68 6f 75 67 route so althoug
0b30: 68 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 69 h the argument i
0b40: 73 20 60 61 6c 74 65 72 6e 61 74 69 76 65 5f 67 s `alternative_g
0b50: 65 6f 6d 65 74 72 69 65 73 60 20 69 74 20 69 73 eometries` it is
0b60: 20 61 63 74 75 61 6c 6c 79 20 74 68 65 20 66 69 actually the fi
0b70: 72 73 74 20 61 6c 74 65 72 6e 61 74 69 76 65 20 rst alternative
0b80: 74 68 61 74 20 69 73 20 75 73 65 64 2e 20 49 66 that is used. If
0b90: 20 60 61 6c 74 65 72 6e 61 74 69 76 65 5f 67 65 `alternative_ge
0ba0: 6f 6d 65 74 72 69 65 73 60 20 69 73 20 6e 6f 74 ometries` is not
0bb0: 20 73 70 65 63 69 66 69 65 64 20 74 68 65 6e 20 specified then
0bc0: 74 68 65 20 64 65 66 61 75 6c 74 20 72 6f 75 74 the default rout
0bd0: 65 20 69 73 20 75 73 65 64 2e 20 49 66 20 79 6f e is used. If yo
0be0: 75 27 64 20 6c 69 6b 65 20 74 6f 20 73 65 65 20 u'd like to see
0bf0: 76 69 73 75 61 6c 6c 79 20 77 68 69 63 68 20 72 visually which r
0c00: 6f 75 74 65 20 69 73 20 74 68 65 20 64 65 66 61 oute is the defa
0c10: 75 6c 74 20 61 6e 64 20 77 68 69 63 68 20 69 73 ult and which is
0c20: 20 74 68 65 20 61 6c 74 65 72 6e 61 74 69 76 65 the alternative
0c30: 20 79 6f 75 20 63 61 6e 20 73 65 65 20 74 68 65 you can see the
0c40: 6d 20 61 74 20 5b 50 72 6f 6a 65 63 74 20 4f 53 m at [Project OS
0c50: 52 4d 5d 28 68 74 74 70 3a 2f 2f 6d 61 70 2e 70 RM](http://map.p
0c60: 72 6f 6a 65 63 74 2d 6f 73 72 6d 2e 6f 72 67 2f roject-osrm.org/
0c70: 29 20 61 73 20 72 6f 75 74 65 73 20 41 20 28 64 ) as routes A (d
0c80: 65 66 61 75 6c 74 29 20 61 6e 64 20 42 20 28 61 efault) and B (a
0c90: 6c 74 65 72 6e 61 74 69 76 65 29 2e 0a 0a 5f 4e lternative)..._N
0ca0: 6f 74 65 32 3a 5f 20 49 20 64 6f 6e 27 74 20 75 ote2:_ I don't u
0cb0: 73 65 20 5b 69 6e 69 74 20 73 74 6f 70 5d 28 68 se [init stop](h
0cc0: 74 74 70 3a 2f 2f 65 72 6c 61 6e 67 63 65 6e 74 ttp://erlangcent
0cd0: 72 61 6c 2e 6f 72 67 2f 77 69 6b 69 2f 69 6e 64 ral.org/wiki/ind
0ce0: 65 78 2e 70 68 70 3f 74 69 74 6c 65 3d 52 75 6e ex.php?title=Run
0cf0: 6e 69 6e 67 5f 45 72 6c 61 6e 67 5f 43 6f 64 65 ning_Erlang_Code
0d00: 5f 46 72 6f 6d 5f 54 68 65 5f 43 6f 6d 6d 61 6e _From_The_Comman
0d10: 64 5f 4c 69 6e 65 26 6f 6c 64 69 64 3d 32 32 39 d_Line&oldid=229
0d20: 33 29 20 69 6e 20 6d 79 20 6d 61 69 6e 20 63 6f 3) in my main co
0d30: 6d 6d 61 6e 64 20 6c 69 6e 65 20 63 61 6c 6c 20 mmand line call
0d40: 61 73 20 49 20 68 61 76 65 20 74 68 61 74 20 69 as I have that i
0d50: 6e 20 6d 79 20 73 63 72 69 70 74 20 69 6e 73 74 n my script inst
0d60: 65 61 64 2e 20 4f 74 68 65 72 77 69 73 65 2c 20 ead. Otherwise,
0d70: 69 66 20 60 68 65 61 64 73 69 6c 6f 73 65 60 20 if `headsilose`
0d80: 65 72 72 6f 72 73 20 6f 75 74 20 74 68 65 6e 20 errors out then
0d90: 60 69 6e 69 74 20 73 74 6f 70 60 20 77 69 6c 6c `init stop` will
0da0: 20 63 72 61 73 68 20 6f 75 74 20 28 49 20 67 75 crash out (I gu
0db0: 65 73 73 20 62 65 63 61 75 73 65 20 69 74 20 69 ess because it i
0dc0: 73 20 74 72 79 69 6e 67 20 74 6f 20 73 74 6f 70 s trying to stop
0dd0: 20 73 6f 6d 65 74 68 69 6e 67 20 74 68 61 74 20 something that
0de0: 69 73 6e 27 74 20 72 75 6e 6e 69 6e 67 29 2e 0a isn't running)..
0df0: 0a 23 23 20 43 72 65 64 69 74 73 0a 0a 56 61 72 .## Credits..Var
0e00: 69 6f 75 73 20 70 6f 73 74 73 20 49 27 76 65 20 ious posts I've
0e10: 66 6f 75 6e 64 20 74 68 61 74 20 68 61 76 65 20 found that have
0e20: 68 65 6c 70 65 64 20 6d 65 20 6f 75 74 3a 0a 0a helped me out:..
0e30: 2d 20 49 6e 69 74 69 61 6c 20 69 6e 73 70 69 72 - Initial inspir
0e40: 61 74 69 6f 6e 20 66 72 6f 6d 20 5b 50 72 61 67 ation from [Prag
0e50: 44 61 76 65 20 2d 20 41 20 46 69 72 73 74 20 45 Dave - A First E
0e60: 72 6c 61 6e 67 20 50 72 6f 67 72 61 6d 5d 28 68 rlang Program](h
0e70: 74 74 70 3a 2f 2f 70 72 61 67 64 61 76 65 2e 70 ttp://pragdave.p
0e80: 72 61 67 70 72 6f 67 2e 63 6f 6d 2f 70 72 61 67 ragprog.com/prag
0e90: 64 61 76 65 2f 32 30 30 37 2f 30 34 2f 61 5f 66 dave/2007/04/a_f
0ea0: 69 72 73 74 5f 65 72 6c 61 6e 67 5f 2e 68 74 6d irst_erlang_.htm
0eb0: 6c 29 0a 2d 20 50 75 74 74 69 6e 67 20 69 6e 69 l).- Putting ini
0ec0: 74 69 61 6c 20 69 6e 73 70 69 72 61 74 69 6f 6e tial inspiration
0ed0: 20 74 6f 20 70 72 61 63 74 69 63 65 20 28 69 2e to practice (i.
0ee0: 65 2e 20 60 69 6e 65 74 73 3a 73 74 61 72 74 60 e. `inets:start`
0ef0: 29 20 66 72 6f 6d 20 5b 41 6e 64 72 65 77 20 4c ) from [Andrew L
0f00: 6f 63 61 74 65 6c 6c 69 20 57 6f 6f 64 63 6f 63 ocatelli Woodcoc
0f10: 6b 20 2d 20 43 6f 6e 6e 65 63 74 69 6e 67 20 74 k - Connecting t
0f20: 6f 20 43 6c 6f 75 64 61 6e 74 20 66 72 6f 6d 20 o Cloudant from
0f30: 45 72 6c 61 6e 67 3a 20 61 20 71 75 69 63 6b 20 Erlang: a quick
0f40: 65 78 61 6d 70 6c 65 20 6f 66 20 75 73 69 6e 67 example of using
0f50: 20 48 54 54 50 53 20 66 72 6f 6d c2 a0 68 74 74 HTTPS from htt
0f60: 70 63 3a 72 65 71 75 65 73 74 5d 28 68 74 74 70 pc:request](http
0f70: 3a 2f 2f 61 6e 64 72 65 77 6c 6f 63 61 74 65 6c ://andrewlocatel
0f80: 6c 69 77 6f 6f 64 63 6f 63 6b 2e 63 6f 6d 2f 32 liwoodcock.com/2
0f90: 30 31 32 2f 30 36 2f 31 32 2f 63 6f 6e 6e 65 63 012/06/12/connec
0fa0: 74 69 6e 67 2d 74 6f 2d 63 6c 6f 75 64 61 6e 74 ting-to-cloudant
0fb0: 2d 66 72 6f 6d 2d 65 72 6c 61 6e 67 2d 61 2d 71 -from-erlang-a-q
0fc0: 75 69 63 6b 2d 65 78 61 6d 70 6c 65 2d 6f 66 2d uick-example-of-
0fd0: 75 73 69 6e 67 2d 68 74 74 70 73 2d 66 72 6f 6d using-https-from
0fe0: 2d 68 74 74 70 63 72 65 71 75 65 73 74 2d 31 37 -httpcrequest-17
0ff0: 2d 32 2f 29 0a 2d 20 54 68 65 20 72 65 63 75 72 -2/).- The recur
1000: 73 69 76 65 20 70 61 72 73 69 6e 67 20 6f 66 20 sive parsing of
1010: 58 4d 4c 20 66 72 6f 6d 20 5b 53 61 6d 20 52 75 XML from [Sam Ru
1020: 62 79 20 2d 20 50 61 72 73 69 6e 67 20 41 74 6f by - Parsing Ato
1030: 6d 20 77 69 74 68 20 45 72 6c 61 6e 67 5d 28 68 m with Erlang](h
1040: 74 74 70 3a 2f 2f 69 6e 74 65 72 74 77 69 6e 67 ttp://intertwing
1050: 6c 79 2e 6e 65 74 2f 62 6c 6f 67 2f 32 30 30 37 ly.net/blog/2007
1060: 2f 30 38 2f 32 38 2f 50 61 72 73 69 6e 67 2d 41 /08/28/Parsing-A
1070: 74 6f 6d 2d 77 69 74 68 2d 45 72 6c 61 6e 67 29 tom-with-Erlang)
1080: 0a 2d 20 46 6f 72 6d 61 74 69 6e 67 20 64 61 74 .- Formating dat
1090: 65 73 20 77 69 74 68 20 6c 65 61 64 69 6e 67 20 es with leading
10a0: 7a 65 72 6f 65 73 20 66 72 6f 6d 20 5b 57 61 72 zeroes from [War
10b0: 72 65 6e 20 59 6f 75 6e 67 20 6f 6e 20 53 74 61 ren Young on Sta
10c0: 63 6b 20 4f 76 65 72 66 6c 6f 77 5d 28 68 74 74 ck Overflow](htt
10d0: 70 3a 2f 2f 73 74 61 63 6b 6f 76 65 72 66 6c 6f p://stackoverflo
10e0: 77 2e 63 6f 6d 2f 61 2f 37 35 39 39 35 30 36 2f w.com/a/7599506/
10f0: 32 30 38 37 39 33 29 0a 2d 20 46 69 67 75 72 69 208793).- Figuri
1100: 6e 67 20 6f 75 74 20 63 6f 6d 6d 61 6e 64 20 6c ng out command l
1110: 69 6e 65 20 61 72 67 75 6d 65 6e 74 73 20 66 72 ine arguments fr
1120: 6f 6d 20 5b 43 6f 64 79 20 6f 6e 20 53 74 61 63 om [Cody on Stac
1130: 6b 20 4f 76 65 72 66 6c 6f 77 5d 28 68 74 74 70 k Overflow](http
1140: 3a 2f 2f 73 74 61 63 6b 6f 76 65 72 66 6c 6f 77 ://stackoverflow
1150: 2e 63 6f 6d 2f 61 2f 38 34 39 38 30 37 33 2f 32 .com/a/8498073/2
1160: 30 38 37 39 33 29 0a 2d 20 46 69 67 75 72 69 6e 08793).- Figurin
1170: 67 20 6f 75 74 20 5b 4a 69 66 66 79 5d 28 68 74 g out [Jiffy](ht
1180: 74 70 3a 2f 2f 77 77 77 2e 73 6e 69 70 32 63 6f tp://www.snip2co
1190: 64 65 2e 63 6f 6d 2f 53 6e 69 70 70 65 74 2f 35 de.com/Snippet/5
11a0: 31 34 36 33 2f 68 6f 77 2d 74 6f 2d 73 75 70 70 1463/how-to-supp
11b0: 6f 72 74 2d 63 68 69 6e 65 73 65 2d 69 6e 2d 68 ort-chinese-in-h
11c0: 74 74 70 2d 72 65 71 75 65 73 74 2d 62 2f 29 0a ttp-request-b/).
11d0: 2d 20 5b 52 6f 75 6e 64 69 6e 67 20 6e 75 6d 62 - [Rounding numb
11e0: 65 72 73 5d 28 68 74 74 70 3a 2f 2f 77 77 77 2e ers](http://www.
11f0: 63 6f 64 65 63 6f 64 65 78 2e 63 6f 6d 2f 77 69 codecodex.com/wi
1200: 6b 69 2f 69 6e 64 65 78 2e 70 68 70 3f 74 69 74 ki/index.php?tit
1210: 6c 65 3d 52 6f 75 6e 64 5f 61 5f 6e 75 6d 62 65 le=Round_a_numbe
1220: 72 5f 74 6f 5f 61 5f 73 70 65 63 69 66 69 63 5f r_to_a_specific_
1230: 64 65 63 69 6d 61 6c 5f 70 6c 61 63 65 23 45 72 decimal_place#Er
1240: 6c 61 6e 67 29 0a 2d 20 5b 43 6f 6e 76 65 72 74 lang).- [Convert
1250: 69 6e 67 20 62 65 74 77 65 65 6e 20 62 69 6e 61 ing between bina
1260: 72 79 20 61 6e 64 20 64 65 63 69 6d 61 6c 5d 28 ry and decimal](
1270: 68 74 74 70 3a 2f 2f 65 72 6c 61 6e 67 63 65 6e http://erlangcen
1280: 74 72 61 6c 2e 6f 72 67 2f 77 69 6b 69 2f 69 6e tral.org/wiki/in
1290: 64 65 78 2e 70 68 70 2f 43 6f 6e 76 65 72 74 69 dex.php/Converti
12a0: 6e 67 5f 42 65 74 77 65 65 6e 5f 42 69 6e 61 72 ng_Between_Binar
12b0: 79 5f 61 6e 64 5f 44 65 63 69 6d 61 6c 29 0a 0a y_and_Decimal)..
12c0: 49 20 64 69 64 20 72 65 61 64 20 74 68 72 6f 75 I did read throu
12d0: 67 68 20 61 20 5b 6e 75 6d 62 65 72 5d 28 68 74 gh a [number](ht
12e0: 74 70 3a 2f 2f 77 77 77 2e 6d 61 74 68 77 6f 72 tp://www.mathwor
12f0: 6b 73 2e 63 6f 6d 2f 6d 61 74 6c 61 62 63 65 6e ks.com/matlabcen
1300: 74 72 61 6c 2f 66 69 6c 65 65 78 63 68 61 6e 67 tral/fileexchang
1310: 65 2f 33 32 33 34 31 2d 67 6f 6f 67 6c 65 2d 6d e/32341-google-m
1320: 61 70 73 2d 61 70 69 2d 70 6f 6c 79 6c 69 6e 65 aps-api-polyline
1330: 2d 64 65 63 6f 64 65 72 29 20 5b 6f 66 5d 28 68 -decoder) [of](h
1340: 74 74 70 3a 2f 2f 6a 65 66 66 72 65 79 73 61 6d ttp://jeffreysam
1350: 62 65 6c 6c 73 2e 63 6f 6d 2f 32 30 31 30 2f 30 bells.com/2010/0
1360: 35 2f 32 37 2f 64 65 63 6f 64 69 6e 67 2d 70 6f 5/27/decoding-po
1370: 6c 79 6c 69 6e 65 73 2d 66 72 6f 6d 2d 67 6f 6f lylines-from-goo
1380: 67 6c 65 2d 6d 61 70 73 2d 64 69 72 65 63 74 69 gle-maps-directi
1390: 6f 6e 2d 61 70 69 2d 77 69 74 68 2d 6a 61 76 61 on-api-with-java
13a0: 29 20 5b 70 6f 73 74 73 5d 28 68 74 74 70 3a 2f ) [posts](http:/
13b0: 2f 73 65 65 77 61 68 2e 62 6c 6f 67 73 70 6f 74 /seewah.blogspot
13c0: 2e 63 6f 2e 75 6b 2f 32 30 30 39 2f 31 31 2f 67 .co.uk/2009/11/g
13d0: 70 6f 6c 79 6c 69 6e 65 2d 64 65 63 6f 64 69 6e polyline-decodin
13e0: 67 2d 69 6e 2d 70 79 74 68 6f 6e 2e 68 74 6d 6c g-in-python.html
13f0: 29 2f 5b 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f )/[implementatio
1400: 6e 73 5d 28 68 74 74 70 3a 2f 2f 75 6e 69 74 73 ns](http://units
1410: 74 65 70 2e 6e 65 74 2f 62 6c 6f 67 2f 32 30 30 tep.net/blog/200
1420: 38 2f 30 38 2f 30 32 2f 64 65 63 6f 64 69 6e 67 8/08/02/decoding
1430: 2d 67 6f 6f 67 6c 65 2d 6d 61 70 73 2d 65 6e 63 -google-maps-enc
1440: 6f 64 65 64 2d 70 6f 6c 79 6c 69 6e 65 73 2d 75 oded-polylines-u
1450: 73 69 6e 67 2d 70 68 70 2f 29 20 5b 6f 66 5d 28 sing-php/) [of](
1460: 68 74 74 70 73 3a 2f 2f 67 69 74 68 75 62 2e 63 https://github.c
1470: 6f 6d 2f 50 72 6f 6a 65 63 74 2d 4f 53 52 4d 2f om/Project-OSRM/
1480: 6f 73 72 6d 2d 66 72 6f 6e 74 65 6e 64 2f 62 6c osrm-frontend/bl
1490: 6f 62 2f 6d 61 73 74 65 72 2f 57 65 62 43 6f 6e ob/master/WebCon
14a0: 74 65 6e 74 2f 72 6f 75 74 69 6e 67 2f 4f 53 52 tent/routing/OSR
14b0: 4d 2e 52 6f 75 74 69 6e 67 47 65 6f 6d 65 74 72 M.RoutingGeometr
14c0: 79 2e 6a 73 29 20 70 6f 6c 79 6c 69 6e 65 20 64 y.js) polyline d
14d0: 65 63 6f 64 65 72 73 2c 20 62 75 74 20 74 68 65 ecoders, but the
14e0: 79 20 64 69 64 6e 27 74 20 72 65 61 6c 6c 79 20 y didn't really
14f0: 68 65 6c 70 20 6d 65 20 69 6e 20 45 72 6c 61 6e help me in Erlan
1500: 67 20 73 6f 20 49 20 6a 75 73 74 20 77 6f 72 6b g so I just work
1510: 65 64 20 62 61 63 6b 77 61 72 64 73 20 74 68 72 ed backwards thr
1520: 6f 75 67 68 20 74 68 65 20 5b 73 70 65 63 69 66 ough the [specif
1530: 69 63 61 74 69 6f 6e 5d 28 68 74 74 70 73 3a 2f ication](https:/
1540: 2f 64 65 76 65 6c 6f 70 65 72 73 2e 67 6f 6f 67 /developers.goog
1550: 6c 65 2e 63 6f 6d 2f 6d 61 70 73 2f 64 6f 63 75 le.com/maps/docu
1560: 6d 65 6e 74 61 74 69 6f 6e 2f 75 74 69 6c 69 74 mentation/utilit
1570: 69 65 73 2f 70 6f 6c 79 6c 69 6e 65 61 6c 67 6f ies/polylinealgo
1580: 72 69 74 68 6d 29 20 61 6e 64 20 77 72 6f 74 65 rithm) and wrote
1590: 20 6d 79 20 6f 77 6e 2c 20 6d 75 63 68 20 6c 65 my own, much le
15a0: 73 73 20 63 6f 6e 63 69 73 65 2c 20 76 65 72 73 ss concise, vers
15b0: 69 6f 6e 20 72 61 74 68 65 72 20 74 68 61 6e 20 ion rather than
15c0: 70 6f 72 74 69 6e 67 20 61 6e 20 65 78 69 73 74 porting an exist
15d0: 69 6e 67 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 ing implementati
15e0: 6f 6e 2e 0a 0a 23 23 20 54 6f 64 6f 0a 0a 5f 49 on...## Todo.._I
15f0: 20 73 68 6f 75 6c 64 20 72 65 61 6c 6c 79 20 70 should really p
1600: 75 74 20 74 68 65 73 65 20 61 73 20 69 73 73 75 ut these as issu
1610: 65 73 5f 0a 0a 2d 20 53 6f 72 74 20 74 68 65 20 es_..- Sort the
1620: 6c 69 73 74 20 6f 66 20 6c 6f 63 61 74 69 6f 6e list of location
1630: 73 3f 0a 2d 20 46 69 6e 69 73 68 20 6f 66 66 20 s?.- Finish off
1640: 69 6d 70 6c 65 6d 65 6e 74 69 6e 67 20 74 68 65 implementing the
1650: 20 6c 69 73 74 20 6f 66 20 63 6c 69 65 6e 74 20 list of client
1660: 22 73 75 70 70 6f 73 65 64 20 74 6f 22 73 20 66 "supposed to"s f
1670: 72 6f 6d 20 74 68 65 20 4f 53 52 4d 20 41 50 49 rom the OSRM API
1680: 2c 20 73 75 63 68 20 61 73 20 63 68 65 63 6b 73 , such as checks
1690: 75 6d 20 61 6e 64 20 68 69 6e 74 20 64 61 74 61 um and hint data
16a0: 2c 20 62 75 74 20 74 68 69 73 20 77 6f 75 6c 64 , but this would
16b0: 20 6d 65 61 6e 20 63 61 63 68 69 6e 67 20 61 6c mean caching al
16c0: 6c 20 70 72 65 76 69 6f 75 73 20 72 65 71 75 65 l previous reque
16d0: 73 74 73 20 6d 61 64 65 2e 0a 2d 20 55 73 65 20 sts made..- Use
16e0: 70 6f 73 74 63 6f 64 65 73 20 74 6f 20 67 65 74 postcodes to get
16f0: 20 74 68 65 20 6c 61 74 69 74 75 64 65 73 20 61 the latitudes a
1700: 6e 64 20 6c 6f 6e 67 69 74 75 64 65 73 20 76 69 nd longitudes vi
1710: 61 20 5b 55 4b 20 50 6f 73 74 63 6f 64 65 73 5d a [UK Postcodes]
1720: 28 68 74 74 70 3a 2f 2f 77 77 77 2e 75 6b 2d 70 (http://www.uk-p
1730: 6f 73 74 63 6f 64 65 73 2e 63 6f 6d 2f 29 0a 2d ostcodes.com/).-
1740: 20 46 69 67 75 72 65 20 6f 75 74 20 68 6f 77 20 Figure out how
1750: 74 6f 20 70 61 73 73 20 6e 65 67 61 74 69 76 65 to pass negative
1760: 20 6e 75 6d 62 65 72 73 20 6f 6e 20 74 68 65 20 numbers on the
1770: 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 20 28 70 65 command line (pe
1780: 72 68 61 70 73 20 75 73 65 20 5b 67 65 74 6f 70 rhaps use [getop
1790: 74 5d 28 68 74 74 70 3a 2f 2f 67 69 74 68 75 62 t](http://github
17a0: 2e 63 6f 6d 2f 6a 63 6f 6d 65 6c 6c 61 73 2f 67 .com/jcomellas/g
17b0: 65 74 6f 70 74 29 3f 29 0a 2d 20 55 73 65 20 74 etopt)?).- Use t
17c0: 75 70 6c 65 73 20 69 6e 73 74 65 61 64 20 6f 66 uples instead of
17d0: 20 6c 69 73 74 73 20 77 68 65 72 65 20 69 74 20 lists where it
17e0: 6d 61 6b 65 73 20 73 65 6e 73 65 0a makes sense.