/doc/report/app_code.tex

http://github.com/hhughes/ocaml-frui · LaTeX · 50 lines · 47 code · 3 blank · 0 comment · 0 complexity · 1fba2c9394934ac918a7b365426a3a88 MD5 · raw file

  1. \chapter{Code}
  2. \section{OCaml}
  3. \subsection{froc-list.ml}
  4. \label{app:froc-list}
  5. \begin{alltt}
  6. class ['a] flist =
  7. object (self)
  8. val mutable first = []
  9. val mutable last = []
  10. val mutable fs = []
  11. method lift (f : 'a -> unit) =
  12. begin
  13. let l o = ignore (Froc.lift f o) in
  14. fs <- f :: fs;
  15. List.iter l first;
  16. List.iter l (List.rev last)
  17. end
  18. method lift_all o =
  19. begin
  20. let l f = ignore (Froc.lift f o) in
  21. List.iter l fs
  22. end
  23. method list = List.rev_append (List.rev first) (List.rev last)
  24. method push o = self#lift_all o; first <- o :: first
  25. method push_end o = self#lift_all o; last <- o :: last
  26. method pop = let hd = List.hd first in first <- List.tl first; hd
  27. method pop_end = let hd = List.hd last in last <- List.tl last; hd
  28. end
  29. \end{alltt}
  30. \section{JavaScript}
  31. \section{Shell}
  32. \subsection{get-world-bank-data.sh}
  33. \label{app:data}
  34. \begin{alltt}
  35. #!/bin/sh
  36. if [ "\$1" = "gdp" ]
  37. then
  38. OUT="gdp"
  39. URL="http://api.worldbank.org/countries/all/indicators/NY.GDP.MKTP.CD"
  40. else
  41. OUT="life"
  42. URL="http://api.worldbank.org/countries/all/indicators/SP.DYN.LE00.IN"
  43. fi
  44. for n in \$(seq 1 245)
  45. do wget -O \${OUT}-\${n}.json \${URL}?format=json\&per_page=50\&page=\${n} && sleep 5
  46. done
  47. \end{alltt}