Skip to content

Instantly share code, notes, and snippets.

@jonelf
Last active December 27, 2015 21:09
Show Gist options
  • Save jonelf/7389882 to your computer and use it in GitHub Desktop.
Save jonelf/7389882 to your computer and use it in GitHub Desktop.
# 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