CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/dev/set_binary_encoding.rb
Views: 1904
1
#!/usr/bin/env ruby
2
# -*- coding: binary -*-
3
4
str = '# -*- coding: binary -*-'
5
6
fname = ARGV.shift || exit
7
data = ''
8
done = nil
9
fd = ::File.open(fname, "rb")
10
fd.each_line do |line|
11
if line =~ /^#.*coding:.*/
12
done = true
13
end
14
15
if not done
16
unless line =~ /^#\!.*env ruby/
17
data << str + "\n"
18
done = true
19
end
20
end
21
22
data << line
23
end
24
fd.close
25
26
fd = ::File.open(fname, "wb")
27
fd.write(data)
28
fd.close
29
30