_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
language
stringclasses
1 value
meta_information
dict
q11400
train
function(number, precision) { const multiplier = !!precision ? Math.pow(10, precision) : 1;
javascript
{ "resource": "" }
q11401
train
function(number, precision) { const multiplier = !!precision ? Math.pow(10, precision) : 1;
javascript
{ "resource": "" }
q11402
train
function(number, precision) { const multiplier = !!precision ? Math.pow(10, precision) : 1;
javascript
{ "resource": "" }
q11403
getFunctionOverhead
train
function getFunctionOverhead(runs) { var result, dummy, start, i; // The dummy has to return something, // or it'll get insanely optimized dummy = Function('return 1'); // Call dummy now to get it jitted dummy(); start = Blast.performanceNow(); for (i = 0; i < runs; i++) { dumm...
javascript
{ "resource": "" }
q11404
doSyncBench
train
function doSyncBench(fn, callback) { var start, fnOverhead, pretotal, result, runs, name; runs = 0; // For the initial test, to determine how many iterations we should // test later, we just use Date.now() start = Date.now(); // See how many times we can get it to run for 5...
javascript
{ "resource": "" }
q11405
doAsyncBench
train
function doAsyncBench(fn, callback) { var fnOverhead, pretotal, result, args, i; if (benchRunning > 0) { // Keep function optimized by not leaking the `arguments` object args = new Array(arguments.length); for (i = 0; i < args.length; i++) args[i] = arguments[i]; benchQueue.p...
javascript
{ "resource": "" }
q11406
WhileStatement
train
function WhileStatement(node, print) { this.keyword("while"); this.push("(");
javascript
{ "resource": "" }
q11407
buildForXStatement
train
function buildForXStatement(op) { return function (node, print) { this.keyword("for"); this.push("("); print.plain(node.left); this.push(" " + op + " ");
javascript
{ "resource": "" }
q11408
CatchClause
train
function CatchClause(node, print) { this.keyword("catch");
javascript
{ "resource": "" }
q11409
SwitchStatement
train
function SwitchStatement(node, print) { this.keyword("switch"); this.push("("); print.plain(node.discriminant); this.push(")"); this.space(); this.push("{"); print.sequence(node.cases, { indent: true, addNewlines:
javascript
{ "resource": "" }
q11410
has
train
function has(object) { // The intent of this method is to replace unsafe tests relying on type // coercion for optional arguments or obj properties: // | function on(event,options){ // | options = options || {}; // type coercion // | if (!event || !event.data || !event.data.value){ // | ...
javascript
{ "resource": "" }
q11411
extend
train
function extend(receiver, extension, path) { var props = has(path) ? path.split('.') : [], target = receiver, i; // iterative variable for (i = 0; i < props.length; i += 1) { if (!has(target, props[i])) {
javascript
{ "resource": "" }
q11412
get
train
function get(o, path, defaultValue) { var props = path.split('.'), i, // iterative variable p, // current property success = true; for (i = 0; i < props.length; i += 1) { p = props[i]; if
javascript
{ "resource": "" }
q11413
stringify
train
function stringify(obj) { var cache = []; return JSON.stringify(obj, function (key, value) { if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null) { if (cache.indexOf(value) !== -1) {
javascript
{ "resource": "" }
q11414
getClassNames
train
function getClassNames(classObject) { var classNames = []; for (var key in classObject) { if (classObject.hasOwnProperty(key)) { let check = classObject[key]; let className = _.kebabCase(key); if (_.isFunction(check)) { if (check()) { ...
javascript
{ "resource": "" }
q11415
train
function (data){ //create a new item object, place data in var node = { data: data, next: null, prev: null }; //special case: no items in the list yet if (this._length == 0) { this._head = node; ...
javascript
{ "resource": "" }
q11416
train
function(index){ //check for out-of-bounds values if (index > -1 && index < this._length){ var current = this._head, i = 0; while(i++ < index){ current = current.next;
javascript
{ "resource": "" }
q11417
train
function(start, end){ //subQueue to Array if(start >= 0 && start < end && end <= this._length) { var result = [], current = this._head, i = 0; while(i++ < start) { current = current.next; } while(start++ < e...
javascript
{ "resource": "" }
q11418
formatError
train
function formatError(e) { var s = typeof e === 'object' && e !== null && (e.stack || e.message) ? e.stack || e.message : formatObject(e);
javascript
{ "resource": "" }
q11419
formatObject
train
function formatObject(o) { var s = String(o); if(s === '[object Object]' && typeof JSON
javascript
{ "resource": "" }
q11420
init
train
function init(resolver) { var handler = new Pending(); try { resolver(promiseResolve, promiseReject, promiseNotify); } catch (e) { promiseReject(e); } return handler; /** * Transition from pre-resolution state to post-resolution state, notifying * all listeners of the ultimate fulfi...
javascript
{ "resource": "" }
q11421
resolve
train
function resolve(x) { return isPromise(x)
javascript
{ "resource": "" }
q11422
race
train
function race(promises) { if(typeof promises !== 'object' || promises === null) { return reject(new TypeError('non-iterable passed to race()')); } // Sigh, race([]) is untestable unless we return *something* // that is recognizable without calling .then()
javascript
{ "resource": "" }
q11423
getHandler
train
function getHandler(x) { if(isPromise(x)) { return x._handler.join(); } return maybeThenable(x)
javascript
{ "resource": "" }
q11424
getHandlerUntrusted
train
function getHandlerUntrusted(x) { try { var untrustedThen = x.then; return typeof untrustedThen ===
javascript
{ "resource": "" }
q11425
Pending
train
function Pending(receiver, inheritedContext) { Promise.createContext(this, inheritedContext); this.consumers = void 0;
javascript
{ "resource": "" }
q11426
Thenable
train
function Thenable(then, thenable) { Pending.call(this); tasks.enqueue(new
javascript
{ "resource": "" }
q11427
Rejected
train
function Rejected(x) { Promise.createContext(this); this.id = ++errorId; this.value = x;
javascript
{ "resource": "" }
q11428
AssimilateTask
train
function AssimilateTask(then, thenable, resolver) {
javascript
{ "resource": "" }
q11429
Fold
train
function Fold(f, z, c, to) { this.f = f; this.z = z; this.c = c; this.to = to; this.resolver
javascript
{ "resource": "" }
q11430
tryCatchReject3
train
function tryCatchReject3(f, x, y, thisArg, next) { try { f.call(thisArg, x, y, next);
javascript
{ "resource": "" }
q11431
copy
train
function copy(out, a) { out[0] = a[0] out[1] = a[1] out[2] = a[2]
javascript
{ "resource": "" }
q11432
RESTController
train
function RESTController(i,o,a,r){ var fn for (var j=0; j < RESTController.filters.length; j++) { fn = RESTController.filters[j] if (typeof fn === 'function') fn(i,o,a,r)
javascript
{ "resource": "" }
q11433
train
function(element, options) { var $el = $(element); // React on every server/socket.io message. // If the element is defined with a data-react-on-event attribute // we take that as an eventType the user wants to be warned on this // element and we forward the event via jQuery events on $(this). ...
javascript
{ "resource": "" }
q11434
train
function(el, data) { var dataupdateScope = $(el).data().reactOnDataupdate; var templateScope = $(el).data().templateScope; var userinputScope = $(el).data().reactOnUserinput; if (data) { $myelements.doRender(el, data); } else if (!data && templateScope) { $myelements.recoverTemplateScope...
javascript
{ "resource": "" }
q11435
train
function(el, scope) { var tplScopeObject = {}; $myelements.debug("Trying to update Element Scope without data from scope: %s", scope); // If no data is passed // we look up in localstorage $myelements.localDataForElement(el, scope, function onLocalDataForElement(err, data) { if (err) {
javascript
{ "resource": "" }
q11436
train
function(el, data, done) { if (!el.template) { $myelements.debug("Creating EJS template from innerHTML for element: ", el); // Save the compiled template only once try { el.template = new EJS({ element: el }); } catch (e) { console.error("myelements.jquery...
javascript
{ "resource": "" }
q11437
train
function(cb) { // If we're inside phonegap use its event. if (window.phonegap) { return document.addEventListener("offline", cb, false); } else if (window.addEventListener) { // With the offline HTML5 event from the window this.addLocalEventListener(window, "offline", cb); } else { ...
javascript
{ "resource": "" }
q11438
train
function($el) { // Reaction to socket.io messages $myelements.socket.on("message", function onMessage(message) { if ($el.data().templateScope === message.event) { // Update element scope (maybe re-render) var scope = {}; scope[message.event] = message.data; $myelements.upda...
javascript
{ "resource": "" }
q11439
execute
train
function execute() { var context = getDefaultContext(); var compiledOutput = fs.readFileSync(this.outputPath) vm.runInContext(compiledOutput,
javascript
{ "resource": "" }
q11440
wrap
train
function wrap() { var ports = this.compiledModule.ports; var incomingEmitter = new EventEmitter(); var outgoingEmitter = new EventEmitter(); var emit = incomingEmitter.emit.bind(incomingEmitter); Object.keys(ports).forEach(function(key) { outgoingEmitter.addListener(key, function() { var args = A...
javascript
{ "resource": "" }
q11441
mkdirsInner
train
function mkdirsInner(dirnames, currentPath, callback) { // Check for completion and call callback if (dirnames.length === 0) { return _callback(callback); } // Make next directory
javascript
{ "resource": "" }
q11442
pushResultsArray
train
function pushResultsArray(obj, size) { if (typeof obj === "string" && obj in stack) { stack[obj]["size"] = size; return; }
javascript
{ "resource": "" }
q11443
ClassBody
train
function ClassBody(node, print) { this.push("{"); if (node.body.length === 0) { print.printInnerComments(); this.push("}"); } else { this.newline();
javascript
{ "resource": "" }
q11444
loadModule
train
function loadModule(loader, name, options) { return new Promise(asyncStartLoadPartwayThrough({ step: options.address ? 'fetch' : 'locate', loader: loader, moduleName: name, // allow metadata for
javascript
{ "resource": "" }
q11445
requestLoad
train
function requestLoad(loader, request, refererName, refererAddress) { // 15.2.4.2.1 CallNormalize return new Promise(function(resolve, reject) { resolve(loader.loaderObj.normalize(request, refererName, refererAddress)); }) // 15.2.4.2.2 GetOrCreateLoad .then(function(name) { var load; ...
javascript
{ "resource": "" }
q11446
asyncStartLoadPartwayThrough
train
function asyncStartLoadPartwayThrough(stepState) { return function(resolve, reject) { var loader = stepState.loader; var name = stepState.moduleName; var step = stepState.step; if (loader.modules[name]) throw new TypeError('"' + name + '" already exists in the module table'); ...
javascript
{ "resource": "" }
q11447
doLink
train
function doLink(linkSet) { var error = false; try { link(linkSet, function(load, exc) { linkSetFailed(linkSet, load, exc);
javascript
{ "resource": "" }
q11448
train
function(name, source, options) { // check if already defined if (this._loader.importPromises[name]) throw new TypeError('Module is already loading.'); return createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ step: 'translate', loader: this._loader, ...
javascript
{ "resource": "" }
q11449
train
function(name) { var loader = this._loader; delete loader.importPromises[name];
javascript
{ "resource": "" }
q11450
train
function(source, options) { var load = createLoad(); load.address = options && options.address; var linkSet = createLinkSet(this._loader, load); var sourcePromise = Promise.resolve(source); var loader = this._loader;
javascript
{ "resource": "" }
q11451
getESModule
train
function getESModule(exports) { var esModule = {}; // don't trigger getters/setters in environments that support them if ((typeof exports == 'object' || typeof exports == 'function') && exports !== __global) { if (getOwnPropertyDescriptor) { for (var p in exports)
javascript
{ "resource": "" }
q11452
getPackageConfigMatch
train
function getPackageConfigMatch(loader, normalized) { var pkgName, exactMatch = false, configPath; for (var i = 0; i < loader.packageConfigPaths.length; i++) { var packageConfigPath = loader.packageConfigPaths[i]; var p = packageConfigPaths[packageConfigPath] || (packageConfigPaths[packageConfigPath]...
javascript
{ "resource": "" }
q11453
combinePluginParts
train
function combinePluginParts(loader, argumentName, pluginName, defaultExtension) { if (defaultExtension && argumentName.substr(argumentName.length - 3, 3) == '.js') argumentName = argumentName.substr(0, argumentName.length - 3);
javascript
{ "resource": "" }
q11454
getElements
train
function getElements(input) { if (typeof input === 'string') { return _getElements(document, input); } if (input instanceof window.NodeList || input instanceof window.HTMLCollection) { return _nodelistToArray(input); } if (input instanceof Array) { if (input['_chrsh-valid']) { return input...
javascript
{ "resource": "" }
q11455
forIn
train
function forIn(object, callback) { if ((typeof object === 'undefined' ? 'undefined' :
javascript
{ "resource": "" }
q11456
getElement
train
function getElement(input) { if (typeof input === 'string') { return _getElement(document, input); } if (input instanceof window.NodeList || input instanceof window.HTMLCollection) { return input[0]; }
javascript
{ "resource": "" }
q11457
append
train
function append(element, nodes) { element = getElement(element); if (!element
javascript
{ "resource": "" }
q11458
closest
train
function closest(element, tested) { var limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document; element = getElement(element); if (!element || (typeof limit === 'string' ? element.matches(limit) : element === limit)) { return false;
javascript
{ "resource": "" }
q11459
findOne
train
function findOne(element, selector) { return (element
javascript
{ "resource": "" }
q11460
hasClass
train
function hasClass(element) { element = getElement(element); if (!element) return; var n = arguments.length <= 1 ? 0 : arguments.length - 1; var found = void 0; var i = 0; while
javascript
{ "resource": "" }
q11461
removeClass
train
function removeClass(elements) { for (var _len = arguments.length, classes = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { classes[_key -
javascript
{ "resource": "" }
q11462
setData
train
function setData(elements, dataAttributes) { var attributes = {}; forIn(dataAttributes, _prefixAttribute.bind(null,
javascript
{ "resource": "" }
q11463
toggleClass
train
function toggleClass(elements) { for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } if (_typeof(args[0]) === 'object') {
javascript
{ "resource": "" }
q11464
on
train
function on(elements, input) { elements = _setEvents(elements, 'add', input); return function (offElements, events) { _setEvents(offElements ||
javascript
{ "resource": "" }
q11465
delegate
train
function delegate(selector, input) { var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.body; target =
javascript
{ "resource": "" }
q11466
once
train
function once(elements, input) { var eachElement = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var eachEvent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
javascript
{ "resource": "" }
q11467
trigger
train
function trigger(elements, events) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; elements = getElements(elements); if (!elements.length) return;
javascript
{ "resource": "" }
q11468
clearStyle
train
function clearStyle(elements) { var style = {}; for (var _len = arguments.length, props = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { props[_key - 1]
javascript
{ "resource": "" }
q11469
getHeight
train
function getHeight(element) { var offset = arguments.length > 1 && arguments[1] !== undefined ?
javascript
{ "resource": "" }
q11470
getWidth
train
function getWidth(element) { var offset = arguments.length > 1 && arguments[1] !== undefined ?
javascript
{ "resource": "" }
q11471
getSize
train
function getSize(element) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return {
javascript
{ "resource": "" }
q11472
getStyleProp
train
function getStyleProp(element) { var computedStyle = getComputedStyle(element); if (!computedStyle) return false; for (var _len = arguments.length, props = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len;
javascript
{ "resource": "" }
q11473
offset
train
function offset(element) { var screenPos = screenPosition(element); return screenPos && { top: screenPos.top
javascript
{ "resource": "" }
q11474
plugin
train
function plugin(plugins) { var z, method, conf; for(z in plugins) { if(typeof plugins[z] === 'function') { method = plugins[z]; }else{ method = plugins[z].plugin; conf = plugins[z].conf; }
javascript
{ "resource": "" }
q11475
hook
train
function hook() { var comp = hook.proxy.apply(null, arguments);
javascript
{ "resource": "" }
q11476
widthTraverse
train
function widthTraverse (graph, reachable, start, depth, hops, iter) { if(!start) throw new Error('Graphmitter#traverse: start must be provided') //var nodes = 1 reachable[start] = reachable[start] == null ? 0 : reachable[start] var queue = [start] //{key: start, hops: depth}] iter = iter || function ()...
javascript
{ "resource": "" }
q11477
toArray
train
function toArray (span, root) { if(!span[root]) return null var a = [root] while(span[root])
javascript
{ "resource": "" }
q11478
train
function(oldObserved, newObserveSet, onchanged) { for (var name in newObserveSet) {
javascript
{ "resource": "" }
q11479
train
function(oldObserved, newObserveSet, name, onchanged) { if (oldObserved[name]) { // After binding is set up, values // in `oldObserved` will be unbound. So if a name // has already be observed, remove from `oldObserved` // to prevent this. ...
javascript
{ "resource": "" }
q11480
train
function() { bundle.browserify.pipeline.get('deps').push(through.obj(function(row, enc, next) { var file = row.expose ? bundle.browserify._expose[row.id] : row.file; if (self.cache) { bundle.browserifyOptions.cache[file] = { source: ro...
javascript
{ "resource": "" }
q11481
IkoReporter
train
function IkoReporter(baseReporterDecorator, config, loggerFactory, formatError) { // extend the base reporter baseReporterDecorator(this); const logger = loggerFactory.create("reporter.iko"); const divider = "=".repeat(process.stdout.columns || 80); let slow = 0; let totalTime = 0; let netTime = 0; ...
javascript
{ "resource": "" }
q11482
train
function(options){ if (!options) { options = { cwd: workingDirectory }; return options;
javascript
{ "resource": "" }
q11483
train
function (command, options) { var exec = require('child_process').exec; var defer = Q.defer(); //Prepare the options object to be valid options = prepareOptions(options); //Activate-Deactivate command logging execution printCommandExecution(command, options); e...
javascript
{ "resource": "" }
q11484
plugin
train
function plugin(options){ options = options || {}; var keys = options.keys || []; return function(files, metalsmith, done){ setImmediate(done); Object.keys(files).forEach(function(file){ debug('checking file: %s', file); if (!isHtml(file)) return; var data = files[file]; var dir =...
javascript
{ "resource": "" }
q11485
npmInstall
train
function npmInstall(packageName) { return new Promise((resolve,reject) => { npm.load({ save:false, progress: false, force:true }, function (er) { if (er) { PAILogger.error(er);
javascript
{ "resource": "" }
q11486
train
function(filePath, currentPath){ if(/^(?:\/|[a-zA-Z]:(?:\/|\\))/.test(filePath)){ // Is the path absolute? filePath = path.normalize(filePath); }else{ // Relative paths
javascript
{ "resource": "" }
q11487
View
train
function View(tplPath, tplFile, data){ this.data = data||{}; this.defines = {}; this.enabled = true; // Default settings this.settings = doT.templateSettings; this.settings.varname = 'it,helpers'; // Add the helpers as a second data param for the parser this.settings.cache = true; // Use memory cache for compile...
javascript
{ "resource": "" }
q11488
fullWidth
train
function fullWidth(text, param) { let cols = process.stdout.columns; let lines = text.split('\n'); for (i = 0; i < lines.length; i++) { let size = cols; if (i === 0) size = size - 15; if ((lines[i].indexOf('%') > 0) && (param !== undefined)) size = size - param.length + 2;
javascript
{ "resource": "" }
q11489
revertInit
train
function revertInit(reinit, list, prefix, name, currentVersion) { exec('rm -Rf ./.versionFilesList.json', function(error, stdout, stderr) { if (error) sendProcessError(stdout, stderr);
javascript
{ "resource": "" }
q11490
loadConfiguration
train
function loadConfiguration() { let configuration; if (isInit()) { configuration = jsonReader('./.versionFilesList.json'); // check configuration file's integrity if (!configuration.name || !configuration.currentVersion || !configuration.filesList || !configuration.versionPrefix) { ...
javascript
{ "resource": "" }
q11491
discoverVersion
train
function discoverVersion() { // try to understand package name and current version // from package.json or bower.json let packageFile; let packageFileExtension; let packageType; let results = { name: '', currentVersion: '' }; let possiblePackageFiles = ['package.json', 'b...
javascript
{ "resource": "" }
q11492
patch
train
function patch(node, languages) { var data = node.data || {}; var primary = languages[0][0]; data.language = primary ===
javascript
{ "resource": "" }
q11493
concatenateFactory
train
function concatenateFactory() { var queue = []; /** * Gather a parent if not already gathered. * * @param {NLCSTChildNode} node - Child. * @param {number} index - Position of `node` in * `parent`. * @param {NLCSTParentNode} parent - Parent of `child`. */ function concat...
javascript
{ "resource": "" }
q11494
concatenate
train
function concatenate(node, index, parent) { if ( parent && (parent.type === 'ParagraphNode' || parent.type === 'RootNode') &&
javascript
{ "resource": "" }
q11495
one
train
function one(node) { var children = node.children; var length = children.length; var index = -1; var languages; var child; var dictionary = {}; var tuple; while (++index < length) { child = children[index]; languages = child.data &...
javascript
{ "resource": "" }
q11496
fromCallback
train
function fromCallback(source) { var callCount = 0; // Throw an error if the source is not a function if (typeof source !== 'function') { throw new TypeError('Expected `source` to be a function.'); } return new Readable({ objectMode: true, read: function () { var self = this; // Incr...
javascript
{ "resource": "" }
q11497
train
function() { Object.keys(this.name2Ws).forEach(function(name) { delete this.name2Ws[name]; }.bind(this));
javascript
{ "resource": "" }
q11498
train
function(text, lang, callback) { if (arguments.length == 4) { var options = callback; callback = arguments[arguments.length - 1]; } var uri = url.format({ pathname: url.resolve(baseAddress, 'lookup'), query: { key: dis.APIkey, ...
javascript
{ "resource": "" }
q11499
getPlatforms
train
function getPlatforms(tdef) { const platforms = []; if (tdef) { tdef.deployUnits.array.forEach((du) => { const platform = du.findFiltersByID('platform'); if (platform &&
javascript
{ "resource": "" }