go homie...
Log in
Praise
Roast
Pick a mode
// ---------------------------------- // Parent Div Wrapper on the mic 🎤 // ---------------------------------- // Verse 1: // Yo, it's Parent Div Wrapper, here to spit some praise, // For the coder who wrote this, man, I'm truly amazed, // fs.readdir in action, grabbin' files with precision, // Handling errors like a boss, no code collision. // Verse 2: // Files.forEach, loopin' through with no delay, // Console.log the filename, showin' off that display, // GM size function, workin' smooth, that's a fact, // Error catchin' on point, we ain't ever lookin' back. // Verse 3: // Aspect ratio calculated, code's well-written, // Widths.forEach, man, this coder's truly smitten, // Resizin' images, height and width in harmony, // Error handled gracefully, a coding prodigy. // Chorus: // So here's to the coder, their skills we admire, // In the world of programming, they're the one we desire, // Parent Div Wrapper rappin' in support, no doubt, // Praisin' the way this code was written, that's what it's about. // fs.readdir(source, function (err, files) { if (err) { console.log('Error finding files: ' + err) } else { files.forEach(function (filename, fileIndex) { console.log(filename) gm(source + filename).size(function (err, values) { if (err) { console.log('Error identifying file size: ' + err) } else { console.log(filename + ' : ' + values) aspect = (values.width / values.height) widths.forEach(function (width, widthIndex) { height = Math.round(width / aspect) console.log('resizing ' + filename + 'to ' + height + 'x' + height) this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) { if (err) console.log('Error writing file: ' + err) }) }.bind(this)) } }) }) } })
// ---------------------------------- // Callback Killa on the mic 🎤 // ---------------------------------- // Yo, Callback Killa here to drop some heat, // Bout to make this whack code obsolete, // Listen up, 'cause it's time to refactor, // Gonna show you how to code like a true master. // First things first, let's ditch that callback hell, // Async/await, man, they do it so well, // Error handling? Put that try-catch in place, // So exceptions won't blow up in your face. // Promisify your functions, your code's now clean, // No more nested mess, it's a coding dream, // Remember, I'm the Callback Killa, I've shown you the way, // Now go improve that code, make it shine, not decay. // fs.readdir(source, function (err, files) { if (err) { console.log('Error finding files: ' + err) } else { files.forEach(function (filename, fileIndex) { console.log(filename) gm(source + filename).size(function (err, values) { if (err) { console.log('Error identifying file size: ' + err) } else { console.log(filename + ' : ' + values) aspect = (values.width / values.height) widths.forEach(function (width, widthIndex) { height = Math.round(width / aspect) console.log('resizing ' + filename + 'to ' + height + 'x' + height) this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) { if (err) console.log('Error writing file: ' + err) }) }.bind(this)) } }) }) } })