tilde.news/extras/utils.rb
Peter Bhat Harkins bf1885d87c rubocop: Style/SymbolProc, 374
There were 18 &:foo and 19 {|x| x.foo}, so I updated to the new idiom.
2018-03-18 01:07:08 -05:00

30 lines
674 B
Ruby

class Utils
def self.random_str(len)
str = ""
while str.length < len
chr = OpenSSL::Random.random_bytes(1)
ord = chr.unpack('C')[0]
# 0 9 A Z a z
if (ord >= 48 && ord <= 57) || (ord >= 65 && ord <= 90) || (ord >= 97 && ord <= 122)
str += chr
end
end
return str
end
def self.silence_stream(*streams)
on_hold = streams.collect(&:dup)
streams.each do |stream|
stream.reopen("/dev/null")
stream.sync = true
end
yield
ensure
streams.each_with_index do |stream, i|
stream.reopen(on_hold[i])
end
end
end