X-Git-Url: http://git.hcoop.net/bpt/portal.git/blobdiff_plain/aaa50197ad95b7f5e3aca4293ec4f0201e0f30fc..64ec9551fc56c42188e195cbbe24c79ad18b293f:/util.sml diff --git a/util.sml b/util.sml index a9ed02b..07793bb 100644 --- a/util.sml +++ b/util.sml @@ -29,12 +29,13 @@ fun makeSet f items = fun neg (r : real) = ~r fun add (r1 : real, r2) = r1 + r2 +fun sub (r1 : real, r2) = r1 - r2 fun mult (r1, r2) = real r1 * r2 fun isIdent ch = Char.isLower ch orelse Char.isDigit ch orelse ch = #"-" fun validHost s = - size s > 0 andalso size s < 20 andalso List.all isIdent (String.explode s) + size s > 0 andalso size s < 40 andalso List.all isIdent (String.explode s) fun validDomain s = size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s) @@ -64,7 +65,7 @@ fun init () = rnd := Random.rand (SysWord.toInt (Posix.Process.pidToWord (Posix. fun randomPassword () = Int.toString (Int.abs (Random.randInt (!rnd))) fun domainDir dom = - String.concatWith "/" ("/etc/domains" :: String.fields (fn ch => ch = #".") dom) + String.concatWith "/" ("/afs/hcoop.net/common/etc/domtool/nodes/deleuze" :: List.rev (String.fields (fn ch => ch = #".") dom)) fun readFile fname = let @@ -81,4 +82,28 @@ fun readFile fname = fun mem (x, ls) = List.exists (fn y => y = x) ls +val allLower = CharVector.map Char.toLower + +fun normEmail s = case String.tokens Char.isSpace (allLower s) of + s :: _ => s + | [] => "" + +val s_cutoff = LargeInt.fromInt 60 +val m_cutoff = LargeInt.fromInt (60 * 60) +val h_cutoff = LargeInt.fromInt (60 * 60 * 24) + +fun diffFromNow t = + let + val secs = Time.toSeconds (Time.- (Time.now (), t)) + in + if LargeInt.< (secs, s_cutoff) then + LargeInt.toString secs ^ " seconds" + else if LargeInt.< (secs, m_cutoff) then + LargeInt.toString (LargeInt.div (secs, s_cutoff)) ^ " minutes" + else if LargeInt.< (secs, h_cutoff) then + LargeInt.toString (LargeInt.div (secs, m_cutoff)) ^ " hours" + else + LargeInt.toString (LargeInt.div (secs, h_cutoff)) ^ " days" + end + end