Created
June 15, 2023 12:24
-
-
Save fxn/0536772bc3b8d29561f3e9c71fda68a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'find' | |
require 'ptools' | |
frequencies = Hash.new(0) | |
Find.find('.') do |path| | |
basename = File.basename(path) | |
if basename.start_with?('.') | |
Find.prune if basename == '.git' | |
next | |
end | |
next if File.directory?(path) | |
next if File.binary?(path) | |
contents = File.read(path) | |
# ptools is letting some PNGs pass. | |
next unless contents.valid_encoding? | |
contents.each_char do |char| | |
next if char.match?(/\s|[a-zA-Z0-9]/) | |
frequencies[char] += 1 | |
end | |
end | |
pp frequencies.sort_by { -_2 }[0, 20] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment