-
Notifications
You must be signed in to change notification settings - Fork 1
/
aux.rb
63 lines (50 loc) · 884 Bytes
/
aux.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'logger'
LOG = Logger.new(STDOUT)
### AUX classes ###
class Stopwatch
def initialize
start
end
def start
@t0 = Time.now
end
def end
@t1 = Time.now
@t1 - @t0
end
def self.ts
Time.now.to_i.to_s
end
def self.ts2
t=Time.new.to_i.to_s
[t.slice(0..6), t.slice(7..-1)]
end
end
class Util
def self.hexsha512 str
Digest::SHA512::hexdigest str
end
def self.sha512 str
Digest::SHA512::digest str
end
def self.hexsha384 str
Digest::SHA384::hexdigest str
end
def self.sha384 str
Digest::SHA384::digest str
end
def self.log str, error_level=1
@@counter ||=0
str="" if str.nil?
str = Time.now.to_s + "|" + (@@counter+=1).to_s+ "|" + str
if error_level > 1
LOG.warn str
else
LOG.info str
end
end
def self.exit
self.log "exiting..."
exit 0
end
end