1 structure Util
:> UTIL
=
4 datatype 'a flat_element
=
8 type 'a flat_tree
= 'a flat_element list
11 Web
.print (if n
< 0 then
12 "-" ^
Int.toString (~n
)
17 Web
.print (if n
< 0.0 then
18 "-" ^
Real.fmt (StringCvt.FIX (SOME
2)) (~n
)
20 Real.fmt (StringCvt.FIX (SOME
2)) n
)
27 |
[usr
] => "(" ^ f usr ^
")"
28 | usr
::rest
=> foldl (fn (usr
, s
) => s ^
", " ^ f usr
) ("(" ^ f usr
) rest ^
")"
30 fun neg (r
: real) = ~r
31 fun add (r1
: real, r2
) = r1
+ r2
32 fun sub (r1
: real, r2
) = r1
- r2
33 fun mult (r1
, r2
) = real r1
* r2
35 fun isIdent ch
= Char.isLower ch
orelse Char.isDigit ch
orelse ch
= #
"-"
38 size s
> 0 andalso size s
< 40 andalso List.all
isIdent (String.explode s
)
41 size s
> 0 andalso size s
< 100 andalso List.all
validHost (String.fields (fn ch
=> ch
= #
".") s
)
44 size s
> 0 andalso size s
< 50 andalso List.all
45 (fn ch
=> isIdent ch
orelse ch
= #
"." orelse ch
= #
"_" orelse ch
= #
"-" orelse ch
= #
"+")
48 fun validEmailUser s
=
49 size s
> 0 andalso size s
< 50 andalso List.all
50 (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"." orelse ch
= #
"_" orelse ch
= #
"-" orelse ch
= #
"+")
54 (case String.fields (fn ch
=> ch
= #
"@") s
of
55 [user
, host
] => validEmailUser user
andalso validDomain host
58 fun whoisUrl dom
= String.concat
["http://reports.internic.net/cgi/whois?whois_nic=", dom
, "&type=domain"]
60 val rnd
= ref (Random
.rand (0, 0))
62 fun init () = rnd
:= Random
.rand (SysWord
.toInt (Posix
.Process
.pidToWord (Posix
.ProcEnv
.getpid ())),
63 SysWord
.toInt (Posix
.Process
.pidToWord (Posix
.ProcEnv
.getpid ())))
65 fun randomPassword () = Int.toString (Int.abs (Random
.randInt (!rnd
)))
68 String.concatWith
"/" ("/afs/hcoop.net/common/etc/domtool/nodes/deleuze" :: List.rev (String.fields (fn ch
=> ch
= #
".") dom
))
72 val inf
= TextIO.openIn fname
75 case TextIO.inputLine inf
of
76 NONE
=> String.concat (List.rev lines
)
77 | SOME line
=> readLines (line
:: lines
)
80 before TextIO.closeIn inf
83 fun mem (x
, ls
) = List.exists (fn y
=> y
= x
) ls
85 val allLower
= CharVector
.map
Char.toLower
87 fun normEmail s
= case String.tokens
Char.isSpace (allLower s
) of
91 val s_cutoff
= LargeInt
.fromInt
60
92 val m_cutoff
= LargeInt
.fromInt (60 * 60)
93 val h_cutoff
= LargeInt
.fromInt (60 * 60 * 24)
97 val secs
= Time
.toSeconds (Time
.- (Time
.now (), t
))
99 if LargeInt
.< (secs
, s_cutoff
) then
100 LargeInt
.toString secs ^
" seconds"
101 else if LargeInt
.< (secs
, m_cutoff
) then
102 LargeInt
.toString (LargeInt
.div (secs
, s_cutoff
)) ^
" minutes"
103 else if LargeInt
.< (secs
, h_cutoff
) then
104 LargeInt
.toString (LargeInt
.div (secs
, m_cutoff
)) ^
" hours"
106 LargeInt
.toString (LargeInt
.div (secs
, h_cutoff
)) ^
" days"