-
-
Save Narnach/77969 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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