st.ml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. let camel = "🐫"
  2. let seppo_s = "Seppo.Social"
  3. let seppo_u = Uri.make ~scheme:"https" ~host:seppo_s ()
  4. let seppo_c = "Seppo - Personal Social Web"
  5. open Astring
  6. let is_prefix = String.is_prefix
  7. let is_suffix = String.is_suffix
  8. let after ~prefix s : string option =
  9. if String.is_prefix ~affix:prefix s
  10. then Some (String.sub ~start:(String.length prefix) s
  11. |> String.Sub.to_string)
  12. else None
  13. let before ~suffix s : string option =
  14. if String.is_suffix ~affix:suffix s
  15. then Some (String.sub ~stop:((String.length s) - (String.length suffix)) s
  16. |> String.Sub.to_string)
  17. else None
  18. let updir path =
  19. match path
  20. |> String.cuts ~sep:"/"
  21. |> List.fold_left (fun (l,i) s ->
  22. match s,i with
  23. | ("",0) -> (l,0)
  24. | (_,0) -> (l,1)
  25. | (".",i) -> (l,i)
  26. | _ -> (".." :: l,i+1)) ([],0) with
  27. | [],_ -> ""
  28. | l,_ -> (l |> String.concat ~sep:"/") ^ "/"
  29. let last l =
  30. let flast _ v = v in
  31. List.fold_left flast (List.hd l) l
  32. let is_monotonous cmp l =
  33. let step (r,p) o =
  34. if (not r) || cmp p o < 0
  35. then (false,p)
  36. else (r,o)
  37. in
  38. let r,_ = List.fold_left step (true,List.hd l) l in
  39. r
  40. let window ?(size = 50) ?(page = 0) l =
  41. let mi = page * size in
  42. let ma = mi + size in
  43. l
  44. |> List.filteri (fun i _ -> mi <= i && i < ma)
  45. let pp_json_err ppf e = Format.pp_print_string ppf (e |> Ezjsonm.read_error_description)
  46. let pp_exc ppf e = Format.pp_print_string ppf (Printexc.to_string e)