Skip to content

Instantly share code, notes, and snippets.

@joelcardinal
joelcardinal / getUrls.js
Last active November 23, 2015 20:19
I have a habit of opening a gazillion tabs of links I want to keep. One quick way I've discovered other than bookmarking is to open chrome://inspect and you can collect all the links (except if more than 100 characters, Chrome truncates with "...") in the console by running this:
/* run in console on chrome://inspect..., select and copy output. Doesn't work with if URL more than 100 characters, Chrome truncates with "..." */
(function(){var arr=[],urls=document.querySelectorAll('.url');for (i=0,len=urls.length; len > i; i++){arr.push(urls[i].innerHTML)}return arr.join('\n\r');}());
@joelcardinal
joelcardinal / findUnusedFiles.sh
Created November 24, 2015 17:08
Quick bash script to discover static files not used in Demandware codebase
#!/bin/bash
# Quick script to discover static files not used in codebase
# to create fileList.txt
# ls -1R ./workspace2/app_core/cartridge/static > imgList.txt
# then dedupe...
# This script needs to go in parent dir of "workspace" dir
while read p; do
@joelcardinal
joelcardinal / getPageData.js
Last active April 28, 2016 21:05
Cobbled together some code examples to put together some functions that will retrieve text from a page (via AJAX) by selector
(function(){
// cobbled together some code examples to put together some functions
// that will retrieve text from a page (via AJAX) by selector
var url = 'http://www.cnn.com';
var selector = 'h2';
getPageData(url,selector);
@joelcardinal
joelcardinal / cssToFile.js
Created May 24, 2016 16:17
Outputs CSS file based on all child elements of and including provided parent element that have a class or id
(function(){
var query = '.myParentClass'; // required, selector query of containing element
var prefix = ''; // optional, leave '' if no prefix
// ========= end of input params ========== //
var cssArr = [];
function addClassRule(classValue){
@joelcardinal
joelcardinal / debugTechniques.md
Last active June 6, 2016 19:44
General debugging techniques I like to use...

#General Debugging Techniques

##Reproduce It The first step is to find a way to reliably reproduce the problem, document the steps. Often doing this alone will give you a good indication of where the problem might originate. If you have a reproducable procedure that only works some of the time it is likely you have a race condition somewhere in your logic.

##Up-to-date Second step should be to confirm you are inspecting the latest code. Did your changes really get uploaded to your development instance? Are you absolutely sure you are editing the correctly file(s), not a similarly named or overridden file?

##Inspect Error Logs Often the problem is already being reported, whether server-side or client-side console errors.

@joelcardinal
joelcardinal / getCssData.js
Last active May 23, 2019 09:55
Lists pages stylesheet/inline CSS. Also reports CSS selectors used on page from stylesheet/inline and inline JS.
/*
TODO: add check for used Font Family, refactor
*/
(function getStyleSheetsCssData(){
var styleSheets = document.styleSheets,
data = {
cssData : {
allUsedSelectorText : []
},
jsData : []
@joelcardinal
joelcardinal / template.js
Created February 2, 2018 18:45
Utility to populate templates for pre-ES2015 backticks
/*
* str = 'I went to the {{location}} and found {{item}}';
* obj = {location : 'store', item : 'milk'};
*/
function getFilledTplObj(str,obj){
function replacer() {
return obj[arguments[1]];
}
return str.replace(/{{([^}}]+)?}}/g, replacer);
}
@joelcardinal
joelcardinal / getSelectParams.js
Created February 2, 2018 20:29
Get Only Select Current URL Params
function getSelectParams(){
var selectParamsArr = [];
var paramsArr = window.location.search.replace('?','').split('&');
for(var i=0,len=paramsArr.length;i<len;i++){
if(/cgid=|cid=|sid=/.test(paramsArr[i]) ){
selectParamsArr.push(paramsArr[i]);
}
}
return selectParamsArr.join('&');
}
@joelcardinal
joelcardinal / proxyExample.js
Created March 23, 2018 18:50
JavaScript Proxy Example
/*
JavaScript Proxy
First read this...
https://hacks.mozilla.org/2015/07/es6-in-depth-proxies-and-reflect/
Above is an old article, proxy is available, except in IE...
https://caniuse.com/proxy
@joelcardinal
joelcardinal / mutationObserver.js
Created March 23, 2018 18:53
JavaScript MutationObserver Example
/*
JavaScript MutationObserver
https://caniuse.com/#feat=mutationobserver
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
*/