Skip to content

Instantly share code, notes, and snippets.

@mcarneiro
Last active December 28, 2020 15:34
Show Gist options
  • Save mcarneiro/583459 to your computer and use it in GitHub Desktop.
Save mcarneiro/583459 to your computer and use it in GitHub Desktop.
JS util stuff
function getSymbolPositions(text, value){
var positions = text.split(value),
results = [];
for(var i=0, len = positions.length-1; i<len; i++){
results.push(positions[i].length + (results[i-1] + 1 || 0));
}
return results;
}
getSymbolPositions("1234561891abcdefghi1lmnop", "1"); // [0, 6, 9, 19]
var leadingZero = function (v, n) {
v = isNaN(v) ? 0 : v || 0;
n = isNaN(n) ? 1 : n || 1;
return v.toPrecision(n).split('.').reverse().join('');
};
leadingZero(1, 6); // "000001"
leadingZero(12, 6); // "000012"
leadingZero(123, 6); // "000123"
leadingZero(1234, 6); // "001234"
(function(){
var ls = document.getElementsByTagName('link'), c, i, l;
for(i=0,l=ls.length;i<l;i++){
c=ls[i].href;
if(c.match(/(?:\?|&)v=[\d\.\,]{0,}/)){
c=c.replace(/v=[\d\.\,]{0,}/, 'v=' + Number(new Date()));
}else{
c = c + (c.match(/\?/) ? "&" : "?") + "v=" + Number(new Date());
}
ls[i].href = c;
}
})();
/*
Usage: create a bookmark with the escaped on-line code below
javascript:%20(function(){var%20ls=document.getElementsByTagName('link'),c,i,l;for(i=0,l=ls.length;i<l;i++){c=ls[i].href;if(c.match(/(?:\?|&)v=[\d\.\,]{0,}/)){c=c.replace(/v=[\d\.\,]{0,}/,'v='+Number(new%20Date()));}else{c=c+(c.match(/\?/)?"&":"?")+"v="+Number(new%20Date());}%20ls[i].href=c;}})();void(0);
Execute and it will force the CSS to update
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment