Skip to content

Instantly share code, notes, and snippets.

@fnando
Created September 28, 2010 20:41
Show Gist options
  • Save fnando/601738 to your computer and use it in GitHub Desktop.
Save fnando/601738 to your computer and use it in GitHub Desktop.
class Achievement
class << self
attr_accessor :all
end
self.all = []
attr_accessor :badge
def initialize(badge)
@badge = badge
end
def description(*args)
@description = args.first unless args.empty?
@description
end
def condition(&block)
@valid = block.call
end
def valid?
!!@valid
end
end
def achieve(badge, &block)
Achievement.all << Achievement.new(badge).tap do |a|
a.instance_eval(&block)
end
end
class BashHistory
def self.lines
@lines ||= File.open(File.expand_path("~/.bash_history")).readlines.collect(&:chomp).collect {|l| l.gsub(/\s+/, " ")}
end
def self.select(regex)
lines.select {|line| line =~ regex}
end
def self.count(regex)
select(regex).size
end
end
achieve "It's me, Mario!" do
description "Using lots of pipes"
condition { BashHistory.count(/|/) > 300 }
end
achieve "The Jeweler" do
description "Heavy user of RubyGems"
condition { BashHistory.count(/^gem install/) > 300 }
end
achieve "The Machinist" do
description "Ruby on Rails developer"
condition { BashHistory.count(/^rails new/) > 30 }
end
achieve "The Archaeologist" do
description "Digging into git-log"
condition { BashHistory.count(/^git log/) > 100 }
end
achieve "The Gold Miner" do
description "When grep is your picktool"
condition { BashHistory.count(/| ?grep\b/) > 300 }
end
achieve "I'm a Mac" do
description "You're running Mac OS X"
condition { RUBY_PLATFORM =~ /darwin/ }
end
achieve "The Rubyist" do
description "Running an old Ruby version"
condition { BashHistory.count(/^ruby /) > 150 }
end
achieve "The Old Fashion Rubyist" do
description "Running an old Ruby version"
condition { RUBY_VERSION < "1.8.7" }
end
achieve "The Tester" do
description "Writing tested code is the way to go!"
condition { BashHistory.count(/^rake (spec|test)/) > 150 }
end
achieve "The Psychopath" do
description "Killing processes is your specialty"
condition { BashHistory.count(/kill -(9|SIGKILL)/) > 100 }
end
achieve "The Seeker" do
description "You're always looking for something"
condition { BashHistory.count(/^find /) > 100 }
end
achieve "Web addicted" do
description "Lynx? Really?"
condition { BashHistory.count(/^lynx /).nonzero? }
end
achieve "The Pythonist" do
description "The Zen of Python is your mantra"
condition { BashHistory.count(/^python /) > 150 }
end
achieve "The Ubuntu Guy" do
description %[Ubuntu is an ancient african word, meaning "I can't configure Debian"]
condition { `cat /etc/issue 2> /dev/null` =~ /Ubuntu/ }
end
achieve "The Pr0n collector" do
description "*fap* *fap* *fap*"
condition { BashHistory.count(/wget .*?\.(porn|sex)/).nonzero? }
end
achieve "It wasn't me!" do
description "Pointing your finger to everyone with git-blame"
condition { BashHistory.count(/git blame/) > 100 }
end
Achievement.all.each do |a|
next unless a.valid?
puts "#{a.badge}, #{a.description}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment