Skip to content

Move the Ruby implementation #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ruby/fucking_coffee.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions ruby/hangover.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions ruby/kumar_asshole.rb
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'

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 changes: 32 additions & 0 deletions ruby/smack_my_bitch_up.rb
Original file line number Diff line number Diff line change
@@ -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}"