Skip to content

Instantly share code, notes, and snippets.

@Tho85
Created March 30, 2011 10:27
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 Tho85/894178 to your computer and use it in GitHub Desktop.
Save Tho85/894178 to your computer and use it in GitHub Desktop.
require "set"
def all_chars_in_file(file)
all_chars = Set.new
File.open(file).each_line do |line|
line.chars.inject(all_chars) { |s,c| s << c }
end
all_chars
end
def all_utf8_chars_in_file(file)
Hash[all_chars_in_file(file).select { |c| c.ord > 255 }.map{|c| ['u%04x' % c.ord, c]}]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment