Skip to content

Instantly share code, notes, and snippets.

View theareba's full-sized avatar

Victor Areba theareba

View GitHub Profile
class VideoAttachment < Attachment
validate :file_codec_validation, if: :new_record?
# Checks video file Codec format for Instagram
# Fails if not HEVC or H264
# @see https://developers.facebook.com/docs/instagram-api/reference/ig-user/media#video-specifications
# @see https://github.com/ruby-av/av/blob/master/lib/av/commands/base.rb
def file_codec_validation
ffmpeg = `if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi`
av_probe = `if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi`
validate :file_codec_validation, if: :new_record?
# Checks video file Codec format for Instagram
# Fails if not HEVC or H264
# @see https://developers.facebook.com/docs/instagram-api/reference/ig-user/media#video-specifications
# @see https://github.com/ruby-av/av/blob/master/lib/av/commands/base.rb
def file_codec_validation
ffmpeg = `if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi`
av_probe = `if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi`
user = User.find 151778
stakeholder = user.stakeholder
em_subscription = EnterpriseManager::Subscription.find 2
# Add user as manager of all EM gaggles
em_subscription.organizations.each do |organization|
organization.managers.find_or_create_by(user: user, role: "admin")
end
# Add user as member of all EM gaggles
1. All Star Dodge Chrysler Jeep Ram
-not found
2. Fisher Chrysler Dodge Jeep Ram Fiat
89306
89859
3. Stan McNabb Chrysler Dodge Jeep Ram Fiat
89433
89872
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
METRICS = %w[post_impressions_organic_unique]
METRIC_ID_REGEX = %r{\/insights\/(\S+)\/lifetime}
facebook_handlers = [Activity::FacebookMessage, Activity::FacebookPhoto, Activity::FacebookVideo, Activity::FacebookReShare]
eligible_message_statuses = SMS.shared.joins(:message)
.where.not(share_id: nil)
.where(messages: { handler_type: facebook_handlers })
.where(SMS.arel_table[:shared_at].gteq('1/1/2019'.to_datetime))
queued_smses = []
eligible_message_statuses.find_each do |sms|
@theareba
theareba / gaggles_merger.rb
Created September 27, 2019 12:08
Merging Gaggles 4441 & 5892
# 1. Add "ZS Marketing" and "ZS Employer Branding" Tags to Gaggle 4441
new_organization = Organization.find(4441)
marketing_tag = Tag.find_by(organization_id: 4441, name: 'ZS Employer Branding') # ZS Marketing tag already exists
branding_tag = Tag.create(organization_id: 4441, name: 'ZS Employer Branding') # create ZS Employer Branding tag
# 2. Tag all current Members in Gaggle 4441 with “ZS Marketing”
new_organization.stakeholders.includes(:tags).each do |s|
next if s.tags.include? marketing_tag
marketing_tag.stakeholders << s
end
# 1. Add "ZS Marketing" and "ZS Employer Branding" Tags to Gaggle 4441
new_organization = Organization.find(4441)
marketing_tag = Tag.find_by(organization_id: 4441, name: 'ZS Employer Branding') # ZS Marketing tag already exists
branding_tag = Tag.create(organization_id: 4441, name: 'ZS Employer Branding') # create ZS Employer Branding tag
# 2. Tag all current Members in Gaggle 4441 with “ZS Marketing”
new_organization.stakeholders.includes(:tags).each do |s|
next if s.tags.include? marketing_tag
marketing_tag.stakeholders << s
end
### Contacts Table Migration
class CreateHubspotContacts < ActiveRecord::Migration[5.2]
def change
create_table :hubspot_contacts, id: false do |t|
t.string :contact_id
t.string :first_name,
t.string :last_name,
t.string :email,
t.string :contact_source,
t.string :lifecycle_stage,
User.find_each do |user|
next if user.email == user.email.downcase
user.email = user.email.downcase
user.skip_reconfirmation!
user.save(validate: false)
end