Skip to content

Instantly share code, notes, and snippets.

View pythonandchips's full-sized avatar

Colin Gemmell pythonandchips

View GitHub Profile
def set_rates(end_date)
us_rates = [
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5480658613")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5522279056")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5473")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5474")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5535749501")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5484416182")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5566405175")},
{base_currency: "GBP", counter_currency: "USD", rate: BigDecimal("1.5520790022")},
@pythonandchips
pythonandchips / identify_duplicate_invoice_references.rb
Last active April 29, 2019 11:32
identify_duplicate_invoice_references.rb
def find_dup_invoice_references(file_path = "")
out = []
invoices = Invoice.non_recurring.group(:company_id, :reference).having('count(*) > 1')
invoices.each do |invoice|
invoices = Invoice.non_recurring.where(reference: invoice.reference, company_id: invoice.company_id)
invoices.each do |invoice|
out << [
invoice.company.subdomain,
invoice.company.subscription.channel,
invoice.company.subscription.account_type,
const fs = require("fs");
const puppeteer = require('puppeteer');
let convertHTMLToPDF = async (html, callback, options = null) => {
if (typeof html !== 'string') {
throw new Error(
'Invalid Argument: HTML expected as type of string and received a value of a different type. Check your request body and request headers.'
);
}
const browser = await puppeteer.launch();
@pythonandchips
pythonandchips / genrate_transactions.rb
Created August 17, 2018 10:58
generate transaction file
require 'date'
require 'securerandom'
number_of_debt_per_day = 3
number_of_credits_per_day = 3
max_value = 1000
date_range = Date.new(2018,7,1)..Date.today
lines = []
@pythonandchips
pythonandchips / job_runner.rb
Created August 15, 2018 16:06
Sledge hammer for running delayed jobs
puts "RUNNING JOBS"
while true do
puts "CHECKING FOR JOBS #{DateTime.now}"
Delayed::Job.where(failed_at: nil).each do |job|
puts "RUNNING #{ job.handler }"
begin
job.invoke_job
job.destroy
puts "COMPLETED #{ job.handler }"
rescue StandardError => ex
def restore_s3_objects(company, simulate=true)
attachments = company.attachments.map{ |a| a.attachment }
s3_client = Aws::S3::Client.new(
region: AWS_REGION,
access_key_id: AWS_ACCESS_KEY_ID,
secret_access_key: AWS_SECRET_ACCESS_KEY
)
attachments.each do |attachment|
paths = [attachment.path]
attachment.styles.keys.each do |style|
ae = AttachmentExportSummary.new(
company: c, export_name: "all_the_datas", status: "successful",
attachment_exports: [
AttachmentExport.new(export_file_name: "all_the_data.1.zip", export_file_size: 1_000_000, export_content_type: "application/zip", company: c, s3_client: S3ClientMock.new),
AttachmentExport.new(export_file_name: "all_the_data.2.zip", export_file_size: 1_000_000, export_content_type: "application/zip", company: c, s3_client:S3ClientMock.new)
]
)
"MY VIMRC
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
def remove_company_schedule_for_deletion(subdomain)
delete_request = CompanyDeleteRequest.joins(:company)
.find_by(companies: { subdomain: subdomain })
if delete_request.nil?
puts "No delete request found for #{ subdomain }"
return false
end
company = delete_request.company
puts "Company: #{ company.name }"
puts "Company Subdomain: #{ company.subdomain }"
def schedule_company_for_deletion(subdomain)
company = Company.find_by(subdomain: subdomain)
if company.nil?
puts "Company with subdomain #{subdomain} could not be found"
return false
end
puts "Company: #{ company.name }"
puts "Company Subdomain: #{ company.subdomain }"
puts "Company Id: #{ company.id }"
puts "Company account owner email: #{ company.account_owner.email }"