diff --git a/ruby/fucking_coffee.rb b/ruby/fucking_coffee.rb new file mode 100755 index 00000000..69a85ab1 --- /dev/null +++ b/ruby/fucking_coffee.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +# Exit early if no sessions with my username are found +exit unless `who -q`.include? ENV['USER'] + +require 'net/telnet' + +coffee_machine_ip = '10.10.42.42' +password = '1234' +password_prompt = 'Password: ' +delay_before_brew = 17 +delay = 24 + +sleep delay_before_brew +con = Net::Telnet.new('Host' => coffee_machine_ip) +con.cmd('String' => password, 'Match' => /#{password_prompt}/) +con.cmd('sys brew') +sleep delay +con.cmd('sys pour') +con.close diff --git a/ruby/hangover.rb b/ruby/hangover.rb new file mode 100755 index 00000000..8578aaf8 --- /dev/null +++ b/ruby/hangover.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby + +# Exit early if sessions with my username are found +exit if `who -q`.include? ENV['USER'] + +require 'dotenv' +require 'twilio-ruby' + +Dotenv.load + +TWILIO_ACCOUNT_SID = ENV['TWILIO_ACCOUNT_SID'] +TWILIO_AUTH_TOKEN = ENV['TWILIO_AUTH_TOKEN'] + +@twilio = Twilio::REST::Client.new TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN + +# Phone numbers +my_number = '+xxx' +number_of_boss = '+xxx' + +excuse = [ + 'Locked out', + 'Pipes broke', + 'Food poisoning', + 'Not feeling well' +].sample + +# Send a text message +@twilio.messages.create( + from: my_number, to: number_of_boss, + body: "Gonna work from home. #{excuse}" +) + +# Log this +puts "Message sent at: #{Time.now} | Excuse: #{excuse}" diff --git a/ruby/kumar_asshole.rb b/ruby/kumar_asshole.rb new file mode 100755 index 00000000..0dc5cb7c --- /dev/null +++ b/ruby/kumar_asshole.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby + +require 'dotenv' +require 'gmail' + +Dotenv.load + +GMAIL_USERNAME = ENV['GMAIL_USERNAME'] +GMAIL_PASSWORD = ENV['GMAIL_PASSWORD'] + +GMAIL = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD) +KUMARS_EMAIL = 'kumar.a@example.com' + +DB_NAME_REGEX = /\S+_staging/ +KEYWORDS_REGEX = /sorry|help|wrong/i + +def create_reply(subject) + GMAIL.compose do + to KUMARS_EMAIL + subject "RE: #{subject}" + body "No problem. I've fixed it. \n\n Please be careful next time." + end +end + +GMAIL.inbox.find(:unread, from: KUMARS_EMAIL).each do |email| + if email.body.raw_source[KEYWORDS_REGEX] && (db_name = email.body.raw_source[DB_NAME_REGEX]) + backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz' + abort 'ERROR: Backup file not found' unless File.exist?(backup_file) + + # Restore DB + `gunzip -c #{backup_file} | psql #{db_name}` + + # Mark as read, add label and reply + email.read! + email.label('Database fixes') + reply = create_reply(email.subject) + GMAIL.deliver(reply) + end +end diff --git a/ruby/smack_my_bitch_up.rb b/ruby/smack_my_bitch_up.rb new file mode 100755 index 00000000..b81a3349 --- /dev/null +++ b/ruby/smack_my_bitch_up.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby + +# Exit early if no sessions with my username are found +exit unless `who -q`.include? ENV['USER'] + +require 'dotenv' +require 'twilio-ruby' + +Dotenv.load + +TWILIO_ACCOUNT_SID = ENV['TWILIO_ACCOUNT_SID'] +TWILIO_AUTH_TOKEN = ENV['TWILIO_AUTH_TOKEN'] + +@twilio = Twilio::REST::Client.new TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN + +# Phone numbers +my_number = '+xxx' +her_number = '+xxx' + +reason = [ + 'Working hard', + 'Gotta ship this feature', + 'Someone fucked the system again' +].sample + +# Send a text message +@twilio.messages.create( + from: my_number, to: her_number, body: "Late at work. #{reason}" +) + +# Log this +puts "Message sent at: #{Time.now} | Reason: #{reason}"