Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Last active December 16, 2015 04:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelfeathers/5378227 to your computer and use it in GitHub Desktop.
Save michaelfeathers/5378227 to your computer and use it in GitHub Desktop.
Report leading whitespace in a set of files to characterize programmers' indentation conventions.
class Array
def freq_by &block
group_by(&block).map {|k,v| [k, v.count] }.sort_by(&:first)
end
def freq
freq_by {|e| e }
end
end
puts ARGF.lines.map {|l| l.split(/\S/).first }
.compact
.freq
.sort_by {|p,c| -c }
.map {|p,c| "%5d %2d: %s" % [c, p.length, p.dump] }
.join($/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment