mirror of
https://github.com/tildeverse/lobsters
synced 2024-06-14 13:06:41 +00:00
28c8217652
* Upgrade to rails 5.1 - Update versions of dependencies - Switch before_filter to before_action - Use render plain rather than render text * Generate new rails 5.1 scripts
30 lines
690 B
Ruby
30 lines
690 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 {|stream| stream.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
|