Skip to content

Instantly share code, notes, and snippets.

@atsmith813
atsmith813 / update_todays_birthdays.rb
Last active November 6, 2019 18:00
Update today's birthdays to be 1 year in the future
# Continuing with the birthdays, todays_birthdays, session, spreadsheet, and ws objects created above...
(1..ws.num_rows).each do |row|
name = ws[row, 1]
birthday = todays_birthdays.find { |bday| bday[:name] == name }
next unless birthday
next_birthday = birthday[:date].next_year.to_s
ws[row, 2] = next_birthday
@atsmith813
atsmith813 / send_text_of_todays_birthdays.rb
Last active November 6, 2019 04:26
Send text of today's birthdays
# Continuing with the birthdays object created above...
todays_birthdays = birthdays.select { |birthday| birthday[:date] == Date.today }
account_sid = TWILIO_ACCOUNT_SID # Your Twilio phone number
auth_token = TWILIO_AUTH_TOKEN # Your Twilio auth token
client = Twilio::REST::Client.new(account_sid, auth_token)
from = '+11234567890' # Your Twilio number
to = '+10987654321' # Your mobile phone number
@atsmith813
atsmith813 / export_from_google_sheets.rb
Last active November 6, 2019 04:25
Export birthdays from Google Sheets
# Continuing with the birthdays, session, spreadsheet, and ws objects created above...
birthdays = []
(1..ws.num_rows).each do |row|
name = ws[row, 1]
date = Date.parse(ws[row, 2])
birthdays << { name: name, date: date}
end
@atsmith813
atsmith813 / import_to_google_sheets.rb
Last active November 6, 2019 04:25
Import birthdays from .ics file to Google Sheets
# Continuing with the birthdays object created above...
# Initiate and authenticate a Google Drive session
session = GoogleDrive::Session.from_service_account_key('client_secret.json')
# Open our birthday_bot spreadsheet
spreadsheet = session.spreadsheet_by_name('birthday_bot')
# Select the first worksheet in the spreadsheet
ws = spreadsheet.worksheets.first
@atsmith813
atsmith813 / import_birthdays.rb
Last active November 6, 2019 04:24
Import .ics file
require 'date'
# This will be the name of your .ics file in the root directory
file_name = 'birthdays.ics'
cal = File.read(file_name).split("BEGIN:VEVENT")
cal.shift # First row is meta data from export
birthdays = []
@atsmith813
atsmith813 / textract.rb
Last active October 23, 2019 23:16
AWS Textract
# continuing from above with s3_image
client = Aws::Textract::Client.new
resp = client.analyze_document({
document: { s3_object: { bucket: ENV['AWS_BUCKET'], name: s3_image.key } },
feature_types: ['TABLES']
})
@atsmith813
atsmith813 / s3.rb
Last active October 23, 2019 22:50
AWS Textract
# This process will upload the image to the S3 bucket
image = params[:image]
s3 = Aws::S3::Resource.new
bucket = ENV['AWS_BUCKET']
name = File.basename(file)
obj = s3.bucket(bucket).object(name)
s3_image = obj.upload_file(file)
@atsmith813
atsmith813 / Gemfile.rb
Last active October 23, 2019 22:43
AWS Textract
gem 'aws-sdk-s3', '~> 1'
gem 'aws-sdk-textract', '~> 1'
@atsmith813
atsmith813 / rubo_changes.sh
Created June 4, 2018 23:40
Run Rubocop only on Ruby files with changes
alias rubo_changes="git ls-files -m | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs rubocop"
@atsmith813
atsmith813 / open_pr.sh
Last active May 11, 2018 15:56
Open pull request from the command line.
function open_pr() {
if [ $# -eq 1 ]
then
br=$(git rev-parse --abbrev-ref HEAD)
else
br=$2
fi
open "https://github.com/$(git remote get-url origin | awk -F '[:.]' '{print $3}')/compare/$1...$br?expand=1"
}