Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/ | |
function bytesToSize(bytes) { | |
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; | |
if (bytes == 0) return 'n/a'; | |
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
if (i == 0) return bytes + ' ' + sizes[i]; | |
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; | |
}; |
Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
//1. Generate a random string: | |
Math.random().toString(36).substr(2); | |
//This simply generates a random float, casts it into a String using base 36 and remove the 2 first chars 0 and .. | |
//2. Clone an array: | |
var newA = myArray.slice(0); | |
//This will return a copy of the array, ensuring no other variables point to it. | |
//3. Remove HTML tags: | |
"<b>A</b>".replace(/<[^>]+>/gi, ""); |