Skip to content

Instantly share code, notes, and snippets.

View thescubageek's full-sized avatar
🤿
Are you for scuba?

Steve Craig thescubageek

🤿
Are you for scuba?
  • @evidation
  • Wilmington, NC
View GitHub Profile
@thescubageek
thescubageek / repair_drop_targets.rb
Created September 14, 2016 18:38
Repairs bad drop targets for CMS
def repair_drop_targets(html_id, widgets=[])
bad = Website.all.select do |web|
!web.website_template.blank? && (
web.website_template.drop_targets.find_by_html_id(html_id).blank? ||
web.website_template.drop_targets.find_by_html_id(html_id).widgets.blank?)
end
bad.each do |web|
wt = web.website_template
dt = wt.drop_targets.find_by_html_id(html_id)
class Array
def to_file(filepath, sep="\n")
File.open(filepath, 'w') { |f| f.write(join(sep)) } unless blank?
end
def squash
blank? ? [] : flatten.compact.uniq
end
end
## G5 Hub
def get_urn(url)
url.gsub("https://","").gsub(".herokuapp.com","")
end
## Find all internal clients
Client.where(g5_internal: true).map { |c| get_urn(c.cms_url) }
## Find all real clients
@thescubageek
thescubageek / find_matching_settings.rb
Last active September 14, 2016 22:01
Finds settings (and corresponding owners) matching string pattern
## G5 Content Management System
def find_setting_value(target)
Setting.where(Setting.arel_table[:value].matches("%#{target}%"))
end
def find_setting_value_widgets(target)
find_setting_value(target).map do |setting|
setting.owner
end.uniq
@thescubageek
thescubageek / reseed_websites_missing_website_templates.rb
Last active September 6, 2016 14:10
Reseeds websites missing website_templates
## G5 Content Management System
Website.all.select { |web| web.website_template.blank? }.each do |web|
WebsiteSeederJob.perform_async(web.owner.id)
end
@thescubageek
thescubageek / array_to_file.rb
Created August 8, 2016 21:31
Array to File
def array_to_file(arr, file)
File.open(file, 'w') { |f| f.write(arr.join("\n")) } unless arr.blank?
end
@thescubageek
thescubageek / file_to_array.rb
Created February 17, 2016 16:33
File to Array - Ruby
def file_to_array(file)
arr = []
if File.exists?(file)
f = File.read(file)
f.each_line { |line| arr << line.strip unless line == "\n" }
end
arr
end