Skip to content

Instantly share code, notes, and snippets.

@PotHix
Forked from fnando/achievements.rb
Created October 3, 2010 02:52
Show Gist options
  • Save PotHix/608218 to your computer and use it in GitHub Desktop.
Save PotHix/608218 to your computer and use it in GitHub Desktop.
class Achievement
WEIGHT = 100
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
module BashHistory
extend self
def lines
@lines ||= File.open(File.expand_path("~/.bash_history")).readlines.collect(&:chomp).collect {|l| l.gsub(/\s+/, " ")}
end
def select(regex)
lines.select {|line| line =~ regex}
end
def count(regex)
select(regex).size
end
end
achieve "It's me, Mario!" do
description "Using lots of pipes"
condition { BashHistory.count(/|/) > WEIGHT * 3.0 }
end
achieve "The Jeweler" do
description "Heavy user of RubyGems"
condition { BashHistory.count(/^gem install/) > WEIGHT * 3.0 }
end
achieve "The Machinist" do
description "Ruby on Rails developer"
condition { BashHistory.count(/^rails new/) > WEIGHT * 0.3 }
end
achieve "The Archaeologist" do
description "Digging into git-log"
condition { BashHistory.count(/^git log/) > WEIGHT * 1.0 }
end
achieve "The Gold Miner" do
description "When grep is your picktool"
condition { BashHistory.count(/| ?grep\b/) > WEIGHT * 3.0 }
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 /) > WEIGHT * 1.5 }
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)/) > WEIGHT * 1.5 }
end
achieve "The Psychopath" do
description "Killing processes is your specialty"
condition { BashHistory.count(/kill -(9|SIGKILL)/) > WEIGHT * 1.0 }
end
achieve "The Seeker" do
description "You're always looking for something"
condition { BashHistory.count(/^find /) > WEIGHT * 1.0 }
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 /) > WEIGHT * 1.5 }
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/) > WEIGHT * 1.0 }
end
achieve "Oldschool sound configurator" do
description "I don't like this graphical interfaces"
condition { BashHistory.count(/alsamixer /) > WEIGHT * 0.05 }
end
achieve "VI master" do
description "You can edit all texts with THE ONE unix editor"
condition { BashHistory.count(/(vi|vim) /) > WEIGHT * 1.0 }
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