Skip to content

Instantly share code, notes, and snippets.

@lesleh
Last active August 18, 2017 22:18
Show Gist options
  • Save lesleh/113e484e1f31eebeb5e35237ed68c174 to your computer and use it in GitHub Desktop.
Save lesleh/113e484e1f31eebeb5e35237ed68c174 to your computer and use it in GitHub Desktop.
Count the number of occurrences of each unicode character in a bunch of files
require 'json'
all_chars = {}
Dir["**/*.md"].each do |file|
character_data = IO.read(file).each_char.each_with_object(Hash.new(0)) do |word,counts|
counts[word] += 1
end
all_chars.merge!(character_data) do |_, oldval, newval|
oldval + newval
end
end
all_chars.sort_by {|_key, value| value}.reverse.each do |x|
puts "#{x[0]} - #{x[1]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment