Skip to content

Instantly share code, notes, and snippets.

View mattfitzgerald's full-sized avatar

Matt Fitzgerald mattfitzgerald

View GitHub Profile
def calculate_downtime_minutes
check_id = 387085
user = "***"
pass = "***"
key = "***"
today = DateTime.now.to_date
last_sunday = today - today.wday
# sort an array with one known special value first.
# so given
arr = [{:val => 23},{:val => 46},{:val => 65464},{:val => 33},{:val => 50}]
# sort the array so {:val => 33} is first and the rest are ordered by their :val vlaues.
def SqsTest.send_batch_of_long_messages
IntegrationTest.print_test_name "SqsTest.send_batch_of_long_messages"
SqsTest.before_each
sqs_client = Client.find_by_name "sqs_client"
sqs = RightAws::SqsGen2.new(sqs_client.access_key_id, sqs_client.secret_access_key)
sqs_queue = RightAws::Sqs::Queue.create(sqs, sqs_client.sqs_input_queue)
# calculates e
e = (1..20).inject(1){|e,n| e + 1.0/((1..n).inject(:*))}
def convert_time_safely time_input
begin
return nil if time_input.to_i == 0
Time.at(time_input.to_i/1000)
rescue
return nil
end
end
puts "10000 -> #{convert_time_safely(10000)}"
# in a module
def SmsExchange.convert_time_safely_from_int_millis input
begin
return nil if input.to_i == 0
Time.at(input.to_i/1000)
rescue
return nil
end
describe "modify_value" do
before(:all) do
@field = mock_account.database.fields.find_by_system_name('date_of_birth')
end
it "should not accept integer only dates" do
@field.modify_value('1').should == nil
end
# find messages triggered as self generating delayed jobs that have no job and setup
AnniversaryMessage.find_all_by_enabled(true).select{|am| AnniversaryMessageSchedulerDelayedAction.currently_enqueued_for(am).empty?}.each{|m| m.setup_delayed_job}
BirthdayMessage.find_all_by_enabled(true).select{|bm| BirthdayMessageSchedulerDelayedAction.currently_enqueued_for(bm).empty?}.each{|m| m.setup_delayed_job}
AnnualPlannerMessage.find_all_by_enabled(true).select{|apm| AnniversaryMessageSchedulerDelayedAction.currently_enqueued_for(apm).empty?}.each{|m| m.setup_delayed_job}
OngoingCampaign.find_all_by_enabled(true).select{|om| OngoingMessageSchedulerDelayedAction.currently_enqueued_for(om).empty?}.each{|m| m.setup_delayed_job}
# in the console I see this
>> d.modify_value("123")
FieldType::CriterionConversionError: Unable to parse "123" as a date, giving up
from ./lib/field_types/date.rb:104:in `modify_value'
from (irb):4
# in the spec this
file = File.new("message_process.txt", "r")
id_counts = {}
while (line = file.gets)
id = line.split[-2].split(":")[1].chop
if id_counts.has_key? id
id_counts[id] += 1
else