Skip to content

Instantly share code, notes, and snippets.

@Zhong-z
Zhong-z / generate_packing_slip.rake
Created June 15, 2016 23:21
Generate packing slip with different format for last order
namespace :gps do
task ga4: :environment do
pdf = Couriers::Base::A4PackingSlipPublisher.new(Order.last)
pdf.render_file '/Users/ZZ/Desktop/a.pdf'
end
task ga6: :environment do
pdf = Couriers::Base::A6PackingSlipPublisher.new(Order.last)
pdf.render_file '/Users/ZZ/Desktop/a.pdf'
end
@Zhong-z
Zhong-z / rubocop.yml
Created June 28, 2016 03:23
Shippit Rubocop configration
AllCops:
Rails:
Enabled: true
Exclude:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
- 'db/**/*'
TargetRubyVersion: 2.1
@Zhong-z
Zhong-z / oz_phone_regex
Last active October 24, 2016 06:51
Australia phone regular expression
^(\+61|0)[2-478][0-9]{8}$)|(^\+64[0-9]{8,9}$)
@Zhong-z
Zhong-z / bulk-order-address-suggestion.rb
Last active October 18, 2018 01:42
Bulk order creation with suggested addression response
require 'httparty'
require 'json'
country = 'ph'
tests = File.read("/Users/zz/Downloads/#{country}.json")
csv = CSV.open("/Users/zz/downloads/#{country}_final_#{Time.now.to_i}.csv", 'w')
csv << %w[index response_code suggested_or_not suggest_address delivery_suburb delivery_postcode raw_request raw_response]
orders = JSON.parse(tests)
succeed = 0
failed_with_suggestion = 0
completed_failed = 0
@Zhong-z
Zhong-z / split.rb
Created October 18, 2018 23:44
Split a string into chunks of specified size without breaking words
line = 'something very long that we need to split it ----llll aaa '
# the size/limit is 30
line.scan(/.{1,30}\b|.{1,30}/).map(&:strip)
@Zhong-z
Zhong-z / put_object_acl.rb
Created July 24, 2019 00:18
Publicize S3 Object
client = Aws::S3::Client.new(access_key_id: 'xxx', secret_access_key: 'xxx', region: 'ap-southeast-2')
client.put_object_acl({bucket: 'bucket_name', key: 'object_key', acl: 'public-read'})
@Zhong-z
Zhong-z / index.js
Created August 1, 2022 11:39 — forked from alshdavid/README.md
CBA PDF statement converter to PDF or CSV
"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.parsePDF=void 0;const e=t(require("fs")),n=t(require("pdf-parse")),s=require("json2csv");async function r(t,r){const l=e.default.readFileSync(t),o=(await n.default(l)).text.split("TransactionDebitCreditBalance");o.shift();let a=[],c=0;for(let t of o){const{results:e,finalBalance:n}=i(t,c);c=n,a=[...a,...e]}if(r&&r.endsWith(".json"))e.default.writeFileSync(r,JSON.stringify(a,null,2));else if(r&&r.endsWith(".csv")){const t=s.parse(a);e.default.writeFileSync(r,t)}else console.log(a)}function i(t,e=0){const{openingBalance:n,firstPassResults:s}=function(t){const e=t.split("\n");let n;e.shift();const s=[];if(function(t){return t.includes("OPENING BALANCE")}(e[0])){n=l((e.shift()||"").split("$")[1])}let r=!1;for(const t of e)if(!0!==r){if(""===t)break;if(t.includes("CLOSING BALANCE"))break;t.includes("CREDIT INTEREST EARNED")?r=!0:s.push(t)}else r=!1;return{f