Skip to content

Instantly share code, notes, and snippets.

@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 April 1, 2025 23:24
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
@vhsu
vhsu / file2Array.java
Created July 30, 2018 16:44
Convert File to Array
//Convert a file to an array (each line /n as an element)
public String[] UrlFileToArray(String fileurl){
ArrayList inputFile =readFile(fileurl);
String urlArray[] = (String[])inputFile.toArray(new String[inputFile.size()]);
return urlArray;
}
@vhsu
vhsu / consolelogadd.js
Last active July 8, 2018 06:54
Javascript debugging : Add console logs in functions in the global namespace
//Author Wayne Burkett
//https://stackoverflow.com/questions/5033836/adding-console-log-to-every-function-automatically#5034657
//Add console log to all existing function existing in 5he global namespace at the time of execution
function augment(withFn) {
var name, fn;
for (name in window) {
fn = window[name];
if (typeof fn === 'function') {
window[name] = (function(name, fn) {