_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q20600 | matchAt | train | function matchAt(content, index, match) {
return content.substring(index, index + match.length) === match;
} | javascript | {
"resource": ""
} |
q20601 | replaceAt | train | function replaceAt(content, index, oldString, newString) {
logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
return (
content.substr(0, index) +
newString +
content.substr(index + oldString.length)
);
} | javascript | {
"resource": ""
} |
q20602 | getFileList | train | function getFileList(branchName = config.baseBranch) {
logger.debug(`getFileList(${branchName})`);
return config.storage.getFileList(branchName);
} | javascript | {
"resource": ""
} |
q20603 | massageConfig | train | function massageConfig(config) {
if (!allowedStrings) {
allowedStrings = [];
options.forEach(option => {
if (option.allowString) {
allowedStrings.push(option.name);
}
});
}
const massagedConfig = clone(config);
for (const [key, val] of Object.entries(config)) {
if (allowedStr... | javascript | {
"resource": ""
} |
q20604 | poetry2npm | train | function poetry2npm(input) {
const versions = input
.split(',')
.map(str => str.trim())
.filter(notEmpty);
return versions.join(' ');
} | javascript | {
"resource": ""
} |
q20605 | initRepo | train | async function initRepo({ repository, endpoint, localDir }) {
logger.debug(`initRepo("${repository}")`);
const opts = hostRules.find({ platform: 'bitbucket' }, { endpoint });
// istanbul ignore next
if (!(opts.username && opts.password)) {
throw new Error(
`No username/password found for Bitbucket rep... | javascript | {
"resource": ""
} |
q20606 | getBranchCommit | train | async function getBranchCommit(branchName) {
try {
const branch = (await api.get(
`/2.0/repositories/${config.repository}/refs/branches/${branchName}`
)).body;
return branch.target.hash;
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, `getBranchCommit('${branchName}') failed'`... | javascript | {
"resource": ""
} |
q20607 | removeMultiLineComments | train | function removeMultiLineComments(content) {
const beginRegExp = /(^|\n)=begin\s/;
const endRegExp = /(^|\n)=end\s/;
let newContent = content;
let i = newContent.search(beginRegExp);
let j = newContent.search(endRegExp);
while (i !== -1 && j !== -1) {
if (newContent[i] === '\n') {
i += 1;
}
... | javascript | {
"resource": ""
} |
q20608 | getFile | train | async function getFile(repoId, repository, filePath, branchName) {
logger.trace(`getFile(filePath=${filePath}, branchName=${branchName})`);
const azureApiGit = await azureApi.gitApi();
const item = await azureApiGit.getItemText(
repoId,
filePath,
null,
null,
0, // because we look for 1 file
... | javascript | {
"resource": ""
} |
q20609 | maxSatisfyingVersion | train | function maxSatisfyingVersion(versions, range) {
return versions.find(v => equals(v, range)) || null;
} | javascript | {
"resource": ""
} |
q20610 | Pathformer | train | function Pathformer(element) {
// Test params
if (typeof element === 'undefined') {
throw new Error('Pathformer [constructor]: "element" parameter is required');
}
// Set the element
if (element.constructor === String) {
element = document.getElementById(element);
if (!element) {
throw new ... | javascript | {
"resource": ""
} |
q20611 | Vivus | train | function Vivus(element, options, callback) {
setupEnv();
// Setup
this.isReady = false;
this.setElement(element, options);
this.setOptions(options);
this.setCallback(callback);
if (this.isReady) {
this.init();
}
} | javascript | {
"resource": ""
} |
q20612 | record_data | train | function record_data(e) {
var lock = LockService.getDocumentLock();
lock.waitLock(30000); // hold off up to 30 sec to avoid concurrent writing
try {
Logger.log(JSON.stringify(e)); // log the POST data in case we need to debug it
// select the 'responses' sheet by default
var doc = SpreadsheetA... | javascript | {
"resource": ""
} |
q20613 | getFormData | train | function getFormData(form) {
var elements = form.elements;
var fields = Object.keys(elements).filter(function(k) {
return (elements[k].name !== "honeypot");
}).map(function(k) {
if(elements[k].name !== undefined) {
return elements[k].name;
// special case for Edge's html colle... | javascript | {
"resource": ""
} |
q20614 | resolve | train | function resolve (queries, context) {
if (Array.isArray(queries)) {
queries = flatten(queries.map(parse))
} else {
queries = parse(queries)
}
return queries.reduce(function (result, query, index) {
var selection = query.queryString
var isExclude = selection.indexOf('not ') === 0
if (isExcl... | javascript | {
"resource": ""
} |
q20615 | browserslist | train | function browserslist (queries, opts) {
if (typeof opts === 'undefined') opts = { }
if (typeof opts.path === 'undefined') {
opts.path = path.resolve ? path.resolve('.') : '.'
}
if (typeof queries === 'undefined' || queries === null) {
var config = browserslist.loadConfig(opts)
if (config) {
... | javascript | {
"resource": ""
} |
q20616 | doMatch | train | function doMatch (string, qs) {
var or = /^(?:,\s*|\s+OR\s+)(.*)/i
var and = /^\s+AND\s+(.*)/i
return find(string, function (parsed, n, max) {
if (and.test(parsed)) {
qs.unshift({ type: QUERY_AND, queryString: parsed.match(and)[1] })
return true
} else if (or.test(parsed)) {
qs.unshift(... | javascript | {
"resource": ""
} |
q20617 | makeDataset | train | function makeDataset(arr, colstats) {
var labelix = parseInt($("#labelix").val());
if(labelix < 0) labelix = D + labelix; // -1 should turn to D-1
var data = [];
var labels = [];
for(var i=0;i<N;i++) {
var arri = arr[i];
// create the input datapoint Vol()
var p = arri.sli... | javascript | {
"resource": ""
} |
q20618 | train | function() {
var b = test_batch;
var k = Math.floor(Math.random()*num_samples_per_batch);
var n = b*num_samples_per_batch+k;
var p = img_data[b].data;
var x = new convnetjs.Vol(image_dimension,image_dimension,image_channels,0.0);
var W = image_dimension*image_dimension;
var j=0;
for(var dc=0;dc<image_... | javascript | {
"resource": ""
} | |
q20619 | train | function() {
var num_classes = net.layers[net.layers.length-1].out_depth;
document.getElementById('testset_acc').innerHTML = '';
var num_total = 0;
var num_correct = 0;
// grab a random test image
for(num=0;num<4;num++) {
var sample = sample_test_instance();
var y = sample.label; // ground truth ... | javascript | {
"resource": ""
} | |
q20620 | train | function(lst, x, y, w, h) {
lst.push(new Wall(new Vec(x,y), new Vec(x+w,y)));
lst.push(new Wall(new Vec(x+w,y), new Vec(x+w,y+h)));
lst.push(new Wall(new Vec(x+w,y+h), new Vec(x,y+h)));
lst.push(new Wall(new Vec(x,y+h), new Vec(x,y)));
} | javascript | {
"resource": ""
} | |
q20621 | train | function() {
// positional information
this.p = new Vec(50, 50);
this.op = this.p; // old position
this.angle = 0; // direction facing
this.actions = [];
this.actions.push([1,1]);
this.actions.push([0.8,1]);
this.actions.push([1,0.8]);
this.actions.push(... | javascript | {
"resource": ""
} | |
q20622 | train | function() {
var new_defs = [];
for(var i=0;i<defs.length;i++) {
var def = defs[i];
if(def.type==='softmax' || def.type==='svm') {
// add an fc layer here, there is no reason the user should
// have to worry about this and we almost always want to
... | javascript | {
"resource": ""
} | |
q20623 | train | function(w) {
if(w.length === 0) { return {}; } // ... ;s
var maxv = w[0];
var minv = w[0];
var maxi = 0;
var mini = 0;
var n = w.length;
for(var i=1;i<n;i++) {
if(w[i] > maxv) { maxv = w[i]; maxi = i; }
if(w[i] < minv) { minv = w[i]; mini = i; }
}
return {maxi: maxi, m... | javascript | {
"resource": ""
} | |
q20624 | train | function(lst, probs) {
var p = randf(0, 1.0);
var cumprob = 0.0;
for(var k=0,n=lst.length;k<n;k++) {
cumprob += probs[k];
if(p < cumprob) { return lst[k]; }
}
} | javascript | {
"resource": ""
} | |
q20625 | train | function(opt, field_name, default_value) {
if(typeof field_name === 'string') {
// case of single string
return (typeof opt[field_name] !== 'undefined') ? opt[field_name] : default_value;
} else {
// assume we are given a list of string instead
var ret = default_value;
for(var i=0;... | javascript | {
"resource": ""
} | |
q20626 | train | function(state0, action0, reward0, state1) {
this.state0 = state0;
this.action0 = action0;
this.reward0 = reward0;
this.state1 = state1;
} | javascript | {
"resource": ""
} | |
q20627 | randi | train | function randi(s, e) {
return Math.floor(Math.random()*(e-s) + s);
} | javascript | {
"resource": ""
} |
q20628 | randn | train | function randn(mean, variance) {
var V1, V2, S;
do {
var U1 = Math.random();
var U2 = Math.random();
V1 = 2 * U1 - 1;
V2 = 2 * U2 - 1;
S = V1 * V1 + V2 * V2;
} while (S > 1);
X = Math.sqrt(-2 * Math.log(S) / S) * V1;
X = mean + Math.sqrt(variance) * X;
return X;
} | javascript | {
"resource": ""
} |
q20629 | train | function(opt) {
var opt = opt || {};
// required
this.k = opt.k;
this.n = opt.n;
this.alpha = opt.alpha;
this.beta = opt.beta;
// computed
this.out_sx = opt.in_sx;
this.out_sy = opt.in_sy;
this.out_depth = opt.in_depth;
this.layer_type = 'lrn';
// checks
if(this.n%... | javascript | {
"resource": ""
} | |
q20630 | train | function() {
var N = this.data.length;
var num_train = Math.floor(this.train_ratio * N);
this.folds = []; // flush folds, if any
for(var i=0;i<this.num_folds;i++) {
var p = randperm(N);
this.folds.push({train_ix: p.slice(0, num_train), test_ix: p.slice(num_train, N)});
}
... | javascript | {
"resource": ""
} | |
q20631 | train | function() {
var input_depth = this.data[0].w.length;
var num_classes = this.unique_labels.length;
// sample network topology and hyperparameters
var layer_defs = [];
layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth: input_depth});
var nl = weightedSample([0,1,2,3], [0.2... | javascript | {
"resource": ""
} | |
q20632 | train | function() {
this.candidates = []; // flush, if any
for(var i=0;i<this.num_candidates;i++) {
var cand = this.sampleCandidate();
this.candidates.push(cand);
}
} | javascript | {
"resource": ""
} | |
q20633 | train | function(data) {
// forward prop the best networks
// and accumulate probabilities at last layer into a an output Vol
var eval_candidates = [];
var nv = 0;
if(this.evaluated_candidates.length === 0) {
// not sure what to do here, first batch of nets hasnt evaluated yet
// ... | javascript | {
"resource": ""
} | |
q20634 | reload | train | function reload() {
eval($("#layerdef").val());
// refresh buttons
var t = '';
for(var i=1;i<net.layers.length-1;i++) { // ignore input and regression layers (first and last)
var butid = "button" + i;
t += "<input id=\""+butid+"\" value=\"" + net.layers[i].layer_type +"\" type=\"submit\" onclick=\"upda... | javascript | {
"resource": ""
} |
q20635 | hardLock | train | function hardLock(callback) {
return self.apos.locks.lock('save-area-' + docId, { waitForSelf: true }, function(err) {
if (err) {
return callback(err);
}
hardLocked = true;
return callback(null);
});
} | javascript | {
"resource": ""
} |
q20636 | advisoryLock | train | function advisoryLock(callback) {
if (!(req.htmlPageId && req.user)) {
// Some consumers of this API might not participate
// in advisory locking. Also, make sure we have a
// valid user to minimize the risk of a DOS attack
// via nuisance locking
return callback(null);
... | javascript | {
"resource": ""
} |
q20637 | train | function(eventName, fn) {
apos.handlers[eventName] = (apos.handlers[eventName] || []).concat([ fn ]);
} | javascript | {
"resource": ""
} | |
q20638 | train | function(eventName, fn) {
if (!fn) {
delete apos.handlers[eventName];
return;
}
apos.handlers[eventName] = _.filter(apos.handlers[eventName], function(_fn) {
return fn !== _fn;
});
} | javascript | {
"resource": ""
} | |
q20639 | train | function(type, options, alias) {
if (_.has(apos.modules, type)) {
// Don't double-create singletons on apos.change(), leads to doubled click events etc.
return;
}
var module = apos.create(type, options);
apos.modules[type] = module;
if (alias) {
apos[alias] = module;
}
} | javascript | {
"resource": ""
} | |
q20640 | findSafe | train | function findSafe($element, selector, ignore) {
var $self = $element;
return $self.find(selector).filter(function() {
var $parents = $(this).parents();
var i;
for (i = 0; (i < $parents.length); i++) {
if ($parents[i] === $self[0]) {
r... | javascript | {
"resource": ""
} |
q20641 | train | function (domElement, styles) {
styles = styles || (document.defaultView && document.defaultView.getComputedStyle ? document.defaultView.getComputedStyle(domElement, null) : domElement.currentStyle);
var px = document.defaultView && document.defaultView.getComputedStyle ? true : false;
var b = {... | javascript | {
"resource": ""
} | |
q20642 | findSafe | train | function findSafe($context, selector) {
if (arguments.length === 1) {
selector = arguments[0];
$context = self.$el;
}
if (!options.nestGuard) {
return $context.find(selector);
}
return $context.find(selector).not($context.find(options.nestGuard).find(selector));
... | javascript | {
"resource": ""
} |
q20643 | getChildren | train | function getChildren(cb) {
const path = self.matchDescendants(page);
self.find(req, { path: path }).sort({ path: 1 }).toArray((err, res) => {
if (!err) {
tree = tree.concat(res);
}
return cb(err, res);
});
} | javascript | {
"resource": ""
} |
q20644 | trashOrUntrashPages | train | function trashOrUntrashPages(cb) {
const ids = tree.map(p => p._id);
return self.apos.docs.db.update({ _id: { $in: ids } }, action, {
multi: true
}, (err, res) => {
cb(err);
});
} | javascript | {
"resource": ""
} |
q20645 | train | function(callback) {
var matches = url.match(/(\w+)\.wufoo\.com\/forms\/[\w]+-[\w-]+/);
if (!matches) {
return setImmediate(callback);
}
return request(url, function(err, response, body) {
if (err) {
return callback(err);
}
var matches ... | javascript | {
"resource": ""
} | |
q20646 | train | function(filter, choice) {
var choices = [];
for (var i = 0; i < filter.choices.length; i++) {
choices.push({
label: filter.choices[i].label,
action: filter.name,
value: filterValueToChoiceValue(filter.choices[i].value, choice),
default: filter.choices[i].valu... | javascript | {
"resource": ""
} | |
q20647 | train | function(self, options) {
self._id = options._id;
self.body = {
_id: self._id
};
self.beforeShow = function(callback) {
self.$el.on('click', '[data-open-changes]', function() {
var $toggle = $(this);
var $version = $toggle.closest('[data-version]');
var currentId = ... | javascript | {
"resource": ""
} | |
q20648 | train | function(pathname, css, req, next) {
if (!self.options.bless) {
fs.writeFileSync(pathname, css);
return next();
}
self.splitWithBless(pathname, css);
return next();
} | javascript | {
"resource": ""
} | |
q20649 | train | function(list, property) {
if (_.isArray(list)) {
return _.some(list, function(item) { return _.has(item, property); });
} else {
return _.has(list, property);
}
} | javascript | {
"resource": ""
} | |
q20650 | train | function(list, value) {
if (_.isArray(list)) {
for (var i = 0; i < list.length; i++) {
var listItem = list[i];
if (listItem.indexOf(value) === 0) {
return true;
}
}
} else {
if (list.indexOf(value) === 0) {
return true;
}
... | javascript | {
"resource": ""
} | |
q20651 | train | function(arr, property, value) {
return _.find(arr, function(item) {
return (item[property] === value);
});
} | javascript | {
"resource": ""
} | |
q20652 | train | function(arr, property, value) {
return _.filter(arr, function(item) {
return (item[property] === value);
});
} | javascript | {
"resource": ""
} | |
q20653 | train | function(arr, property, value) {
return _.reject(arr, function(item) {
return (item[property] === value);
});
} | javascript | {
"resource": ""
} | |
q20654 | train | function(array, without, property) {
return _.filter(Array.isArray(array) ? array : [], function(item) {
return !_.find(without || [], function(other) {
if (property) {
return _.isEqual(item[property], other);
} else {
return _.isEqual(item, other);
}
... | javascript | {
"resource": ""
} | |
q20655 | train | function() {
var result = {};
var i;
for (i = 0; (i < arguments.length); i++) {
if (!arguments[i]) {
continue;
}
result = _.merge(result, arguments[i]);
}
return result;
} | javascript | {
"resource": ""
} | |
q20656 | cleanup | train | function cleanup(html) {
html = cheerio.load(html);
html('[' + ignoreAttr + ']').removeAttr(ignoreAttr);
html = html.html();
return html;
} | javascript | {
"resource": ""
} |
q20657 | train | function(options) {
var pages = [];
var fromPage = options.page - 2;
if (fromPage < 2) {
fromPage = 2;
}
for (var page = fromPage; (page < (fromPage + options.shown)); page++) {
pages.push(page);
}
return pages;
} | javascript | {
"resource": ""
} | |
q20658 | train | function(msg) {
// eslint-disable-next-line no-console
if (console.debug) {
// eslint-disable-next-line no-console
console.debug.apply(console, arguments);
} else {
// eslint-disable-next-line no-console
console.log.apply(console, arguments);
}
} | javascript | {
"resource": ""
} | |
q20659 | train | function(callback) {
async.forEachSeries(file.crops || [], function(crop, callback) {
console.log('RECROPPING');
var originalFile = '/attachments/' + file._id + '-' + file.name + '.' + crop.left + '.' + crop.top + '.' + crop.width + '.' + crop.height + '.' + file.extension;... | javascript | {
"resource": ""
} | |
q20660 | train | function() {
return $(apos.modalSupport.stack.length ? apos.modalSupport.stack[apos.modalSupport.stack.length - 1] : 'body');
} | javascript | {
"resource": ""
} | |
q20661 | baseGet | train | function baseGet(object, path, pathKey) {
if (object == null) {
return;
}
object = toObject(object);
if (pathKey !== undefined && pathKey in object) {
path = [pathKey];
}
var index = 0,
length = path.length;
while (object != null && index < length) {
... | javascript | {
"resource": ""
} |
q20662 | toIterable | train | function toIterable(value) {
if (value == null) {
return [];
}
if (!isArrayLike(value)) {
return values(value);
}
if (lodash.support.unindexedChars && isString(value)) {
return value.split('');
}
return isObject(value) ? value : Object(value);
} | javascript | {
"resource": ""
} |
q20663 | toObject | train | function toObject(value) {
if (lodash.support.unindexedChars && isString(value)) {
var index = -1,
length = value.length,
result = Object(value);
while (++index < length) {
result[index] = value.charAt(index);
}
return result;
}
return... | javascript | {
"resource": ""
} |
q20664 | has | train | function has(object, path) {
if (object == null) {
return false;
}
var result = hasOwnProperty.call(object, path);
if (!result && !isKey(path)) {
path = toPath(path);
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
if (object == null)... | javascript | {
"resource": ""
} |
q20665 | train | function(widget, options) {
var manager = self.getWidgetManager(widget.type);
if (!manager) {
// Not configured in this project
self.warnMissingWidgetType(widget.type);
return '';
}
var partial;
if (!manager.options.wrapperTemplate) {
partial = _.partial(sel... | javascript | {
"resource": ""
} | |
q20666 | train | function(widget, options) {
return self.widgetControlGroups(self.apos.templates.contextReq, widget, options);
} | javascript | {
"resource": ""
} | |
q20667 | train | function(callback) {
if (callback) {
return body(callback);
} else {
return Promise.promisify(body)();
}
function body(callback) {
return self.cacheCollection.remove({
name: name
}, callback);
}
} | javascript | {
"resource": ""
} | |
q20668 | clean | train | function clean(nodes) {
mark(nodes, []);
return prune(nodes);
function mark(nodes, ancestors) {
_.each(nodes, function(node) {
if (node.publish) {
node.good = true;
_.each(ancestors, function(ancestor) {
ancestor.good = true;
... | javascript | {
"resource": ""
} |
q20669 | train | function(self, options) {
self.options = options;
self.editorName = self.name + '-widgets-editor';
// Opens the editor modal of a widget, unless the widget is contextualOnly,
// in which case we simply save the widget and call the save method
// Widget can opitonally be set to skipInitialModal whi... | javascript | {
"resource": ""
} | |
q20670 | checkOrGenerateId | train | function checkOrGenerateId (data) {
data = data || {};
if (!data._id) {
data._id = apos.utils.generateId();
}
return data;
} | javascript | {
"resource": ""
} |
q20671 | train | function (id, name, isFatal) {
this.id = id;
this.name = name;
this.installed = false;
this.metadata = {};
this.isFatal = isFatal || false;
} | javascript | {
"resource": ""
} | |
q20672 | cleanWww | train | function cleanWww (projectRoot, locations) {
var targetDir = path.relative(projectRoot, locations.www);
events.emit('verbose', 'Cleaning ' + targetDir);
// No source paths are specified, so mergeAndUpdateDir() will clear the target directory.
FileUpdater.mergeAndUpdateDir(
[], targetDir, { root... | javascript | {
"resource": ""
} |
q20673 | mapLaunchStoryboardResources | train | function mapLaunchStoryboardResources (splashScreens, launchStoryboardImagesDir) {
var platformLaunchStoryboardImages = mapLaunchStoryboardContents(splashScreens, launchStoryboardImagesDir);
var pathMap = {};
platformLaunchStoryboardImages.forEach(function (item) {
if (item.target) {
pat... | javascript | {
"resource": ""
} |
q20674 | getLaunchStoryboardImagesDir | train | function getLaunchStoryboardImagesDir (projectRoot, platformProjDir) {
var launchStoryboardImagesDir;
var xcassetsExists = folderExists(path.join(projectRoot, platformProjDir, 'Images.xcassets/'));
if (xcassetsExists) {
launchStoryboardImagesDir = path.join(platformProjDir, 'Images.xcassets/LaunchS... | javascript | {
"resource": ""
} |
q20675 | updateLaunchStoryboardImages | train | function updateLaunchStoryboardImages (cordovaProject, locations) {
var splashScreens = cordovaProject.projectConfig.getSplashScreens('ios');
var platformProjDir = path.relative(cordovaProject.root, locations.xcodeCordovaProj);
var launchStoryboardImagesDir = getLaunchStoryboardImagesDir(cordovaProject.root... | javascript | {
"resource": ""
} |
q20676 | getDefaultSimulatorTarget | train | function getDefaultSimulatorTarget () {
return require('./list-emulator-build-targets').run()
.then(function (emulators) {
var targetEmulator;
if (emulators.length > 0) {
targetEmulator = emulators[0];
}
emulators.forEach(function (emulator) {
... | javascript | {
"resource": ""
} |
q20677 | findXCodeProjectIn | train | function findXCodeProjectIn (projectPath) {
// 'Searching for Xcode project in ' + projectPath);
var xcodeProjFiles = shell.ls(projectPath).filter(function (name) {
return path.extname(name) === '.xcodeproj';
});
if (xcodeProjFiles.length === 0) {
return Q.reject('No Xcode project found... | javascript | {
"resource": ""
} |
q20678 | logWithArgs | train | function logWithArgs(level, args) {
args = [level].concat([].slice.call(args));
logger.logLevel.apply(logger, args);
} | javascript | {
"resource": ""
} |
q20679 | handleBridgeChange | train | function handleBridgeChange() {
if (proxyChanged()) {
var commandString = commandQueue.shift();
while(commandString) {
var command = JSON.parse(commandString);
var callbackId = command[0];
var service = command[1];
var action = command[2];
... | javascript | {
"resource": ""
} |
q20680 | cordovaExec | train | function cordovaExec() {
var cexec = require('cordova/exec');
var cexec_valid = (typeof cexec.nativeFetchMessages === 'function') && (typeof cexec.nativeEvalAndFetch === 'function') && (typeof cexec.nativeCallback === 'function');
return (cexec_valid && execProxy !== cexec)? cexec : iOSExec;
} | javascript | {
"resource": ""
} |
q20681 | requireLocalPkg | train | function requireLocalPkg(fspath, pkgName) {
const modulePath = findPkg(fspath, pkgName)
if (modulePath) {
try {
return require(modulePath)
} catch (e) {
console.warn(`Failed to load ${pkgName} from ${modulePath}. Using bundled`)
}
}
return require(pkgName... | javascript | {
"resource": ""
} |
q20682 | validateNesting | train | function validateNesting(node) {
let queue = [...node.parent.children];
let child;
let opener;
while (queue.length) {
child = queue.shift();
opener = child.openingElement;
if (child.type === 'JSXElement' && opener && (opener.name.name === 'input' || opener.name.name === 'textarea')) {
return t... | javascript | {
"resource": ""
} |
q20683 | isPlainObject | train | function isPlainObject(value) {
return (
isObject(value) &&
(!value.constructor || value.constructor === Object) &&
(!value.toString || value.toString === Object.prototype.toString)
);
} | javascript | {
"resource": ""
} |
q20684 | pruneGraphs | train | function pruneGraphs(graph, graphOptions) {
return currentGraph => {
pruneRelatedBranches(graph, currentGraph, graphOptions);
if (!graphOptions.isInsertOnly()) {
pruneDeletedBranches(graph, currentGraph);
}
return currentGraph;
};
} | javascript | {
"resource": ""
} |
q20685 | mapAfterAllReturn | train | function mapAfterAllReturn(arr, mapper, returnValue) {
const results = new Array(arr.length);
let containsPromise = false;
for (let i = 0, l = arr.length; i < l; ++i) {
results[i] = mapper(arr[i]);
if (isPromise(results[i])) {
containsPromise = true;
}
}
if (containsPromise) {
return ... | javascript | {
"resource": ""
} |
q20686 | promiseMap | train | function promiseMap(items, mapper, opt) {
switch (items.length) {
case 0:
return mapZero();
case 1:
return mapOne(items, mapper);
default:
return mapMany(items, mapper, opt);
}
} | javascript | {
"resource": ""
} |
q20687 | initCloneArray | train | function initCloneArray(array) {
var length = array.length,
result = new array.constructor(length);
// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index;
result.input = array.input;
... | javascript | {
"resource": ""
} |
q20688 | createInputColumnSelector | train | function createInputColumnSelector(nodes) {
return builder => {
const selects = new Map();
for (const node of nodes) {
const databaseJson = node.obj.$toDatabaseJson(builder);
for (const column of Object.keys(databaseJson)) {
if (!shouldSelectColumn(column, selects, node)) {
con... | javascript | {
"resource": ""
} |
q20689 | memoize | train | function memoize(func) {
const cache = new Map();
return input => {
let output = cache.get(input);
if (output === undefined) {
output = func(input);
cache.set(input, output);
}
return output;
};
} | javascript | {
"resource": ""
} |
q20690 | camelCase | train | function camelCase(str, { upperCase = false } = {}) {
if (str.length === 0) {
return str;
}
if (upperCase && isAllUpperCaseSnakeCase(str)) {
// Only convert to lower case if the string is all upper
// case snake_case. This allowes camelCase strings to go
// through without changing.
str = str... | javascript | {
"resource": ""
} |
q20691 | mapLastPart | train | function mapLastPart(mapper, separator) {
return str => {
const idx = str.lastIndexOf(separator);
const mapped = mapper(str.slice(idx + separator.length));
return str.slice(0, idx + separator.length) + mapped;
};
} | javascript | {
"resource": ""
} |
q20692 | keyMapper | train | function keyMapper(mapper) {
return obj => {
if (!isObject(obj) || Array.isArray(obj)) {
return obj;
}
const keys = Object.keys(obj);
const out = {};
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
out[mapper(key)] = obj[key];
}
return out;
};
} | javascript | {
"resource": ""
} |
q20693 | normalizeIds | train | function normalizeIds(ids, prop, opt) {
opt = opt || {};
let isComposite = prop.size > 1;
let ret;
if (isComposite) {
// For composite ids these are okay:
//
// 1. [1, 'foo', 4]
// 2. {a: 1, b: 'foo', c: 4}
// 3. [[1, 'foo', 4], [4, 'bar', 1]]
// 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: '... | javascript | {
"resource": ""
} |
q20694 | forEachChildExpression | train | function forEachChildExpression(expr, modelClass, callback) {
if (expr.node.$allRecursive || expr.maxRecursionDepth > RELATION_RECURSION_LIMIT) {
throw modelClass.createValidationError({
type: ValidationErrorType.RelationExpression,
message: `recursion depth of eager expression ${expr.toString()} too ... | javascript | {
"resource": ""
} |
q20695 | after | train | function after(obj, func) {
if (isPromise(obj)) {
return obj.then(func);
} else {
return func(obj);
}
} | javascript | {
"resource": ""
} |
q20696 | promiseTry | train | function promiseTry(callback) {
try {
const maybePromise = callback();
if (isPromise(maybePromise)) {
return maybePromise;
} else {
return Promise.resolve(maybePromise);
}
} catch (err) {
return Promise.reject(err);
}
} | javascript | {
"resource": ""
} |
q20697 | splitQueryProps | train | function splitQueryProps(model, json) {
const keys = Object.keys(json);
if (hasQueryProps(json, keys)) {
const queryProps = {};
const modelProps = {};
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
const value = json[key];
if (isQueryProp(value)) {
query... | javascript | {
"resource": ""
} |
q20698 | mergeQueryProps | train | function mergeQueryProps(model, json, omitProps, builder) {
json = convertExistingQueryProps(json, builder);
json = convertAndMergeHiddenQueryProps(model, json, omitProps, builder);
return json;
} | javascript | {
"resource": ""
} |
q20699 | convertExistingQueryProps | train | function convertExistingQueryProps(json, builder) {
const keys = Object.keys(json);
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
const value = json[key];
if (isQueryProp(value)) {
json[key] = queryPropToKnexRaw(value, builder);
}
}
return json;
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.