Skip to content

Instantly share code, notes, and snippets.

@vhsu
vhsu / Add_border.py
Created May 18, 2024 22:23
Add a blank white border to an image in python using PIL
from PIL import Image
def add_border(input_image_path, output_image_path, border_size=100):
# Open an existing image
img = Image.open(input_image_path)
# Get the size of the original image
width, height = img.size
# Make the new image size as the original size plus the border
@vhsu
vhsu / Take_out_elements.py
Created November 28, 2023 15:57
Take elements out of a list in python and get its value by index
def take_out_elements(list_object, indices):
"""Removes elements from list in specified indices"""
removed_elements = []
indices = sorted(indices, reverse=True)
for idx in indices:
if idx < len(list_object):
removed_elements.append(list_object.pop(idx))
return removed_elements
@vhsu
vhsu / arraysplit.py
Created November 28, 2023 15:55
Split arrays to smaller arrays in Python
def split(arr, size):
"""Splits an array to smaller arrays of size"""
arrays = []
while len(arr) > size:
piece = arr[:size]
arrays.append(piece)
arr = arr[size:]
arrays.append(arr)
return arrays
@vhsu
vhsu / customereventsshopify.hs
Created August 31, 2023 12:33
GTM - Customer Events Shopify
// Step 1. Add and initialize your third-party JavaScript pixel (make sure to exclude HTML)
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
@vhsu
vhsu / dataLayer.push debug.js
Created August 23, 2022 12:36
Listen to dataLayer push calls
//Listen to datalaLayer.push calls (does not actually execute the push)
dataLayer.push = function(obj){ console.log('Something was pushed in the dataLayer');console.log(obj);}
@vhsu
vhsu / listentoiframe.js
Created July 11, 2022 14:05
Listen to Child Iframe (if it sends anything.)
window.addEventListener('message', function (e) {
console.log(e.data)
});
@vhsu
vhsu / GTM mutation event observer.js
Last active March 13, 2020 03:02
GTM Mutation Event
<script>
var contentDiv = document.querySelector(".et-pb-contact-message");
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.type==="childList"&& contentDiv.innerHTML.indexOf("Merci pour votre e-mail") !=-1) {
dataLayer.push({'event': 'contactFormSent'});
observer.disconnect();
}
});
@vhsu
vhsu / GTM Content Tags Dom.js
Created February 25, 2020 12:37
Send Custom events GTM DOM Content
<script>
window.dataLayer = window.dataLayer || [];
try{
var contentTags = document.getElementsByClassName("news-detail__info__tags")[0].children;
if(contentTags.length>1){
for(var i=1;i<contentTags.length;i++){
window.dataLayer.push({
'event': 'contentViewed',
'contentTag': contentTags[i].innerHTML
});
@vhsu
vhsu / combiLoopOptimizer.js
Created October 31, 2018 18:47
combiLoopOptimizer
//This is used in findBalancedSets function, to reduce processing time for large sets of combinations
function combiLoopOptimizer(combinationsR, playerNames) {
var start = 0;
var skipRanges = [];
skipRanges.length = combinationsR[0].length;
for (var i = playerNames.length; i >= 0; i--) {
//size of range to skip
var temp = Math.floor(getTotalCombinations(i - 1, teamsize - 1));
//start of range to skip