This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countWordsInText(text) { | |
let count = {}; | |
let popularity = []; // maybe this should be an object due to JS array expansion logic | |
function updateWord(word, ct) { | |
if (popularity[ct-1]) { | |
popularity[ct-1].delete(word); | |
} | |
if (!popularity[ct]) { | |
popularity[ct] = new Set(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doThingThatAcceptsCallback(arg1, callback) { | |
doThingThatReturnsAPromise(arg1) | |
.then(function resolved(result) { | |
callback(null, result); | |
}) | |
.catch(function rejected(error) { | |
callback(error); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doThingThatReturnsPromise(arg1) { | |
return new Promise(function(resolve, reject) { | |
fnThatDoesTheThingButAcceptsACallback(arg1, function callback(err, result) { | |
if(err) { | |
// the callback was called with an error | |
return reject(err); | |
} | |
// the callback was called with a result | |
resolve(result); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def logDeferredTime(deferred, logfn, message, extra=None): | |
"""Returns a deferred that wraps the passed in deferred and logs how long | |
it took for the provided deferred to return (either callback or errback) | |
from the time of the calling of this function. This creates a proxy | |
Deferred that is passed all of the arguments that are passed to the | |
provided deferred. | |
deferred: The deferred that we wish to time. | |
logfn: A function that is called with (message, extra=extra). IE. | |
`logger.info` |