_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q5900 | sortReceiversAndHighlight | train | function sortReceiversAndHighlight(receiverSignature) {
let trs = Array.from(tbody.getElementsByTagName('tr'));
let sortedFragment = document.createDocumentFragment();
trs.sort(sortFunction);
trs.forEach(function(tr) {
if(tr.id === receiverSignature) {
tr.setAttribute('class', 'monospace animated-hi... | javascript | {
"resource": ""
} |
q5901 | train | function(ev, callback, context) {
var calls = this._callbacks || (this._callbacks = {});
var list = calls[ev] || (calls[ev] = []);
list.push([callback, context]);
return this;
} | javascript | {
"resource": ""
} | |
q5902 | train | function(ev, callback) {
var calls;
if (!ev) {
this._callbacks = {};
} else if (calls = this._callbacks) {
if (!callback) {
calls[ev] = [];
} else {
var list = calls[ev];
if (!list) return this;
for (var i = 0, l = list.length; i < l; i++... | javascript | {
"resource": ""
} | |
q5903 | train | function(eventName) {
var list, calls, ev, callback, args;
var both = 2;
if (!(calls = this._callbacks)) return this;
while (both--) {
ev = both ? eventName : 'all';
if (list = calls[ev]) {
for (var i = 0, l = list.length; i < l; i++) {
if (!(callback = list... | javascript | {
"resource": ""
} | |
q5904 | train | function(options) {
options || (options = {});
if (this.isNew()) return this.trigger('destroy', this, this.collection, options);
var model = this;
var success = options.success;
options.success = function(resp) {
model.trigger('destroy', model, model.collection, options);
i... | javascript | {
"resource": ""
} | |
q5905 | train | function(models, options) {
if (_.isArray(models)) {
for (var i = 0, l = models.length; i < l; i++) {
this._remove(models[i], options);
}
} else {
this._remove(models, options);
}
return this;
} | javascript | {
"resource": ""
} | |
q5906 | train | function(models, options) {
models || (models = []);
options || (options = {});
this.each(this._removeReference);
this._reset();
this.add(models, {silent: true});
if (!options.silent) this.trigger('reset', this, options);
return this;
} | javascript | {
"resource": ""
} | |
q5907 | train | function(model, options) {
var coll = this;
options || (options = {});
model = this._prepareModel(model, options);
if (!model) return false;
var success = options.success;
options.success = function(nextModel, resp, xhr) {
coll.add(nextModel, options);
if (success) su... | javascript | {
"resource": ""
} | |
q5908 | train | function(model, options) {
if (!(model instanceof Backbone.Model)) {
var attrs = model;
model = new this.model(attrs, {collection: this});
if (model.validate && !model._performValidation(attrs, options)) model = false;
} else if (!model.collection) {
model.collection = this;
... | javascript | {
"resource": ""
} | |
q5909 | train | function(model, options) {
options || (options = {});
model = this.getByCid(model) || this.get(model);
if (!model) return null;
delete this._byId[model.id];
delete this._byCid[model.cid];
this.models.splice(this.indexOf(model), 1);
this.length--;
if (!options.silent) mode... | javascript | {
"resource": ""
} | |
q5910 | train | function(fragment, triggerRoute) {
var frag = (fragment || '').replace(hashStrip, '');
if (this.fragment == frag || this.fragment == decodeURIComponent(frag)) return;
if (this._hasPushState) {
var loc = window.location;
if (frag.indexOf(this.options.root) != 0) frag = this.options.root... | javascript | {
"resource": ""
} | |
q5911 | train | function(object) {
if (!(object && object.url)) return null;
return _.isFunction(object.url) ? object.url() : object.url;
} | javascript | {
"resource": ""
} | |
q5912 | train | function(string) {
return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
} | javascript | {
"resource": ""
} | |
q5913 | eq | train | function eq(a, b, stack) {
// Identical objects are equal. `0 === -0`, but they aren't identical.
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
if (a === b) return a !== 0 || 1 / a == 1 / b;
// A strict comparison is necessary because `null == undefined`.
i... | javascript | {
"resource": ""
} |
q5914 | updateNode | train | function updateNode(node, content, append) {
append = append || false;
while(!append && node.firstChild) {
node.removeChild(node.firstChild);
}
if(content instanceof Element) {
node.appendChild(content);
}
else if(content instanceof Array) {
content.forEach(function(element) {
node.appen... | javascript | {
"resource": ""
} |
q5915 | prepareEvents | train | function prepareEvents(raddec) {
let elements = [];
raddec.events.forEach(function(event) {
let i = document.createElement('i');
let space = document.createTextNode(' ');
i.setAttribute('class', EVENT_ICONS[event]);
elements.push(i);
elements.push(space);
});
return elements;
} | javascript | {
"resource": ""
} |
q5916 | prepareRecDecPac | train | function prepareRecDecPac(raddec) {
let maxNumberOfDecodings = 0;
raddec.rssiSignature.forEach(function(signature) {
if(signature.numberOfDecodings > maxNumberOfDecodings) {
maxNumberOfDecodings = signature.numberOfDecodings;
}
});
return raddec.rssiSignature.length + RDPS + maxNumberOfDecodings... | javascript | {
"resource": ""
} |
q5917 | sortRaddecsAndHighlight | train | function sortRaddecsAndHighlight(transmitterId) {
let trs = Array.from(tbody.getElementsByTagName('tr'));
let sortedFragment = document.createDocumentFragment();
trs.sort(sortFunction);
trs.forEach(function(tr) {
if(tr.id === transmitterId) {
tr.setAttribute('class', 'monospace animated-highlight-re... | javascript | {
"resource": ""
} |
q5918 | makeGhostBuster | train | function makeGhostBuster() {
var coordinates = [];
var threshold = 25;
var timeout = 2500;
// no touch support
if(!mobileDetection.is()) {
return { add : function(){}, remove : function(){} };
}
/**
* prevent clicks if they're in a registered XY region
* @param {MouseEvent} event
*/
funct... | javascript | {
"resource": ""
} |
q5919 | registerCoordinates | train | function registerCoordinates(event) {
var ev = event.originalEvent || event;
// It seems that touchend is the cause for derived events like 'change' for
// checkboxes. Since we're creating fastclicks, which will also cause 'change'
// events to fire, we need to prevent default on touchend events, which... | javascript | {
"resource": ""
} |
q5920 | getKeyName | train | function getKeyName (property) {
if (!property.computed && property.key.type === 'Identifier') {
return property.key.name
}
if (property.key.type === 'Literal') {
return '' + property.key.value
}
if (property.key.type === 'TemplateLiteral' && property.key.quasis.length === 1) {
return property.key... | javascript | {
"resource": ""
} |
q5921 | getRuleInfo | train | function getRuleInfo (ast) {
const INTERESTING_KEYS = new Set(['create', 'meta'])
let exportsVarOverridden = false
let exportsIsFunction = false
const exportNodes = ast.body
.filter(statement => statement.type === 'ExpressionStatement')
.map(statement => statement.expression)
.filter(expression => ... | javascript | {
"resource": ""
} |
q5922 | cookieToHeader | train | function cookieToHeader(cookies) {
const SEPARATOR = '; ';
return cookies.reduce(function (previous, current) {
return previous + current.name + '=' + current.value + SEPARATOR;
}, '');
} | javascript | {
"resource": ""
} |
q5923 | updateQuery | train | function updateQuery() {
let query = {};
switch(queryTemplates.value) {
case '0': // All raddecs
query = {
"size": 10,
"query": { "match_all": {} },
"_source": [ "transmitterId", "transmitterIdType", "receiverId",
"receiverIdType", "rssi", "timestamp",... | javascript | {
"resource": ""
} |
q5924 | parseQuery | train | function parseQuery() {
let query = {};
try { query = JSON.parse(queryBox.value); }
catch(error) {
queryError.textContent = 'Query must be valid JSON';
hide(queryButton);
hide(queryResults);
show(queryError);
return null;
}
hide(queryError);
show(queryButton);
return query;
} | javascript | {
"resource": ""
} |
q5925 | handleQuery | train | function handleQuery() {
let query = parseQuery();
let url = window.location.protocol + '//' + window.location.hostname + ':' +
window.location.port + ELASTICSEARCH_INTERFACE_ROUTE;
let httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if(httpRequest.readyState =... | javascript | {
"resource": ""
} |
q5926 | updateResults | train | function updateResults(response) {
responseHits.textContent = response.hits.total;
responseTime.textContent = response.took;
} | javascript | {
"resource": ""
} |
q5927 | updateHits | train | function updateHits(response) {
if(!response.hits.hasOwnProperty('hits') ||
(response.hits.hits.length === 0)) {
hide(hitsCard);
}
else {
show(hitsCard);
hitsBox.textContent = JSON.stringify(response.hits.hits, null, 2);
}
} | javascript | {
"resource": ""
} |
q5928 | updateAggregations | train | function updateAggregations(response) {
if(response.hasOwnProperty('aggregations')) {
aggregationsBox.textContent = JSON.stringify(response.aggregations,
null, 2);
show(aggregationsCard);
}
else {
hide(aggregationsCard);
}
} | javascript | {
"resource": ""
} |
q5929 | implodeArray | train | function implodeArray(tokens) {
var message = "", i, l;
l = tokens.length;
for (i = 0; i < l; i++) {
message += (i > 0 ? globals.SEP : "") + tokens[i];
}
return message;
} | javascript | {
"resource": ""
} |
q5930 | implodeData | train | function implodeData(data) {
var dataArray = [], field;
for(field in data) {
dataArray.push(types.STRING);
dataArray.push(encodeString(field));
dataArray.push(types.STRING);
dataArray.push(encodeString(data[field]));
}
return implodeArray(dataArray);
} | javascript | {
"resource": ""
} |
q5931 | implodeDataArray | train | function implodeDataArray(data) {
var dataArray = [], i, l;
l = data.length;
for(i = 0; i < l; i++) {
dataArray.push(types.STRING);
dataArray.push(encodeString(data[i]));
}
return implodeArray(dataArray);
} | javascript | {
"resource": ""
} |
q5932 | encodeString | train | function encodeString(string) {
//it actually accepts any kind of object as input
if (string === null) {
return values.NULL;
} else if (string === "") {
return values.EMPTY;
} else {//0 false undefined NaN will pass from here
return encodeURIComponent(string)
.replace(/%20/g, "+");
}
} | javascript | {
"resource": ""
} |
q5933 | decodeString | train | function decodeString (string) {
if (string === values.EMPTY) {
return "";
} else if (string === values.NULL) {
return null;
} else {
return decodeURIComponent(
string.replace(/\+/g,"%20"));
}
} | javascript | {
"resource": ""
} |
q5934 | encodeInteger | train | function encodeInteger(value) {
if (value === null) {
return values.NULL;
} else if (!isNaN(value) && parseInt(value)==value) {
return value + "";
} else {
throw new Error('Invalid integer value "' + value + '"');
}
} | javascript | {
"resource": ""
} |
q5935 | encodeDouble | train | function encodeDouble(value) {
if (value === null) {
return values.NULL;
} else if (!isNaN(value)) {
return value + "";
} else {
throw new Error('Invalid double value "' + value + '"');
}
} | javascript | {
"resource": ""
} |
q5936 | encodeMetadataException | train | function encodeMetadataException(type) {
if (type === "metadata") {
return exceptions.METADATA;
} else if (type === "access") {
return exceptions.ACCESS;
} else if (type === "credits") {
return exceptions.CREDITS;
} else if (type === "conflictingSession") {
return exceptions.CONFLICTING_SESSION;
} else if ... | javascript | {
"resource": ""
} |
q5937 | parse | train | function parse(data, initExpected) {
var lines, i, last;
data = tail + data;
data = data.replace(/\r*\n+/g, "\n");
lines = data.split("\n");
last = lines.length - 1;
for (i = 0; i < last; i++) {
messages.push(read(lines[i], initExpected));
}
tail = lines[lines.length - 1];
} | javascript | {
"resource": ""
} |
q5938 | bundleApp | train | function bundleApp(codeList, ns, domload, compile, before, npmTree, o) {
var l = []
, usedBuiltIns = npmTree._builtIns
, len = 0;
delete npmTree._builtIns;
// 1. construct the global namespace object
l.push("window." + ns + " = {data:{}, path:{}};");
// 2. attach path code to the namespace object so... | javascript | {
"resource": ""
} |
q5939 | train | function (onlyMain) {
codeList.forEach(function (pair) {
var dom = pair[0]
, file = pair[1]
, basename = file.split('.')[0];
if ((dom === 'app') !== onlyMain) {
return;
}
var code = before(compile(join(o.domains[dom], file)));
l.push(defineWrap(basename, dom, co... | javascript | {
"resource": ""
} | |
q5940 | subscribe | train | function subscribe(message) {
reply(proto.writeSubscribe(message.id));
subscritions[message.itemName] = message.id;
if (!isSnapshotAvailable(message.itemName)) {
notify(proto.writeEndOfSnapshot(message.id, message.itemName));
}
dequeueSubUnsubRequest(message.itemName);
fireFirstSubUnsubEvent(message.item... | javascript | {
"resource": ""
} |
q5941 | subscribeError | train | function subscribeError(message, exceptionMessage, exceptionType) {
reply(proto.writeSubscribeException(
message.id, exceptionMessage, exceptionType));
dequeueSubUnsubRequest(message.itemName);
fireFirstSubUnsubEvent(message.itemName);
} | javascript | {
"resource": ""
} |
q5942 | unsubscribe | train | function unsubscribe(message) {
reply(proto.writeUnsubscribe(message.id));
subscritions[message.itemName] = undefined;
dequeueSubUnsubRequest(message.itemName);
handleLateSubUnsubRequests(message.itemName);
fireFirstSubUnsubEvent(message.itemName);
} | javascript | {
"resource": ""
} |
q5943 | unsubscribeError | train | function unsubscribeError(message, exceptionMessage, exceptionType) {
reply(proto.writeUnsubscribeException(
message.id, exceptionMessage, exceptionType));
dequeueSubUnsubRequest(message.itemName);
fireFirstSubUnsubEvent(message.itemName);
} | javascript | {
"resource": ""
} |
q5944 | fireFirstSubUnsubEvent | train | function fireFirstSubUnsubEvent(itemName) {
if (subUnsubQueue[itemName].length > 0) {
request = subUnsubQueue[itemName][0];
that.emit(request.message.verb, itemName, request.response);
}
} | javascript | {
"resource": ""
} |
q5945 | train | function(message) {
if (that.listeners(message.verb).length) {
var successHandler = function(msg) {
reply(proto.writeInit(msg.id));
};
var errorHandler = function(msg, exceptionMessage, exceptionType) {
reply(proto.writeInitException(msg.id, exceptionMessage, exceptionType));
};
var res... | javascript | {
"resource": ""
} | |
q5946 | train | function(message) {
var response = new DataResponse(message, subscribe, subscribeError);
if (queueSubUnsubRequest(message, response) === 1) {
fireFirstSubUnsubEvent(message.itemName);
} else {
that.emit("subscribeInQueue", message.itemName);
}
} | javascript | {
"resource": ""
} | |
q5947 | train | function(message) {
var response = new DataResponse(message, unsubscribe, unsubscribeError);
if (queueSubUnsubRequest(message, response) === 1) {
fireFirstSubUnsubEvent(message.itemName);
} else {
that.emit("unsubscribeInQueue", message.itemName);
}
} | javascript | {
"resource": ""
} | |
q5948 | update | train | function update(itemName, isSnapshot, data) {
var message, id = getIdFromItemName(itemName);
message = proto.writeUpdate(id, itemName, isSnapshot, data);
notify(message);
return that;
} | javascript | {
"resource": ""
} |
q5949 | endOfSnapshot | train | function endOfSnapshot(itemName) {
var message, id = getIdFromItemName(itemName);
message = proto.writeEndOfSnapshot(id, itemName);
notify(message);
return that;
} | javascript | {
"resource": ""
} |
q5950 | clearSnapshot | train | function clearSnapshot(itemName) {
var message, id = getIdFromItemName(itemName);
message = proto.writeClearSnapshot(id, itemName);
notify(message);
return that;
} | javascript | {
"resource": ""
} |
q5951 | failure | train | function failure(exception) {
var message;
message = proto.writeFailure(exception);
notify(message);
return that;
} | javascript | {
"resource": ""
} |
q5952 | train | function (array1, array2) {
if (array1.length !== array2.length) {
return false;
}
// Clone the second array
array2 = array2.concat();
let i;
for (i = 0; i < array1.length; i++) {
let index = array2.indexOf(array1[i]);
if (index === -1) {
return false;
}
array2.splice(index, 1... | javascript | {
"resource": ""
} | |
q5953 | changeDropdownIndex | train | function changeDropdownIndex(page, ph, selectorAndIndex, callback) {
page.evaluate(function (selectorAndIndex) {
try {
var selector = selectorAndIndex[0];
var index = selectorAndIndex[1];
var element = document.querySelector(selector);
element.selectedIndex =... | javascript | {
"resource": ""
} |
q5954 | clickElement | train | function clickElement(page, ph, selectorAndOptions, callback) {
var selector = selectorAndOptions[0];
var options = selectorAndOptions[1];
function clickSelector(selector) {
try {
var button = document.querySelector(selector);
var ev = document.createEvent("MouseEvent");
... | javascript | {
"resource": ""
} |
q5955 | setCheckboxState | train | function setCheckboxState(page, ph, selectorAndState, callback) {
page.evaluate(function (selectorAndState) {
try {
var selector = selectorAndState[0];
var state = selectorAndState[1];
var element = document.querySelector(selector);
element.checked = state;
... | javascript | {
"resource": ""
} |
q5956 | fillForm | train | function fillForm(page, ph, selectorAndValue, callback) {
page.evaluate(function (selectorAndValue) {
try {
var selector = selectorAndValue[0];
var value = selectorAndValue[1];
document.querySelector(selector).value = value;
return null;
} catch (error... | javascript | {
"resource": ""
} |
q5957 | submitForm | train | function submitForm(page, ph, callback) {
var oldUrl;
async.waterfall([
function (callback) {
page.get('url', function (url) {
oldUrl = url;
callback();
});
},
function (callback) {
page.evaluate(function () {
... | javascript | {
"resource": ""
} |
q5958 | validate | train | function validate(args) {
var meta = args.query;
if (! (args.query || args.infoHash)) return { code: 0, message: "query/infoHash required" };
if (meta && !meta.imdb_id) return { code: 1, message: "imdb_id required" };
if (meta && (meta.type == "series" && !(meta.hasOwnProperty("episode") && meta.hasOwnP... | javascript | {
"resource": ""
} |
q5959 | LinkedinTokenStrategy | train | function LinkedinTokenStrategy(options, verify) {
options = options || {}
options.authorizationURL = options.authorizationURL || 'https://www.linkedin.com';
options.tokenURL = options.tokenURL || 'https://www.linkedin.com/uas/oauth2/accessToken';
options.scopeSeparator = options.scopeSeparator || ',';
this._... | javascript | {
"resource": ""
} |
q5960 | getProperty | train | function getProperty(style, name)
{
if(style[name] !== void 0)
{
return [name, style[name]];
}
if(name in propertyNames)
{
return [propertyNames[name], style[propertyNames[name]]];
}
name = name.substr(0, 1).toUpperCase() + name.substr(1);
var prefixes = ['webkit', 'moz',... | javascript | {
"resource": ""
} |
q5961 | parse | train | function parse(str, options) {
var obj = options.object || 'obj'
, space = options.pretty ? 2 : 0
, space = options.spaces ? options.spaces : space
, js = str;
return ''
+ 'var ' + obj + ' = factory();\n'
+ (options.self
? 'var self = locals || {};\n' + js
: 'with (locals || {}) {... | javascript | {
"resource": ""
} |
q5962 | Verifier | train | function Verifier(givenMasterKey) {
var masterKey = givenMasterKey || MASTER_KEY;
if (!masterKey) {
throw new errors.ValidationFailed('invalid master key');
}
this.masterKey = base64url.toBuffer(masterKey);
} | javascript | {
"resource": ""
} |
q5963 | inArray | train | function inArray(array, search)
{
if(!isArray(array))
{
throw 'expected an array as first param';
}
if(array.indexOf)
{
return array.indexOf(search);
}
for(var i = 0, end = array.length; i < end; i++)
{
if(array[i] === search)
{
return i;
... | javascript | {
"resource": ""
} |
q5964 | toArray | train | function toArray(args, pos)
{
if(pos === void 0)
{
pos = 0;
}
return Array.prototype.slice.call(args, pos);
} | javascript | {
"resource": ""
} |
q5965 | convertTime | train | function convertTime(value, fromUnit, toUnit)
{
if(fromUnit != toUnit && value !== 0)
{
return value * (toUnit == 's'? 0.001 : 1000);
}
return value;
} | javascript | {
"resource": ""
} |
q5966 | compoundMapping | train | function compoundMapping(name, value)
{
var parts, nameParts, prefix, suffix, dirs, values = {}, easing, i;
if(isArray(value))
{
value = value[0];
easing = value[1];
}
else
{
easing = null;
}
parts = String(value).split(/\s+/);
switch(parts.length)
{
... | javascript | {
"resource": ""
} |
q5967 | transformMapping | train | function transformMapping(name, value)
{
var easing, dirs = ['X', 'Y', 'Z'], values = {}, parts, baseName;
if(isArray(value))
{
value = value[0];
easing = value[1];
}
else
{
easing = null;
}
parts = String(value).split(/\s*,\s*/);
baseName = name.indexOf('3')... | javascript | {
"resource": ""
} |
q5968 | parseSpeed | train | function parseSpeed(value)
{
if(value in speeds)
{
value = speeds[value];
}
value = parseFloat(value);
if(isNaN(value) || !value || value <= 0)
{
value = 1;
}
return value;
} | javascript | {
"resource": ""
} |
q5969 | get | train | function get(target, path) {
var result = target;
for (var i = 0; i < path.length; i++) {
result = result ? result[path[i]] : result;
}
return result;
} | javascript | {
"resource": ""
} |
q5970 | findOneJsInArray | train | function findOneJsInArray(ary) {
var found,
count = 0;
ary.forEach(function(entry) {
if (jsExtRegExp.test(entry)) {
count += 1;
found = entry;
}
});
return count === 1 ? found : null;
} | javascript | {
"resource": ""
} |
q5971 | InvalidSignature | train | function InvalidSignature(reason) {
Error.captureStackTrace(this, this.constructor);
this.type = 'unauthorized';
this.statusCode = 401;
this.message = 'Invalid request signature';
this.reason = reason;
} | javascript | {
"resource": ""
} |
q5972 | ValidationFailed | train | function ValidationFailed(reason) {
Error.captureStackTrace(this, this.constructor);
this.type = 'bad_request';
this.statusCode = 400;
this.message = 'Request validation failed';
this.reason = reason;
} | javascript | {
"resource": ""
} |
q5973 | Signature | train | function Signature(req, buf) {
this.req = req;
this.rawBody = buf || req.rawBody;
this.xSignature = (req.headers['x-signature'] || '').split(' ');
this.signature = base64url.toBuffer(this.xSignature[0] || '');
this.publicKey = base64url.toBuffer(this.xSignature[1] || '');
this.endorsement = base64url.toBuf... | javascript | {
"resource": ""
} |
q5974 | train | function (cb) {
get(SOLVENCY_SERVER + domain, function (roots) {
roots = roots || [];
roots.forEach(function (root) {
files.push({ path: 'root', type: 'root', content: root });
});
cb();
});
} | javascript | {
"resource": ""
} | |
q5975 | train | function (cb) {
files.forEach(function (file) {
var proof = file.content;
if (!proof) return;
if (!proof.id) {
errors.push(file.path + ' has no ID property.');
return;
}
res[proof.id] = res[proof.id] || {};
res[proof.id][file.type] = proof;
... | javascript | {
"resource": ""
} | |
q5976 | throttle | train | function throttle(fn, timeout) {
var timer = null;
return function () {
if (!timer) {
timer = setTimeout(function() {
fn();
timer = null;
}, timeout);
}
};
} | javascript | {
"resource": ""
} |
q5977 | addEvent | train | function addEvent(node, event, fn, opt_useCapture) {
if (typeof node.addEventListener == 'function') {
node.addEventListener(event, fn, opt_useCapture || false);
}
else if (typeof node.attachEvent == 'function') {
node.attachEvent('on' + event, fn);
}
} | javascript | {
"resource": ""
} |
q5978 | removeEvent | train | function removeEvent(node, event, fn, opt_useCapture) {
if (typeof node.removeEventListener == 'function') {
node.removeEventListener(event, fn, opt_useCapture || false);
}
else if (typeof node.detatchEvent == 'function') {
node.detatchEvent('on' + event, fn);
}
... | javascript | {
"resource": ""
} |
q5979 | computeRectIntersection | train | function computeRectIntersection(rect1, rect2) {
var top = Math.max(rect1.top, rect2.top);
var bottom = Math.min(rect1.bottom, rect2.bottom);
var left = Math.max(rect1.left, rect2.left);
var right = Math.min(rect1.right, rect2.right);
var width = right - left;
var height ... | javascript | {
"resource": ""
} |
q5980 | getBoundingClientRect | train | function getBoundingClientRect(el) {
var rect;
try {
rect = el.getBoundingClientRect();
} catch (err) {
// Ignore Windows 7 IE11 "Unspecified error"
// https://github.com/WICG/IntersectionObserver/pull/205
}
if (!rect) return getEmptyRect();
... | javascript | {
"resource": ""
} |
q5981 | getParentNode | train | function getParentNode(node) {
var parent = node.parentNode;
if (parent && parent.nodeType == 11 && parent.host) {
// If the parent is a shadow root, return the host element.
return parent.host;
}
return parent;
} | javascript | {
"resource": ""
} |
q5982 | compact | train | function compact(list,typ) {
if(arguments.length === 1) {
if (Array.isArray(list)) {
// if the only one param is an array
return list.filter(x=>x);
} else {
// Curry it manually
typ = list;
return function (list) {return compact(list, typ)};
}
}
retu... | javascript | {
"resource": ""
} |
q5983 | drop | train | function drop(list,dropCount=1,direction="left",fn=null) {
// If the first argument is not kind of `array`-like.
if (!(list && Array.isArray(list))) {
// Manually currying
let args = arguments;
return (list) => drop(list, ...args);
}
if(dropCount === 0 && !fn) {
return Array.pr... | javascript | {
"resource": ""
} |
q5984 | fill | train | function fill(list, value, startIndex=0, endIndex=list.length){
if (!(list && Array.isArray(list))) {
// Manually currying
let args = arguments;
return (list) => fill(list, ...args);
}
return Array(...list).map((x,i)=> {
if(i>= startIndex && i <= endIndex) {
return x=value;
... | javascript | {
"resource": ""
} |
q5985 | train | function (...values) {
let list = [];
let {main, follower} = reuseables.getMainAndFollower(values);
main.forEach(x=>{
if(list.indexOf(x) ==-1) {
if(follower.indexOf(x) >=0) {
if(list[x] ==undefined) list.push(x) }
}
})
return list;
} | javascript | {
"resource": ""
} | |
q5986 | join | train | function join(joiner, ...values) {
if (values.length > 0) {
return concat([],...values).join(joiner);
}
// Manually currying
return (...values) => join(joiner, ...values);
} | javascript | {
"resource": ""
} |
q5987 | nth | train | function nth(list, indexNum) {
if (arguments.length == 1) {
// Manually currying
indexNum = list;
return (list) => nth(list, indexNum);
}
if(indexNum >= 0) {
return list[+indexNum]
};
return [...list].reverse()[list.length+indexNum];
} | javascript | {
"resource": ""
} |
q5988 | sortedIndex | train | function sortedIndex(list, value, valueIndex) {
if (!(list && Array.isArray(list))) {
// Manually currying
let args = arguments;
return (list) => sortedIndex(list, ...args);
}
return reuseables.sorter(list, value, valueIndex);
} | javascript | {
"resource": ""
} |
q5989 | train | function(list){
const listNoDuplicate = difference([],list);
if(typeof list[0] == "number") {
return listNoDuplicate.sort((a,b)=>a-b);
}
return listNoDuplicate.sort();
} | javascript | {
"resource": ""
} | |
q5990 | union | train | function union(list1, list2, duplicate=false) {
if ( arguments.length < 2 ) {
// Manually currying
let args1 = arguments;
return (...args2) => union(...args1, ...args2);
} else if (arguments.length === 2 && (! Array.isArray(list2))) {
// curring union(_, list, duplicate) cases
// ... | javascript | {
"resource": ""
} |
q5991 | merge | train | function merge(torrents)
{
// NOTE: here, on the merge logic, we can set properties that should always be set
// Or just rip out the model logic from LinvoDB into a separate module and use it
return torrents.reduce(function(a, b) {
return _.merge(a, b, function(x, y) {
// this is for the files array, and we wa... | javascript | {
"resource": ""
} |
q5992 | through | train | function through(transform, flush, objectMode) {
const stream = new TransformStream({objectMode})
stream._transform = transform || pass
if (flush) stream._flush = flush
return stream
} | javascript | {
"resource": ""
} |
q5993 | patchUser | train | function patchUser(user, patchToUser) {
return users.patch(user.id || user._id, patchToUser, {}) // needs users from closure
.then(() => Object.assign(user, patchToUser));
} | javascript | {
"resource": ""
} |
q5994 | injectForeignFields | train | function injectForeignFields(targetEntity) {
switch (type) {
case '1:1':
return entityModifier.readEntityProperty(targetEntity, 'fields').then(function(fields) {
fields.push(entity.primary);
entityModifier.modifyEntityProperty(targetEntity, 'fi... | javascript | {
"resource": ""
} |
q5995 | FA2LayoutSupervisor | train | function FA2LayoutSupervisor(graph, params) {
params = params || {};
// Validation
if (!isGraph(graph))
throw new Error('graphology-layout-forceatlas2/worker: the given graph is not a valid graphology instance.');
// Validating settings
var settings = helpers.assign({}, DEFAULT_SETTINGS, params.settings... | javascript | {
"resource": ""
} |
q5996 | StablePriorityQueue | train | function StablePriorityQueue(comparator) {
this.array = [];
this.size = 0;
this.runningcounter = 0;
this.compare = comparator || defaultcomparator;
this.stable_compare = function(a, b) {
var cmp = this.compare(a.value,b.value);
return (cmp < 0) || ( (cmp == 0) && (a.counter < b.counter) ... | javascript | {
"resource": ""
} |
q5997 | train | function () {
// main code
var x = new StablePriorityQueue(function (a, b) {
return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0) ;
});
x.add({name:"Jack", age:31});
x.add({name:"Anna", age:111});
x.add({name:"Jack", age:46});
x.add({name:"Jack", age:11});
x.add({name:"Abba", ... | javascript | {
"resource": ""
} | |
q5998 | train | function (obj) {
var toc = [],
tocTmpl = _.template("* [<%= heading %>](#<%= id %>)\n"),
sectionTmpl = _.template("### <%= summary %>\n\n<%= body %>\n");
// Finesse comment markdown data.
// Also, statefully create TOC.
var sections = _.chain(obj)
.filter(function (c) {
return !c.isPrivate &&... | javascript | {
"resource": ""
} | |
q5999 | abstractSynchronousLayout | train | function abstractSynchronousLayout(assign, graph, params) {
if (!isGraph(graph))
throw new Error('graphology-layout-forceatlas2: the given graph is not a valid graphology instance.');
if (typeof params === 'number')
params = {iterations: params};
var iterations = params.iterations;
if (typeof iterati... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.