_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q46700 | truncate | train | function truncate(arr, len) {
if (arr.length > len) {
arr.length = len;
return true;
}
} | javascript | {
"resource": ""
} |
q46701 | writeReduceForLoop | train | function writeReduceForLoop(t, path, reducePath, reduceRight) {
const reduceCall = reducePath.node;
const array = defineIdIfNeeded(t, reducePath.get('callee.object'), path);
const func = extractDynamicFuncIfNeeded(t, reducePath, path);
const acc = path.scope.generateUidIdentifier('acc');
const i = path.scope.gener... | javascript | {
"resource": ""
} |
q46702 | randomArray | train | function randomArray(size) {
const cache = arrayCaches[size];
return cache[Math.floor(Math.random() * cache.length)];
} | javascript | {
"resource": ""
} |
q46703 | json2md | train | function json2md(data, prefix, _type) {
prefix = prefix || ""
if (typeof data === "string" || typeof data === "number") {
return indento(data, 1, prefix)
}
let content = []
// Handle arrays
if (Array.isArray(data)) {
for (let i = 0; i < data.length; ++i) {
content.p... | javascript | {
"resource": ""
} |
q46704 | train | function() {
var muteControl = this.options.muted ? 'fa-volume-off' : 'fa-volume-up';
var playPauseControl = this.options.autoplay ? 'fa-pause' : 'fa-play';
var controlsHTML = ' \
<div class="controlsWrapper">\
<div class="valiant-progress-bar">\
... | javascript | {
"resource": ""
} | |
q46705 | cacheUniformLocations | train | function cacheUniformLocations ( program, identifiers ) {
var i, l, id;
for( i = 0, l = identifiers.length; i < l; i ++ ) {
id = identifiers[ i ];
program.uniforms[ id ] = _gl.getUniformLocation( program, id );
}
} | javascript | {
"resource": ""
} |
q46706 | train | function() {
var factConj = '';
for(var key in this.causes) {
factConj += ' ^ ' + this.causes[key].toString().substring(1).replace(/,/g, '');
}
for(var key in this.operatorCauses) {
factConj += ' ^ ' + this.operatorCauses[key].toString().substring(1).replace(/,/g,... | javascript | {
"resource": ""
} | |
q46707 | train | function(FeAdd, FeDel, F, R) {
var FiAdd = [], FiAddNew = [], additions, deletions,
Fe = Logics.getOnlyExplicitFacts(F), FiAddNew = [];
// Deletion
if(FeDel && FeDel.length) {
Fe = Logics.minus(Fe, FeDel);
}
// Insertion
if(FeAdd && FeAdd.length)... | javascript | {
"resource": ""
} | |
q46708 | train | function (FeAdd, FeDel, F, R) {
var Rdel = [], Rred = [], Rins = [],
FiDel = [], FiAdd = [],
FiDelNew = [], FiAddNew = [],
superSet = [],
additions, deletions,
Fe = Logics.getOnlyExplicitFacts(F),
Fi = Logics.getOnlyImplicitFacts(... | javascript | {
"resource": ""
} | |
q46709 | train | function(F) {
var validSet = [];
for (var i = 0; i < F.length; i++) {
if (F[i].isValid()) {
validSet.push(F[i]);
}
}
return validSet;
} | javascript | {
"resource": ""
} | |
q46710 | train | function(fs, subset) {
for (var i = 0; i < fs.length; i++) {
for (var j = 0; j < subset.length; j++) {
if ((subset[j] !== undefined) && (fs[i].equivalentTo(subset[j]))) {
fs[i].causedBy = this.uniquesCausedBy(fs[i].causedBy, subset[j].causedBy);
... | javascript | {
"resource": ""
} | |
q46711 | train | function(fs) {
var fR = [];
for (var key in fs) {
var fact = fs[key];
if(!fact.explicit) {
fR.push(fact);
}
}
return fR;
} | javascript | {
"resource": ""
} | |
q46712 | train | function(rs, fs) {
var restriction = [];
for (var i = 0; i < rs.length; i++) {
var rule = rs[i], matches = false;
for (var j = 0; j < rule.causes.length; j++) {
var cause = rule.causes[j];
for (var k = 0; k < fs.length; k++) {
... | javascript | {
"resource": ""
} | |
q46713 | train | function(cause, fact) {
return this.causeMemberMatchesFactMember(cause.predicate, fact.predicate)
&& this.causeMemberMatchesFactMember(cause.subject, fact.subject)
&& this.causeMemberMatchesFactMember(cause.object, fact.object);
} | javascript | {
"resource": ""
} | |
q46714 | train | function(atom1, atom2) {
if (this.isVariable(atom1) && this.isVariable(atom2) ) {
return true;
} else if(atom1 == atom2) {
return true;
} else {
return false;
}
} | javascript | {
"resource": ""
} | |
q46715 | train | function(fs1, fs2) {
if(!fs2 || (fs2.length > fs1.length)) return false;
for (var key in fs2) {
var fact = fs2[key];
if(!(fact.appearsIn(fs1))) {
return false;
}
}
return true;
} | javascript | {
"resource": ""
} | |
q46716 | train | function(_set1, _set2) {
var flagEquals,
newSet = [];
for (var i = 0; i < _set1.length; i++) {
flagEquals = false;
for(var j = 0; j < _set2.length; j++) {
if (_set1[i].asString == _set2[j].asString) {
flagEquals = true;
... | javascript | {
"resource": ""
} | |
q46717 | train | function(req, res, next) {
var initialTime = req.query.time,
receivedReqTime = new Date().getTime(),
filename = req.params.filename,
absolutePathToFile = ontoDir + '/' + filename,
extension = path.extname(absolutePathToFile),
contentType = mime.content... | javascript | {
"resource": ""
} | |
q46718 | train | function(req, res) {
if (req.headers.accept == 'application/json') {
res.header('Content-Type', 'application/json');
res.status(200).json({
data: {
ontologyTxt: req.rawOntology,
mimeType: req.mimeType
},
... | javascript | {
"resource": ""
} | |
q46719 | train | function(req, res, next) {
var initialTime = 0,
receivedReqTime = new Date().getTime();
req.requestDelay = receivedReqTime - initialTime;
var url = req.body.url;
request.get(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
... | javascript | {
"resource": ""
} | |
q46720 | train | function(rs, facts, doTagging, resolvedImplicitFactSet) {
var deferred = q.defer(), promises = [], cons = [], filteredFacts;
for (var key in rs) {
if (doTagging) {
promises.push(this.evaluateThroughRestrictionWithTagging(rs[key], facts, resolvedImplicitFactSet));
... | javascript | {
"resource": ""
} | |
q46721 | train | function(rule, facts) {
var mappingList = this.getMappings(rule, facts),
consequences = [], deferred = q.defer();
try {
this.checkOperators(rule, mappingList);
for (var i = 0; i < mappingList.length; i++) {
if (mappingList[i]) {
... | javascript | {
"resource": ""
} | |
q46722 | train | function(rule, kb) {
var mappingList = this.getMappings(rule, kb), deferred = q.defer(),
consequences = [], consequence, causes, iterationConsequences;
this.checkOperators(rule, mappingList);
try {
for (var i = 0; i < mappingList.length; i++) {
if (mappi... | javascript | {
"resource": ""
} | |
q46723 | train | function(currentCauses, nextCause, facts, constants, rule) {
var substitutedNextCauses = [],
mappings = [];
for (var i = 0; i < currentCauses.length; i++) {
for (var j = 0; j < facts.length; j++) {
// Get the mapping of the current cause ...
var... | javascript | {
"resource": ""
} | |
q46724 | train | function(fact, ruleFact, mapping, constants, rule) {
var localMapping = {};
// Checks and update localMapping if matches
if (!this.factElemMatches(fact.predicate, ruleFact.predicate, mapping, localMapping)) {
return false;
}
if (!this.factElemMatches... | javascript | {
"resource": ""
} | |
q46725 | train | function(elem, mapping) {
if(Logics.isBNode(elem)) {
return Logics.skolemize(mapping.__facts__, elem);
} else if(Logics.isVariable(elem)) {
if (mapping[elem] !== undefined) {
return mapping[elem]
}
}
return elem;
} | javascript | {
"resource": ""
} | |
q46726 | train | function(t, explicit, notUsingValid) {
if(explicit === undefined) {
explicit = true;
}
return new Fact(t.predicate.toString(), t.subject.toString(), t.object.toString()/*.format()*/, [], explicit, [], [], notUsingValid, t.toString())
} | javascript | {
"resource": ""
} | |
q46727 | train | function(fact) {
var subject, predicate, object;
/*if (fact.fromTriple !== undefined) {
return fact.fromTriple;
}*/
if(fact.falseFact) {
return '';
}
subject = this.parseStrEntityToTurtle(fact.subject);
predicate = this.parseStrEntityToT... | javascript | {
"resource": ""
} | |
q46728 | train | function(facts) {
var ttl = '', fact,
that = this;
for (var i = 0; i < facts.length; i++) {
fact = facts[i];
ttl += that.factToTurtle(fact);
}
return ttl;
} | javascript | {
"resource": ""
} | |
q46729 | train | function() {
var e, spo;
if(this.falseFact) {
spo = 'FALSE';
} else {
spo = '(' + Utils.removeBeforeSharp(this.subject) + ', ' + Utils.removeBeforeSharp(this.predicate) + ', ' + Utils.removeBeforeSharp(this.object) + ')'
}
this.explicit ? e = 'E' : e = '... | javascript | {
"resource": ""
} | |
q46730 | train | function(fact) {
if ((this.explicit != fact.explicit) ||
(this.subject != fact.subject) ||
(this.predicate != fact.predicate) ||
(this.object != fact.object)) {
return false;
}
return true;
} | javascript | {
"resource": ""
} | |
q46731 | train | function(factSet) {
var that = this;
for (var key in factSet) {
if(that.equivalentTo(factSet[key])){
return key;
}
}
return false;
} | javascript | {
"resource": ""
} | |
q46732 | train | function() {
if (this.explicit) {
return this.valid;
} else if (this.causedBy === undefined || this.causedBy.length == 0) {
return undefined;
} else {
var valid,
causes = this.causedBy,
explicitFact;
for (var i = 0; ... | javascript | {
"resource": ""
} | |
q46733 | train | function(_set1, _set2) {
var hash = {}, uniq = [],
fullSet = _set1.concat(_set2);
for (var i = 0; i < fullSet.length; i++) {
if (fullSet[i] !== undefined) hash[fullSet[i].toString()] = fullSet[i];
}
for (var key in hash) {
uniq.push(hash[key... | javascript | {
"resource": ""
} | |
q46734 | Channel | train | function Channel (id, socket) {
var log = debug('webrtc-tree-overlay:channel(' + id + ')')
this._log = log
var self = this
this.id = id
this._socket = socket
.on('data', function (data) {
log('received data:')
log(data.toString())
var message = JSON.parse(data)
if (message.type ===... | javascript | {
"resource": ""
} |
q46735 | _getErrorCorrectLevel | train | function _getErrorCorrectLevel(ecl) {
switch (ecl) {
case "L":
return QRErrorCorrectLevel.L;
case "M":
return QRErrorCorrectLevel.M;
case "Q":
return QRErrorCorrectLevel.Q;
case "H":
return QRErrorCorrectLevel.H;
default:
... | javascript | {
"resource": ""
} |
q46736 | _getTypeNumber | train | function _getTypeNumber(content, ecl) {
var length = _getUTF8Length(content);
var type = 1;
var limit = 0;
for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) {
var table = QRCodeLimitLength[i];
if (!table) {
throw new Error("Content too long: expected " + limit + " but g... | javascript | {
"resource": ""
} |
q46737 | _getUTF8Length | train | function _getUTF8Length(content) {
var result = encodeURI(content).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
return result.length + (result.length != content ? 3 : 0);
} | javascript | {
"resource": ""
} |
q46738 | getShapeZero | train | function getShapeZero(x,y,options,modules){
var EOL = '\r\n';
var width = options.width;
var height = options.height;
var length = modules.length;
var style = options.style;
var xsize = width / (length + 2 * options.padding);
var ysize = height / (length + 2 * options.padding);
var px = (x * xsize + op... | javascript | {
"resource": ""
} |
q46739 | setupReqCounter | train | function setupReqCounter() {
reqCounter = reqCounter || new ReqCounter();
process.monitor.getRequestCount = function () {
return reqCounter._requests;
};
process.monitor.getTotalRequestCount = function () {
return reqCounter._totalRequests;
};
process.monitor.getTransferred =... | javascript | {
"resource": ""
} |
q46740 | startLuxometerNotifications | train | function startLuxometerNotifications()
{
showMessage('Scanning...')
bleat.requestDevice(
{
filters:[{ name: 'CC2650 SensorTag' }]
})
.then(function(device)
{
showMessage('Found device: ' + device.name)
return device.gatt.connect()
})
.then(function(server)
{
gattServer = server
showMessage('Connecte... | javascript | {
"resource": ""
} |
q46741 | onLuxometerChanged | train | function onLuxometerChanged(event)
{
var characteristic = event.target
var lux = calculateLux(characteristic.value)
showMessage('Luxometer value: ' + lux)
} | javascript | {
"resource": ""
} |
q46742 | calculateLux | train | function calculateLux(data)
{
// Get 16 bit value from data buffer in little endian format.
var value = data.getUint16(0, true)
// Extraction of luxometer value, based on sfloatExp2ToDouble
// from BLEUtility.m in Texas Instruments TI BLE SensorTag
// iOS app source code.
var mantissa = value & 0x0FFF
var expon... | javascript | {
"resource": ""
} |
q46743 | findDevice | train | function findDevice()
{
disconnectDevice()
// Used for debugging/testing.
//scanForDevice()
//return
searchForBondedDevice({
name: 'HEXIWEAR',
serviceUUIDs: [INFO_SERVICE],
onFound: connectToDevice,
onNotFound: scanForDevice,
})
} | javascript | {
"resource": ""
} |
q46744 | searchForBondedDevice | train | function searchForBondedDevice(params)
{
console.log('Searching for bonded device')
evothings.ble.getBondedDevices(
// Success function.
function(devices)
{
for (var i in devices)
{
var device = devices[i]
if (device.name == params.name)
{
console.log('Found bonded device: ' + device.name... | javascript | {
"resource": ""
} |
q46745 | getCanonicalUUIDArray | train | function getCanonicalUUIDArray(uuidArray)
{
var result = [];
for (var i in uuidArray)
{
result.push(exports.getCanonicalUUID(uuidArray[i]));
}
return result;
} | javascript | {
"resource": ""
} |
q46746 | littleEndianToUint32 | train | function littleEndianToUint32(data, offset)
{
return (littleEndianToUint8(data, offset + 3) << 24) +
(littleEndianToUint8(data, offset + 2) << 16) +
(littleEndianToUint8(data, offset + 1) << 8) +
littleEndianToUint8(data, offset)
} | javascript | {
"resource": ""
} |
q46747 | littleEndianToInt8 | train | function littleEndianToInt8(data, offset)
{
var x = littleEndianToUint8(data, offset)
if (x & 0x80) x = x - 256
return x
} | javascript | {
"resource": ""
} |
q46748 | gattServerCallbackHandler | train | function gattServerCallbackHandler(winFunc, settings) {
// collect read/write callbacks and add handles, so the native side can tell us which one to call.
var readCallbacks = {};
var writeCallbacks = {};
var nextHandle = 1;
function handleCallback(object, name, callbacks) {
if(!object[name]) {
throw name+" m... | javascript | {
"resource": ""
} |
q46749 | train | function (containerId) {
for (var property in winble.deviceManager.deviceList) {
if (winble.deviceManager.deviceList[property] && winble.deviceManager.deviceList[property].containerId == containerId)
return (winble.deviceManager.deviceList[property]);
}
return (null);
} | javascript | {
"resource": ""
} | |
q46750 | train | function (deviceHandle, functionName, errorCallback) {
var device = winble.deviceManager.deviceList[deviceHandle];
if (device == null) {
var msg = "Could not find the requested device handle '" + deviceHandle + "'";
winble.logger.logError(functionName, msg);
errorCallback(winble.DEVICE_NOT_FOUND);
... | javascript | {
"resource": ""
} | |
q46751 | train | function (device, serviceHandle, functionName, errorCallback) {
var service = device.serviceList[serviceHandle];
if (service == null) {
var msg = "Could not find the requested service handle '" + serviceHandle + "'";
winble.logger.logError(functionName, msg);
errorCallback(msg);
}
return (servic... | javascript | {
"resource": ""
} | |
q46752 | train | function (device, charHandle, functionName, errorCallback) {
var characteristic = device.charList[charHandle];
if (characteristic == null) {
var msg = "Could not find the requested characteristic handle '" + charHandle + "'";
winble.logger.logError(functionName, msg);
errorCallback(msg);
}
retur... | javascript | {
"resource": ""
} | |
q46753 | train | function (successCallback, errorCallback) {
if (!winble.deviceManager.isScanning) {
winble.deviceManager.scanSuccessCallback = successCallback;
winble.deviceManager.scanErrorCallback = errorCallback;
winble.deviceManager.isScanning = true;
setTimeout(function () {
winble.deviceManager.scanDevice... | javascript | {
"resource": ""
} | |
q46754 | train | function () {
if (winble.deviceManager.isScanning)
winble.deviceManager.isScanning = false;
if (winble.deviceManager.connectionWatcher !== null)
winble.deviceManager.stopConnectionWatcher();
} | javascript | {
"resource": ""
} | |
q46755 | train | function (successCallback) {
// If the caller told us to stop scanning since our last scan, or all devices have been removed from the list, nothing to do
if (!winble.deviceManager.isScanning || (winble.deviceManager.reportList.length == 0)) {
winble.deviceManager.isReporting = false;
return;
}
// ... | javascript | {
"resource": ""
} | |
q46756 | train | function (successCallback, errorCallback, deviceId) {
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromId(deviceId, "connectToDevice", errorCallback);
if (device == null) {
errorCallback(winble.DEVICE_NOT_FOUND);
return;
}
// Save the... | javascript | {
"resource": ""
} | |
q46757 | train | function () {
winble.deviceManager.connectionWatcher = Windows.Devices.Enumeration.Pnp.PnpObject.createWatcher(
Windows.Devices.Enumeration.Pnp.PnpObjectType.deviceContainer,
["System.Devices.Connected"],
"");
winble.deviceManager.connectionWatcher.onupdated = winble.deviceManager.onDeviceConnectionUp... | javascript | {
"resource": ""
} | |
q46758 | train | function (successCallback, errorCallback, deviceHandle) {
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromHandle(deviceHandle, "closeDevice", errorCallback);
if (device == null)
return;
// Remove the device from our list
winble.deviceMan... | javascript | {
"resource": ""
} | |
q46759 | train | function (successCallback, errorCallback, deviceHandle) {
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromHandle(deviceHandle, "getDeviceRssi", errorCallback);
if (device == null)
return;
// Return the RSSI value
winble.logger.logDebug("... | javascript | {
"resource": ""
} | |
q46760 | train | function (successCallback, errorCallback, deviceHandle) {
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromHandle(deviceHandle, "getDeviceServices", errorCallback);
if (device == null)
return;
// Enumerate the services
winble.bleDevice.fr... | javascript | {
"resource": ""
} | |
q46761 | train | function (successCallback, errorCallback, deviceHandle, serviceHandle) {
winble.logger.logDebug("getServiceCharacteristics", "deviceHandle='" + deviceHandle + ", serviceHandle='" + serviceHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDevice... | javascript | {
"resource": ""
} | |
q46762 | train | function (successCallback, errorCallback, deviceHandle, charHandle) {
winble.logger.logDebug("getCharacteristicDescriptors", "deviceHandle='" + deviceHandle + ", charHandle='" + charHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromHa... | javascript | {
"resource": ""
} | |
q46763 | train | function (successCallback, errorCallback, deviceHandle, charHandle) {
winble.logger.logDebug("readCharacteristic", "deviceHandle='" + deviceHandle + ", charHandle='" + charHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromHandle(devic... | javascript | {
"resource": ""
} | |
q46764 | train | function (successCallback, errorCallback, deviceHandle, charHandle, dataBuffer) {
winble.logger.logDebug("writeCharacteristic", "deviceHandle='" + deviceHandle + ", charHandle='" + charHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFro... | javascript | {
"resource": ""
} | |
q46765 | train | function (successCallback, errorCallback, deviceHandle, descHandle, dataBuffer) {
winble.logger.logDebug("writeDescriptor", "deviceHandle='" + deviceHandle + ", descHandle='" + descHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFromHan... | javascript | {
"resource": ""
} | |
q46766 | train | function (successCallback, errorCallback, deviceHandle, charHandle) {
winble.logger.logDebug("enableCharacteristicNotification", "deviceHandle='" + deviceHandle + ", charHandle='" + charHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceFr... | javascript | {
"resource": ""
} | |
q46767 | train | function (successCallback, errorCallback, deviceHandle, charHandle) {
winble.logger.logDebug("disableCharacteristicNotification", "deviceHandle='" + deviceHandle + ", charHandle='" + charHandle + "'");
// Find the requested device in our list of discovered devices
var device = winble.deviceManager.getDeviceF... | javascript | {
"resource": ""
} | |
q46768 | arrayToUUID | train | function arrayToUUID(array, offset)
{
var k=0;
var string = '';
var UUID_format = [4, 2, 2, 2, 6];
for (var l=0; l<UUID_format.length; l++)
{
if (l != 0)
{
string += '-';
}
for (var j=0; j<UUID_format[l]; j++, k++)
{
string += evothings.util.toHexString(array[... | javascript | {
"resource": ""
} |
q46769 | train | function(connectInfo)
{
// DEBUG LOG
console.log('BLE connect state: ' + connectInfo.state);
if (connectInfo.state == 2) // connected
{
device.deviceHandle = connectInfo.deviceHandle;
device.__uuidMap = {};
device.__serviceMap = {};
device.__isConnected = true;
internal.c... | javascript | {
"resource": ""
} | |
q46770 | train | function(errorCode)
{
// DEBUG LOG
console.log('BLE connect error: ' + errorCode);
// Set isConnected to false on error.
device.__isConnected = false;
internal.connectedDevices[device.address] = null;
fail(errorCode);
} | javascript | {
"resource": ""
} | |
q46771 | draggable | train | function draggable(e) {
e.preventDefault();
previousEvent = e;
document.addEventListener('mousemove', drag);
document.addEventListener('mouseup', removeDrag);
} | javascript | {
"resource": ""
} |
q46772 | buildPreviewUrl | train | function buildPreviewUrl (pose, scale, gender, style, rotation, traits, outfit) {
// use string templating to build the url
let url = `${basePreviewUrl}${pose}?scale=${scale}&gender=${gender}&style=${style}`
url += `&rotation=${rotation}${mapTraits(traits).join("")}&outfit=${outfit}`
return url;
} | javascript | {
"resource": ""
} |
q46773 | buildFriendmojiUrl | train | function buildFriendmojiUrl (comicId, avatarId1, avatarId2, transparent, scale) {
return `${baseCpanelUrl}${comicId}-${avatarId1}-${avatarId2}-v3.png?transparent=${transparent}&scale=${scale}`;
} | javascript | {
"resource": ""
} |
q46774 | structureResolve | train | function structureResolve(resolve, sPathStartWith) {
var aToResolve = [];
var aResolved = [];
if (typeof resolve === 'object' && resolve instanceof Array) {
aToResolve = resolve;
} else if (typeof resolve === 'string') {
aToResolve.push(resolve);
} else {
return null;
}
... | javascript | {
"resource": ""
} |
q46775 | splitIntoPathAndObject | train | function splitIntoPathAndObject(sValue) {
var aValues = sValue.split('/');
var sObject = aValues.pop();
var sPath = aValues.join('/');
if (sPath.length > 0 && sPath.charAt(0) !== '/') {
sPath = '/' + sPath;
}
return {
path: sPath,
obj: sObject
};
} | javascript | {
"resource": ""
} |
q46776 | Transports | train | function Transports(oOptions, oLogger) {
this._client = new AdtClient(oOptions.conn, oOptions.auth, undefined, oLogger);
} | javascript | {
"resource": ""
} |
q46777 | stringToFlockFlags | train | function stringToFlockFlags(flag) {
// Only mess with strings
if (typeof flag !== 'string') {
return flag;
}
switch (flag) {
case 'sh':
return binding.LOCK_SH;
case 'ex':
return binding.LOCK_EX;
case 'shnb':
return binding.LOCK_SH | binding.LOCK_NB;
case 'exnb':
re... | javascript | {
"resource": ""
} |
q46778 | stringToFcntlFlags | train | function stringToFcntlFlags(flag) {
if (typeof flag !== 'string') {
return flag;
}
switch (flag) {
case 'getfd':
return binding.F_GETFD;
case 'setfd':
return binding.F_SETFD;
case 'setlk':
return binding.F_SETLK;
case 'setlkw':
return binding.F_SETLKW;
case 'ge... | javascript | {
"resource": ""
} |
q46779 | getCurrentFileSize | train | function getCurrentFileSize(counter, timeout, cb) {
var fd = fs.openSync(__filename, 'r');
console.log("Trying to aquire lock for the %s time", counter);
fs.flock(fd, 'exnb', function(err) {
if (err) {
return console.log("Couldn't lock file", counter);
}
console.log('Aquired lock', counter);
... | javascript | {
"resource": ""
} |
q46780 | createClusters | train | function createClusters(units, distanceApart = 15.0) {
const squaredDistanceApart = distanceApart * distanceApart;
return units.reduce((clusters, u) => {
const isGeyser = vespeneGeyserTypes.includes(u.unitType);
/**
* @type {{ distance: number, target: Cluster }}
*/
co... | javascript | {
"resource": ""
} |
q46781 | clusterByNeighbor | train | function clusterByNeighbor(points) {
const sorted = points.slice().sort((a, b) => {
if (a.y < b.y) {
return -1;
} else if (a.y > b.y) {
return 1;
} else {
if (a.x < b.x) {
return -1;
} else if (a.x > b.x) {
retur... | javascript | {
"resource": ""
} |
q46782 | distanceAAShapes | train | function distanceAAShapes(shapeA, shapeB) {
const dx = Math.max(Math.abs(shapeA.pos.x - shapeB.pos.x) - ((shapeA.w / 2) + (shapeB.w / 2)), 0);
const dy = Math.max(Math.abs(shapeA.pos.y - shapeB.pos.y) - ((shapeA.h / 2) + (shapeB.h / 2)), 0);
return Math.sqrt(dx * dx + dy * dy);
} | javascript | {
"resource": ""
} |
q46783 | distanceAAShapeAndPoint | train | function distanceAAShapeAndPoint(shape, point) {
const dx = Math.max(Math.abs(shape.pos.x - point.x) - (shape.w / 2), 0);
const dy = Math.max(Math.abs(shape.pos.y - point.y) - (shape.h / 2), 0);
return Math.sqrt(dx * dx + dy * dy);
} | javascript | {
"resource": ""
} |
q46784 | subtract | train | function subtract(point, rhs) {
if (typeof rhs === 'number') {
return {
x: point.x - rhs,
y: point.y - rhs,
};
} else {
return {
x: point.x - rhs.x,
y: point.y - rhs.y,
};
}
} | javascript | {
"resource": ""
} |
q46785 | multiply | train | function multiply(point, rhs) {
if (typeof rhs === 'number') {
return {
x: point.x * rhs,
y: point.y * rhs,
};
} else {
return {
x: point.x * rhs.x,
y: point.y * rhs.y,
};
}
} | javascript | {
"resource": ""
} |
q46786 | divide | train | function divide(point, rhs) {
if (typeof rhs === 'number') {
return {
x: point.x / rhs,
y: point.y / rhs,
};
} else {
return {
x: point.x / rhs.x,
y: point.y / rhs.y,
};
}
} | javascript | {
"resource": ""
} |
q46787 | proxyRecursive | train | function proxyRecursive(replicant, value, path) {
if (typeof value === 'object' && value !== null) {
let p;
assertSingleOwner(replicant, value);
// If "value" is already a Proxy, don't re-proxy it.
if (proxySet.has(value)) {
p = value;
const metadata = proxyMetadataMap.get(value);
metadata.path = pa... | javascript | {
"resource": ""
} |
q46788 | assertSingleOwner | train | function assertSingleOwner(replicant, value) {
let metadata;
if (proxySet.has(value)) {
metadata = proxyMetadataMap.get(value);
} else if (metadataMap.has(value)) {
metadata = metadataMap.get(value);
} else {
// If there's no metadata for this value, then it doesn't belong to any Replicants yet,
// and we'r... | javascript | {
"resource": ""
} |
q46789 | waitFor | train | function waitFor(stream) {
return new Promise((resolve, reject) => {
stream.on('end', resolve);
stream.on('error', reject);
});
} | javascript | {
"resource": ""
} |
q46790 | declare | train | function declare(name, namespace, opts) {
// Delay requiring the Replicant class until here, otherwise cryptic errors are thrown. Not sure why!
const Replicant = require('./replicant');
return new Replicant(name, namespace, opts);
} | javascript | {
"resource": ""
} |
q46791 | assign | train | function assign(replicant, value) {
const oldValue = replicant.value;
replicant._ignoreProxy = true;
replicant.__value = shared._proxyRecursive(replicant, value, '/');
replicant._ignoreProxy = false;
replicant.revision++;
replicant.emit('change', value, oldValue);
replicant.log.replicants('Assigned:', value);
... | javascript | {
"resource": ""
} |
q46792 | applyOperations | train | function applyOperations(replicant, operations) {
const oldValue = clone(replicant.value);
operations.forEach(operation => shared.applyOperation(replicant, operation));
replicant.revision++;
replicant.emit('change', replicant.value, oldValue, operations);
emitToClients(replicant.namespace, 'replicant:operations',... | javascript | {
"resource": ""
} |
q46793 | find | train | function find(name, namespace) {
// If there are no replicants for that namespace, return undefined
if (!{}.hasOwnProperty.call(declaredReplicants, namespace)) {
return undefined;
}
// If that replicant doesn't exist for that namespace, return undefined
if (!{}.hasOwnProperty.call(declaredReplicants[namespace],... | javascript | {
"resource": ""
} |
q46794 | findOrDeclare | train | function findOrDeclare(name, namespace, opts) {
const existingReplicant = find(name, namespace);
if (typeof existingReplicant !== 'undefined') {
return existingReplicant;
}
return declare(name, namespace, opts);
} | javascript | {
"resource": ""
} |
q46795 | emitToClients | train | function emitToClients(namespace, eventName, data) {
// Emit to clients (in the given namespace's room) using Socket.IO
log.replicants('emitting %s to %s:', eventName, namespace, data);
io.to(`replicant:${namespace}`).emit(eventName, data);
} | javascript | {
"resource": ""
} |
q46796 | resetBackoffTimer | train | function resetBackoffTimer() {
clearTimeout(backoffTimer);
backoffTimer = setTimeout(() => {
backoffTimer = null;
for (const bundleName in hasChanged) {
/* istanbul ignore if: Standard hasOwnProperty check, doesn't need to be tested */
if (!{}.hasOwnProperty.call(hasChanged, bundleName)) {
continue;
... | javascript | {
"resource": ""
} |
q46797 | isPanelHTMLFile | train | function isPanelHTMLFile(bundleName, filePath) {
const bundle = module.exports.find(bundleName);
if (bundle) {
return bundle.dashboard.panels.some(panel => {
return panel.path.endsWith(filePath);
});
}
return false;
} | javascript | {
"resource": ""
} |
q46798 | isManifest | train | function isManifest(bundleName, filePath) {
return path.dirname(filePath).endsWith(bundleName) && path.basename(filePath) === 'package.json';
} | javascript | {
"resource": ""
} |
q46799 | _wrapAcknowledgement | train | function _wrapAcknowledgement(ack) {
let handled = false;
const wrappedAck = function (firstArg, ...restArgs) {
if (handled) {
throw new Error('Acknowledgement already handled');
}
handled = true;
if (isError(firstArg)) {
firstArg = serializeError(firstArg);
}
ack(firstArg, ...restArgs);
};
Ob... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.