Last active
December 27, 2015 21:09
-
-
Save jonelf/7389882 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Outputs the top 10 most used commands. | |
# Usage: | |
# history | ruby top10.rb | |
require 'Set' | |
excluded_commands = Set.new ["ls", "cd ..", "irb", "exit"] | |
distribution = Hash.new(0) | |
ARGF.each do |line| | |
command = line.match(/[\s\d]*(\D.*)/)[1].strip | |
distribution[command] += 1 unless excluded_commands.include? command | |
end | |
sorted = Hash[distribution.sort_by{|k, v| v}.reverse] | |
sorted.first(10).each do |key, value| | |
puts "#{value}: #{key}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment