This commit is contained in:
Matthew Ramirez 2022-08-09 12:06:14 +08:00 committed by GitHub
commit a2f617ec01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 125 additions and 0 deletions

20
ruby/fucking_coffee.rb Executable file
View File

@ -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

34
ruby/hangover.rb Executable file
View File

@ -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}"

39
ruby/kumar_asshole.rb Executable file
View File

@ -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

32
ruby/smack_my_bitch_up.rb Executable file
View File

@ -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}"