Skip to content

Instantly share code, notes, and snippets.

@stanBienaives
Created September 27, 2013 14:48
Show Gist options
  • Save stanBienaives/6729778 to your computer and use it in GitHub Desktop.
Save stanBienaives/6729778 to your computer and use it in GitHub Desktop.
Simple ruby script to spot encoding errors on a given in params.
#!/usr/bin/env ruby
file = ARGV.first
count = %x( wc -l #{file}).split.first.to_i
puts "Number of line in the file: #{count}"
min = 0
max = count
while max - min > 2
n = (max + min)/2
%x( tail -n +#{n} #{file} > tmp)
error = %x( file --mime tmp).gsub(/.*charset=([^ ]*).*/, '\1').chomp == 'binary'
puts "#{n}"
error ? min = n : max = n
end
puts ""
if n > 1
puts "Error spotted on line: #{n}"
puts ""
puts "Run this script again to spot mode encoding errors"
else
puts "no errors spotted"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment