Skip to content

Instantly share code, notes, and snippets.

View abhishekgupta5's full-sized avatar
🎯
Focusing

Abhishek Gupta abhishekgupta5

🎯
Focusing
View GitHub Profile
<?
# MIT license, do whatever you want with it
#
# This is my invoice.php page which I use to make invoices that customers want,
# with their address on it and which are easily printable. I love Stripe but
# their invoices and receipts were too wild for my customers on Remote OK
#
require_once(__DIR__.'/../vendor/autoload.php');
@abhishekgupta5
abhishekgupta5 / braintree.js
Created June 30, 2023 18:10
JS for dropin container and AJAX request with nonce to server
var braintreeButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: clientToken,
container: '#dropin-container'
}, function (createErr, instance) {
braintreeButton.addEventListener('click', function () {
$(this).prop('disabled', true).text('Verifying credit card details...');
$('.braintree-large-button[data-braintree-id="toggle"]').hide();
instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {
@abhishekgupta5
abhishekgupta5 / add_braintree_credit_card.html.erb
Created June 30, 2023 18:07
Braintree client/server setup for card details colleciton and verification
<div id="dropin-wrapper">
<div id="checkout-message"></div>
<div id="dropin-container"></div>
<button id="submit-button">Continue</button>
</div>
<!--Load the braintree JS SDK and our custom JS code which gets payment_method_nonce and tries-->
<!--to verify and add credit card. client_token is passed as a variable from controller to JS-->
<script>
@abhishekgupta5
abhishekgupta5 / image_decorator.rb
Created February 22, 2023 12:10
Fix Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError
module Spree
module ImageDecorator
def find_dimensions
return unless valid?
super
end
::Spree::Image.prepend self
def check_source_level(collection_class, com)
ac_ids = collection_class.upsert_processor.where(company_id: com.id).ids
ac_id_hashes = ac_ids.map { |x| BaseMongoObject.hash_string(x.to_s) }
chunk_id_hashes = DailyShardingStrategy.date_range_to_chunk_hashes(Date.current - 30.months, Date.current)
res = {}
chunk_id_hashes.each do |chunk_id_hash|
filter = { collection_class.upsert_processor.ad_account_field.to_s =>{"$in"=>ac_ids},
collection_class.upsert_processor.ad_account_id_hash_field => { "$in" => ac_id_hashes },
"chunk_id_hash": { "$in" => [chunk_id_hash]},
"custom_tags.Account.source": { "$exists" => true }}
D = cts.split("\n") # To create(spot level)
C = saleshouse.split("\n") # spot level
B = tv_channels.split("\n") # campaign level
A = account_ids.split("\n") #account level
values = A.zip(B, C, D)
# values = [['A', 'B', 'C', 'D'], ['A2', 'B2', 'C2', 'D2'],.....]
keys = ["account_id", "channel", "saleshouse", "Correct TV Saleshouse"]