Skip to content

Instantly share code, notes, and snippets.

@Narnach
Forked from FiXato/excuse.rb
Created March 12, 2009 08:45
Show Gist options
  • Save Narnach/77969 to your computer and use it in GitHub Desktop.
Save Narnach/77969 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Your random BOFH excuse calendar.
# Based upon the The Bastard Operator From Hell Stories written by Simon Paul Travaglia.
# And the list compiled by Jeff Ballard, http://jeffballard.us/
#
# Automatically downloads the excuses from http://pages.cs.wisc.edu/~ballard/bofh/excuses
# and stores them as ~/.excuses.txt for reuse.
require 'open-uri'
class Array
def rand
self[Kernel.rand(size)]
end
end
filename = File.expand_path '~/.excuses.txt'
unless File.exist?(filename)
excuses = URI.parse('http://pages.cs.wisc.edu/~ballard/bofh/excuses').read
File.open(filename,'w') {|f| f.puts(excuses)}
end
lines = File.readlines(filename)
excuse = lines.rand
# Choose one of {multiple,options}:
excuse.gsub!(/\{(.+?,.+?)\}/) {|options| options.gsub(/\{|\}/,'').split(",").rand}
puts excuse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment