This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### BEST SOLUTION I HAVE SO FAR (unrealistic to acheive on first try) | |
# SUPER DRY'd up way of testing both techniques | |
def divide(x, y, technique='multiply') | |
sign = (x < 0 && y > 0 || x > 0 && y < 0) ? -1 : 1 | |
x, y = x.abs, y.abs | |
return 0 if x == 0 || y == 0 || y > x | |
return sign * 1 if x == y | |
i = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project_id = 69 # replace with project id | |
login_ids = [332, 331, 133, 267, 119, 249, 251, 250] # replace with assignee login ids | |
batch_size = 300 # replace with batch size | |
pi_ids = PunchItem.where(project_id: project_id).where("deleted_at IS NULL").pluck(:id) | |
already_used_ids = PunchItemAssignment.where(punch_item_id: pi_ids).pluck(:punch_item_id) | |
pi_ids = (pi_ids - already_used_ids).shuffle | |
idx = 0 | |
PunchItem.includes(:punch_item_assignments).where(id: pi_ids).find_each(batch_size: batch_size) do |pi| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SteemPostBroadcaster | |
attr_accessor :options | |
def initialize(opts={}) | |
@options = opts | |
end | |
def post! | |
raise "Post is missing title, body, or tags" unless is_valid_post? | |
account.post!(post_options) unless ENV['DISABLE_AUTO_POSTING'].to_boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SteemPercentage | |
extend ActiveSupport::Concern | |
STEEM_MAX_PERCENT = 10000.0 | |
# converts to [0.0-1.0] => percent_decimal(8000) == 0.8 | |
def percent_decimal(num) | |
num.to_f / STEEM_MAX_PERCENT | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'radiator' | |
class SteemPostFinder | |
# the max results we can return for a single API query | |
BATCH_SIZE = 100 | |
def initialize(tag_name) | |
@tag_name = tag_name | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget.where(id: child_widget_ids).index_by(&:id).values_at(*child_widget_ids).squish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RISK_FACTORS = { | |
"Senior-Living": 32, | |
"Apartments": 15, | |
"Self-Storage": 20, | |
"Veterinarian": 9 | |
}.freeze | |
def clients_by_vertical_and_location_count(vertical, g5_internal=false) | |
Client.where(vertical: vertical) | |
.where(g5_internal: g5_internal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dups = Website.all.inject({}) { |h,w| h[w.owner_id] ||= 0; h[w.owner_id] += 1; h }.reject! { |k,v| v <= 1 } | |
bad_webs = Website.where(owner_id: dups.keys).all.sort_by(&:name) | |
bad_files = bad_webs.inject({}) do |h, w| | |
file_name = "#{w.id}-#{w.name.parameterize}" | |
mgr = Saves::WebsiteSavesManager.new("[email protected]", w.owner) | |
file_path = mgr.send(:create_save_file, file_name) | |
s3 = S3Bucket.new(w.owner, {s3_folder: 'websites-saves'}) | |
file = s3.upload(file_path, file_name) | |
h[w.id] = { owner_id: w.owner_id, file: s3.bucket_file_url(file_name) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
widgets = Widget.includes(:garden_widget, :settings).by_name('Phone Number').all | |
settings = widgets.map { |w| w.settings.where_name('phone_number').all }.squish.select { |s| s.value.present? && && s.value != "{{location_phone_number}}" } | |
ret = settings.inject("") { |str, s| str << "- #{s.website.name} (#{s.website.owner.urn}) - #{s.website.status}): #{s.value}\n"; str } | |
puts "#{Client.client.name} (#{Client.client.urn}):\n#{ret}\n" unless ret.blank? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_multi_website_locations | |
Location.all.select { |l| Website.where(owner_id: l.id).count > 1 } | |
end |
NewerOlder