Skip to content

Instantly share code, notes, and snippets.

@fxn
Created June 15, 2023 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxn/0536772bc3b8d29561f3e9c71fda68a5 to your computer and use it in GitHub Desktop.
Save fxn/0536772bc3b8d29561f3e9c71fda68a5 to your computer and use it in GitHub Desktop.
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