Advertisement
Jessehz

histogram.rb

Sep 11th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. stream = File.new(ARGV.shift) rescue abort("Where's the file?")
  2. patterns = Array.new(256, 0)
  3. buffer = String.new
  4. size = stream.size
  5. blksize = stream.stat.blksize*256
  6. while stream.read(blksize, buffer)
  7.     buffer.bytes do |byte|
  8.         patterns[byte] += 1
  9.     end
  10. end
  11. patterns.each.with_index do |x, index|
  12.     puts("#" * (x.to_i.fdiv(size)*10000))
  13. end
  14. #patterns.each.with_index do |x, index|
  15.     #char = (index < 127 and index > 31 and index or 32).chr
  16.     #puts "%03d   %s   %02d   %f" % [index, char, x.to_i, x.to_i.fdiv(size)]
  17. #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement