_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q37000
parseJson
train
function parseJson(json, cache, cwd) { return json.replace( /"([^"]+\.json)"/gi, (match, jsonFile) => { const _json = loadJsonFile(jsonFile, cache, cwd); return _json === null ? match : _json; } ); }
javascript
{ "resource": "" }
q37001
train
function(dataset) { // calculate counts for equation (3): var mapWordToTotalCount = {}; var totalNumberOfWordsInDataset = 0; for (var i in dataset) { var datum = dataset[i]; var totalPerDatum = 0; // for each input sentence, count the total number of words in it: for (var word in datum) { mapWordToTotalCount[word] |= 0; mapWordToTotalCount[word] += datum[word]; totalPerDatum += datum[word]; } datum["_total"] = totalPerDatum; totalNumberOfWordsInDataset += totalPerDatum; } mapWordToTotalCount["_total"] = totalNumberOfWordsInDataset; this.dataset = dataset; this.mapWordToTotalCount = mapWordToTotalCount; // calculate smoothing factor for equation (3): var mapWordToSmoothingFactor = {}; for (var word in mapWordToTotalCount) { mapWordToSmoothingFactor[word] = (1-this.smoothingCoefficient) * this.mapWordToTotalCount[word] / this.mapWordToTotalCount["_total"]; } this.mapWordToSmoothingFactor = mapWordToSmoothingFactor; this.globalSmoothingFactor = (1/totalNumberOfWordsInDataset) // a global smoother, for totally unseen words. }
javascript
{ "resource": "" }
q37002
ErrorRead
train
function ErrorRead (message) { Error.call(this); // Add Information this.name = 'ErrorRead'; this.type = 'server'; this.status = 500; if (message) { this.message = message; } }
javascript
{ "resource": "" }
q37003
tryUnshift
train
function tryUnshift(stream, result, desiredLength, emptySlice) { if (typeof stream.unshift !== 'function') { debug('Unable to unshift, stream does not have an unshift method.'); return result; } const errorListeners = stream.listeners('error'); stream.removeAllListeners('error'); // Note: Don't rely on the EventEmitter throwing on 'error' without // listeners, since it may be thrown in the stream's attached domain. let unshiftErr; function onUnshiftError(err) { unshiftErr = err; } stream.on('error', onUnshiftError); let resultLength = result.length; try { if (Array.isArray(result)) { while (resultLength > desiredLength && !unshiftErr) { stream.unshift(result[resultLength - 1]); if (!unshiftErr) { resultLength -= 1; } } } else { stream.unshift(result.slice(desiredLength)); if (!unshiftErr) { resultLength = desiredLength; } } } catch (err) { unshiftErr = err; } if (unshiftErr) { debug('Unable to unshift data: ', unshiftErr); } stream.removeListener('error', onUnshiftError); errorListeners.forEach((errorListener) => { stream.on('error', errorListener); }); return resultLength === 0 && !emptySlice ? null : resultLength < result.length ? result.slice(0, resultLength) : result; }
javascript
{ "resource": "" }
q37004
checkUntil
train
function checkUntil(resultWithData, data, ended) { let desiredLength; try { desiredLength = until(resultWithData, data, ended); } catch (errUntil) { doReject(errUntil, true); return true; } const resultLength = result ? result.length : 0; if (typeof desiredLength === 'number') { if (desiredLength > resultLength) { debug( 'until returned a desired length of %d. ' + 'Only have %d. Reading up to %d.', desiredLength, resultLength, desiredLength ); numSize = desiredLength; size = desiredLength - resultLength; } else if (desiredLength >= 0) { debug( 'until returned a desired length of %d out of %d', desiredLength, resultLength ); if (desiredLength < resultLength) { if (ended) { debug('Unable to unshift: Can not unshift after end.'); } else { result = tryUnshift(stream, result, desiredLength, true); } } doResolve(); return true; } else { debug('until returned %d, continuing to read', desiredLength); } } else if (desiredLength === true) { debug('until returned true, read finished.'); doResolve(); return true; } else if (desiredLength !== undefined && desiredLength !== null && desiredLength !== false) { // Note: Although this could be allowed, it causes an Error so that // future versions may add behavior for these values without causing // breakage. doReject( new TypeError( `non-numeric, non-boolean until() result: ${desiredLength}` ), true ); } else { debug('until returned %s, continuing to read', desiredLength); } return false; }
javascript
{ "resource": "" }
q37005
read
train
function read(stream, size, options) { if (!options && typeof size === 'object') { options = size; size = null; } return readInternal(stream, size, undefined, options); }
javascript
{ "resource": "" }
q37006
readUntil
train
function readUntil(stream, until, options) { if (typeof until !== 'function') { // Note: Synchronous Yaku emits unhandledRejection before returning. // Best current option is to use an async promise, even when flowing const ReadPromise = (options && options.Promise) || Promise; return ReadPromise.reject(new TypeError('until must be a function')); } return readInternal(stream, undefined, until, options); }
javascript
{ "resource": "" }
q37007
readTo
train
function readTo(stream, needle, options) { const endOK = Boolean(options && (options.endOK || options.endOk)); let needleForIndexOf; let needleLength; function until(result, chunk, ended) { if (ended) { return endOK ? (result ? result.length : 0) : -1; } if (Array.isArray(result)) { // objectMode. Use strict equality, like Array.prototype.indexOf return chunk === needle ? result.length : -1; } // Calculate the length of the needle, as used by indexOf and perform the // type conversion done by indexOf once, to avoid converting on every call if (needleLength === undefined) { if (typeof result === 'string') { needleForIndexOf = String(needle); needleLength = needleForIndexOf.length; } else if (result instanceof Buffer) { if (typeof needle === 'number') { // buffertools requires a Buffer or string // buffer-indexof-polyfill converts number to Buffer on each call needleForIndexOf = result.indexOf ? needle : Buffer.from ? Buffer.from([needle]) // eslint-disable-next-line no-buffer-constructor : new Buffer([needle]); needleLength = 1; } else if (typeof needle === 'string') { needleForIndexOf = needle; needleLength = Buffer.byteLength(needle); } else if (needle instanceof Buffer) { needleForIndexOf = needle; needleLength = needle.length; } } if (needleLength === undefined) { throw new TypeError(`Unsupported indexOf argument types: ${ Object.prototype.toString.call(result)}.indexOf(${ Object.prototype.toString.call(needle)})`); } // Buffer.prototype.indexOf returns -1 for 0-length string/Buffer. // To be consistent with string, we return 0. // Note: If removing this check, remove + 1 from start calc when 0. if (needleLength === 0) { return 0; } } const start = Math.max((result.length - chunk.length - needleLength) + 1, 0); const needleIndex = result.indexOf(needleForIndexOf, start); if (needleIndex < 0) { return -1; } return needleIndex + needleLength; } return readInternal(stream, undefined, until, options); }
javascript
{ "resource": "" }
q37008
readToEnd
train
function readToEnd(stream, options) { function until(result, chunk, ended) { return ended; } return readInternal(stream, undefined, until, options); }
javascript
{ "resource": "" }
q37009
readToMatch
train
function readToMatch(stream, regexp, options) { const endOK = Boolean(options && (options.endOK || options.endOk)); const maxMatchLen = Number(options && options.maxMatchLen); // Convert to RegExp where necessary, like String.prototype.match // Make sure RegExp has global flag so lastIndex will be set if (!(regexp instanceof RegExp)) { try { regexp = new RegExp(regexp, 'g'); } catch (errRegExp) { // Note: Synchronous Yaku emits unhandledRejection before returning. // Best current option is to use an async promise, even when flowing const ReadPromise = (options && options.Promise) || Promise; return ReadPromise.reject(errRegExp); } } else if (!regexp.global) { regexp = new RegExp(regexp.source, `${regexp.flags || ''}g`); } function until(result, chunk, ended) { if (ended) { return endOK ? (result ? result.length : 0) : -1; } if (typeof result !== 'string') { throw new TypeError('readToMatch requires a string stream' + ' (use constructor options.encoding or .setEncoding method)'); } regexp.lastIndex = maxMatchLen ? Math.max((result.length - chunk.length - maxMatchLen) + 1, 0) : 0; if (regexp.test(result)) { return regexp.lastIndex; } return -1; } return readInternal(stream, undefined, until, options); }
javascript
{ "resource": "" }
q37010
loadList
train
function loadList(brain) { const taboolist = brain.get("taboo"); if (taboolist != null) { for (let topic of taboolist) { taboo.set(topic, new RegExp(`\\b${topic}\\b`, "i")); } } }
javascript
{ "resource": "" }
q37011
saveList
train
function saveList(brain) { const taboolist = []; taboo.forEach((re, topic) => { taboolist.push(topic); }); brain.set("taboo", taboolist); }
javascript
{ "resource": "" }
q37012
deleteTopic
train
function deleteTopic(res, topic) { const keyTopic = topic.toLowerCase(); if (taboo.delete(keyTopic)) { res.reply(capitalize(`${topic} is no longer taboo`)); saveList(res.robot.brain); } else { res.reply(`Oops, ${topic} is not taboo`); } }
javascript
{ "resource": "" }
q37013
addTopic
train
function addTopic(res, topic) { const keyTopic = topic.toLowerCase(); if (!taboo.has(keyTopic)) { taboo.set(keyTopic, new RegExp(`\\b${topic}\\b`, "i")); saveList(res.robot.brain); res.reply(capitalize(`${topic} is now taboo`)); } else { res.reply(`Oops, ${topic} is already taboo`); } }
javascript
{ "resource": "" }
q37014
listTopics
train
function listTopics(res) { loadList(res.robot.brain); // Not necessary, but helps for testing. if (taboo.size == 0) { res.reply("Nothing is taboo here."); } else { let topics = []; taboo.forEach((re, topic) => { topics.push(topic); }) res.reply("Taboo topics are: " + topics.join(", ")); } }
javascript
{ "resource": "" }
q37015
extend
train
function extend(what, whit) { Object.keys(whit).forEach(function(key) { var def = whit[key]; if (what[key] === undefined) { if (def.get && def.set) { // TODO: look at element.dataset polyfill (iOS?) } else { what[key] = def; } } }); }
javascript
{ "resource": "" }
q37016
strings
train
function strings() { extend(String.prototype, { trim: function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }, repeat: function(n) { return new Array(n + 1).join(this); }, startsWith: function(sub) { return this.indexOf(sub) === 0; }, endsWith: function(sub) { sub = String(sub); var i = this.lastIndexOf(sub); return i >= 0 && i === this.length - sub.length; }, contains: function(sub) { return this.indexOf(sub) > -1; }, toArray: function() { return this.split(""); } }); }
javascript
{ "resource": "" }
q37017
arrays
train
function arrays() { extend(Array, { every: function every(array, fun, thisp) { var res = true, len = array.length >>> 0; for (var i = 0; i < len; i++) { if (array[i] !== undefined) { if (!fun.call(thisp, array[i], i, array)) { res = false; break; } } } return res; }, forEach: function forEach(array, fun, thisp) { var len = array.length >>> 0; for (var i = 0; i < len; i++) { if (array[i] !== undefined) { fun.call(thisp, array[i], i, array); } } }, map: function map(array, fun, thisp) { var m = [], len = array.length >>> 0; for (var i = 0; i < len; i++) { if (array[i] !== undefined) { m.push(fun.call(thisp, array[i], i, array)); } } return m; }, filter: function map(array, fun, thisp) { return Array.prototype.filter.call(array, fun, thisp); }, isArray: function isArray(o) { return Object.prototype.toString.call(o) === "[object Array]"; }, concat: function(a1, a2) { function map(e) { return e; } return this.map(a1, map).concat(this.map(a2, map)); } }); }
javascript
{ "resource": "" }
q37018
train
function(action, thisp) { var is = this.initialized; if (arguments.length) { if (is) { action.call(thisp); } else { this._initcallbacks = this._initcallbacks || []; this._initcallbacks.push(function() { if (gui.debug) { try { action.call(thisp); } catch (exception) { console.error(action.toString()); throw exception; } } else { action.call(thisp); } }); } } return is; }
javascript
{ "resource": "" }
q37019
train
function(action, thisp) { this.init(action, thisp); if(gui.debug) { console.warn('gui.ready() is for spirits, use gui.init()'); } return false; }
javascript
{ "resource": "" }
q37020
train
function(name, module) { var Module; if (gui.Type.isString(name) && name.length) { Module = gui.Module.extend(name, module || {}); module = gui.Module.$register(new Module(name)); return module; } else { throw new Error("Module needs an identity token"); } }
javascript
{ "resource": "" }
q37021
train
function(ns, members) { var no; if (gui.Type.isString(ns)) { no = gui.Object.lookup(ns); no = new gui.Namespace(ns); no = gui.Object.assert(ns, no); } else { throw new TypeError("Expected a namespace string"); } return gui.Object.extend(no, members || {}); }
javascript
{ "resource": "" }
q37022
train
function(msg, arg) { if (gui.Type.isEvent(arg)) { arg = new gui.EventSummary(arg); } gui.Broadcast.dispatchGlobal(msg, arg); }
javascript
{ "resource": "" }
q37023
train
function(o, name) { gui.Object.each(o, function(key, value) { if (key !== "$superclass" && gui.Type.isConstructor(value)) { if (value.$classname === gui.Class.ANONYMOUS) { Object.defineProperty(value, '$classname', { value: name + "." + key, enumerable: true, writable: false }); this._spacename(value, name + "." + key); } } }, this); }
javascript
{ "resource": "" }
q37024
train
function(string) { var hit = null, looks = false; if (gui.Type.isString(string)) { hit = this.extractKey(string); looks = hit && hit[0] === string; } return looks; }
javascript
{ "resource": "" }
q37025
train
function(proto, props) { var resolved = {}; Object.keys(props).forEach(function(prop) { resolved[prop] = { value: props[prop], writable: true, enumerable: true, configurable: true }; }); return Object.create(proto, resolved); }
javascript
{ "resource": "" }
q37026
train
function(source, domap, thisp) { var result = {}, mapping; this.each(source, function(key, value) { mapping = domap.call(thisp, key, value); if (mapping !== undefined) { result[key] = mapping; } }); return result; }
javascript
{ "resource": "" }
q37027
train
function(opath, context) { var result, struct = context || self; if (gui.Type.isString(opath)) { if (!opath.contains(".")) { result = struct[opath]; } else { var parts = opath.split("."); parts.every(function(part) { struct = struct[part]; return gui.Type.isDefined(struct); }); result = struct; } } else { throw new TypeError("Expected string, got " + gui.Type.of(opath)); } return result; }
javascript
{ "resource": "" }
q37028
train
function(desc) { if (desc.value && gui.Type.isFunction(desc.value)) { if (desc.value.$hidden && desc.configurable) { desc.enumerable = false; } } return desc; }
javascript
{ "resource": "" }
q37029
train
function(o) { var type = ({}).toString.call(o).match(this._typeexp)[1].toLowerCase(); if (type === "domwindow" && String(typeof o) === "undefined") { type = "undefined"; // some kind of degenerate bug in Safari on iPad } return type; }
javascript
{ "resource": "" }
q37030
train
function(o) { return o && o.document && o.location && o.alert && o.setInterval; }
javascript
{ "resource": "" }
q37031
train
function(what) { return this.isFunction(what) && this.isObject(what.prototype) && Object.keys(what.prototype).length; }
javascript
{ "resource": "" }
q37032
train
function(string) { var result = String(string); switch (result) { case "null": result = null; break; case "true": case "false": result = (result === "true"); break; default: if (String(parseInt(result, 10)) === result) { result = parseInt(result, 10); } else if (String(parseFloat(result)) === result) { result = parseFloat(result); } break; } return result; }
javascript
{ "resource": "" }
q37033
train
function(/* ...types */) { var types = gui.Array.from(arguments); return function(action) { return function() { if (gui.Arguments._match(arguments, types)) { return action.apply(this, arguments); } }; }; }
javascript
{ "resource": "" }
q37034
train
function(/* ...types */) { var types = gui.Array.from(arguments); return function(action) { return function() { if (gui.Arguments._validate(arguments, types)) { return action.apply(this, arguments); } else { gui.Arguments._abort(this); } }; }; }
javascript
{ "resource": "" }
q37035
train
function(xpect, arg, index) { var needs = !xpect.startsWith("("); var split = this._xtract(xpect, !needs).split("|"); var input = gui.Type.of(arg); var match = (xpect === "*" || (xpect === 'node' && arg && arg.nodeType) || (xpect === 'element' && arg && arg.nodeType === Node.ELEMENT_NODE) || (xpect === 'spirit' && arg && arg.$instanceid && arg.element) || (!needs && input === "undefined") || (!needs && split.indexOf("*") > -1) || split.indexOf(input) > -1); if (!match && this._validating) { if (input === "string") { arg = '"' + arg + '"'; } this._bugsummary = [index, xpect, input, arg]; } return match; }
javascript
{ "resource": "" }
q37036
train
function(that) { var summ = this._bugsummary; var name = that.constructor.$classname || String(that); console.error([ "Bad argument " + summ.shift(), "for " + name + ":", "Expected " + summ.shift() + ",", "got " + summ.shift() + ":", summ.shift() ].join(" ")); }
javascript
{ "resource": "" }
q37037
train
function(name, params, body, context) { var F = context ? context.Function : Function; name = this.safename(name); params = params ? params.join(",") : ""; body = body || ""; return new F( "return function " + name + " ( " + params + " ) {" + body + "}" )(); }
javascript
{ "resource": "" }
q37038
train
function() { var b = this._breakdown_base(arguments); var C = this._createclass(null, b.proto, b.name); gui.Object.extend(C.prototype, b.protos); gui.Object.extend(C, b.statics); gui.Property.extendall(b.protos, C.prototype); if (b.recurring) { gui.Object.each(b.recurring, function(key, val) { var desc = Object.getOwnPropertyDescriptor(C, key); if (!desc || desc.writable) { C[key] = C.$recurring[key] = val; } }); } return C; }
javascript
{ "resource": "" }
q37039
train
function(SuperC, args) { args = this._breakdown_subs(args); return this._extendclass( SuperC, args.protos, args.recurring, args.statics, args.name ); }
javascript
{ "resource": "" }
q37040
train
function(SuperC, protos, recurring, statics, name) { var C = this._createclass(SuperC, SuperC.prototype, name); gui.Object.extend(C, statics); gui.Object.extend(C.$recurring, recurring); gui.Object.each(C.$recurring, function(key, val) { var desc = Object.getOwnPropertyDescriptor(C, key); if (!desc || desc.writable) { C[key] = val; } }); gui.Property.extendall(protos, C.prototype); C = this._classname(C, name); return C; }
javascript
{ "resource": "" }
q37041
train
function(C, SuperC) { C.$super = null; // what's this? C.$subclasses = []; C.$superclass = SuperC || null; C.$recurring = SuperC ? gui.Object.copy(SuperC.$recurring) : Object.create(null); if (SuperC) { SuperC.$subclasses.push(C); } return C; }
javascript
{ "resource": "" }
q37042
train
function(proto, recurring, statics) { Array.forEach(arguments, function(mixins, i) { if (mixins) { gui.Object.each(mixins, function(name, value) { if (i === 0) { // TODO: something more elaborate (like defineProperty) this.prototype[name] = value; } else { // TODO: only at index 1 right? gui.Class.descendantsAndSelf(this, function(C) { C.$recurring[name] = value; C[name] = value; }); } }, this); } }, this); return this; }
javascript
{ "resource": "" }
q37043
train
function(C, action, thisp) { var results = []; action = action || gui.Combo.identity; C.$subclasses.forEach(function(sub) { results.push(action.call(thisp, sub)); }, thisp); return results; }
javascript
{ "resource": "" }
q37044
train
function(C, action, thisp, results) { results = results || []; action = action || gui.Combo.identity; C.$subclasses.forEach(function(sub) { results.push(action.call(thisp, sub)); gui.Class.descendants(sub, action, thisp, results); }, thisp); return results; }
javascript
{ "resource": "" }
q37045
train
function(C, action, thisp) { var results = []; action = action || gui.Combo.identity; results.push(action.call(thisp, C)); return this.descendants(C, action, thisp, results); }
javascript
{ "resource": "" }
q37046
train
function(C, action, thisp) { if (C && C.$superclass) { action = action || gui.Combo.identity; return action.call(thisp, C.$superclass); } return null; }
javascript
{ "resource": "" }
q37047
train
function(C, action, thisp) { var results = this.ancestorsAndSelf(C).concat(this.descendants(C)); if (action) { results = results.map(function(C) { return action.call(thisp, C); }); } return results; }
javascript
{ "resource": "" }
q37048
train
function(proto, key, desc) { var val = desc.value; if (gui.Type.isObject(val)) { if (val.getter || val.setter) { if (this._isactive(val)) { desc = this._activeaccessor(proto, key, val); } } } return desc; }
javascript
{ "resource": "" }
q37049
train
function(proto, key, def) { var desc; ["getter", "setter"].forEach(function(name, set) { while (proto && proto[key] && !gui.Type.isDefined(def[name])) { proto = Object.getPrototypeOf(proto); desc = Object.getOwnPropertyDescriptor(proto, key); if (desc) { def[name] = desc[set ? "set" : "get"]; } } }); return { enumerable: true, configurable: true, get: def.getter || this._NOGETTER, set: def.setter || this._NOSETTER }; }
javascript
{ "resource": "" }
q37050
train
function(interfais, object) { var is = true; var expected = interfais.toString(); var type = gui.Type.of(object); switch (type) { case "null": case "string": case "number": case "boolean": case "undefined": throw new Error("Expected " + expected + ", got " + type + ": " + object); default: try { var missing = null, t = null; is = Object.keys(interfais).every(function(name) { missing = name; t = gui.Type.of(interfais[name]); return gui.Type.of(object[name]) === t; }); if (!is) { throw new Error("Expected " + expected + ". A required " + type + " \"" + missing + "\" is missing"); } } catch (exception) { throw new Error("Expected " + expected); } break; } return is; }
javascript
{ "resource": "" }
q37051
train
function(decoration) { return function(base) { return function() { var result = base.apply(this, arguments); decoration.apply(this, arguments); return result; }; }; }
javascript
{ "resource": "" }
q37052
train
function(decoration) { var slice = [].slice; return function(base) { return function() { var argv, callback, result, that = this; argv = 1 <= arguments.length ? slice.call(arguments, 0) : []; result = void 0; callback = function() { return (result = base.apply(that, argv)); }; decoration.apply(this, [callback].concat(argv)); return result; }; }; }
javascript
{ "resource": "" }
q37053
train
function(condition) { return function(base, otherwise) { return function() { if (condition.apply(this, arguments)) { return base.apply(this, arguments); } else if (otherwise) { return otherwise.apply(this, arguments); } }; }; }
javascript
{ "resource": "" }
q37054
train
function(client) { this.client = client; if(gui.hasModule('gui-spirits@wunderbyte.com')) { if(client instanceof gui.Spirit) { this.spirit = client || null; this.context = window; // otherwise web worker scenario, maybe deprecate } } this.onconstruct(); }
javascript
{ "resource": "" }
q37055
train
function() { gui.Plugin.prototype.ondestruct.call(this); gui.Object.each(this._trackedtypes, function(type, list) { list.slice().forEach(function(checks) { this._cleanup(type, checks); }, this); }, this); }
javascript
{ "resource": "" }
q37056
train
function(on /*...rest */ ) { var rest = gui.Array.from(arguments).slice(1); if (on) { return this.add.apply(this, rest); } else { return this.remove.apply(this, rest); } }
javascript
{ "resource": "" }
q37057
train
function(type, checks) { var result = false; var list = this._trackedtypes[type]; if (!list) { list = this._trackedtypes[type] = []; result = true; } else { result = !this._haschecks(list, checks); } if (result && checks) { list.push(checks); } return result; }
javascript
{ "resource": "" }
q37058
train
function(type, checks) { var result = false; var list = this._trackedtypes[type]; if (list) { var index = this._checksindex(list, checks); if (index > -1) { result = true; // TODO: this seems to not run when checks is none (undefined)! if (gui.Array.remove(list, index) === 0) { delete this._trackedtypes[type]; } } } return result; }
javascript
{ "resource": "" }
q37059
train
function(type, checks) { var result = false; var list = this._trackedtypes[type]; if (list) { result = !checks || this._haschecks(list, checks); } return result; }
javascript
{ "resource": "" }
q37060
train
function(list, checks) { var result = !checks || false; if (!result) { list.every(function(a) { if (a.every(function(b, i) { return b === checks[i]; })) { result = true; } return !result; }); } return result; }
javascript
{ "resource": "" }
q37061
train
function(list, checks) { var result = -1; list.every(function(a, index) { if (a.every(function(b, i) { return b === checks[i]; })) { result = index; } return result === -1; }); return result; }
javascript
{ "resource": "" }
q37062
train
function(a, key) { var prefix = "spiritual-action:"; return prefix + (function() { a.target = null; a.data = (function(d) { if (gui.Type.isComplex(d)) { if (gui.Type.isFunction(d.stringify)) { d = d.stringify(); } else { try { JSON.stringify(d); } catch (jsonexception) { d = null; } } } return d; }(a.data)); a.instanceid = key || null; return JSON.stringify(a); }()); }
javascript
{ "resource": "" }
q37063
train
function(b) { var prefix = "spiritual-broadcast:"; return prefix + (function() { b.target = null; b.data = (function(d) { if (gui.Type.isComplex(d)) { if (gui.Type.isFunction(d.stringify)) { d = d.stringify(); } else { try { JSON.stringify(d); // @TODO: think mcfly - how come not d = JSON.stringify???? } catch (jsonexception) { d = null; } } } return d; }(b.data)); return JSON.stringify(b); }()); }
javascript
{ "resource": "" }
q37064
train
function(msg) { var prefix = "spiritual-broadcast:"; if (msg.startsWith(prefix)) { return JSON.parse(msg.split(prefix)[1]); } }
javascript
{ "resource": "" }
q37065
train
function(b) { var map = b.global ? this._globals : this._locals[gui.$contextid]; if (gui.hasModule('gui-spirits@wunderbyte.com')) { if(!gui.spiritualized) { if(b.type !== gui.BROADCAST_WILL_SPIRITUALIZE) { // TODO: cache broadcast until spiritualized? } } } if (this.$target) { if (!b.global) { b.target = this.$target; } this.$target = null; } if (b instanceof gui.Broadcast === false) { b = new gui.Broadcast(b); } if (map) { var handlers = map[b.type]; if (handlers) { handlers.slice().forEach(function(handler) { handler.onbroadcast(b); }); } } if (b.global) { this._propagate(b); } return b; }
javascript
{ "resource": "" }
q37066
train
function(b) { var postmessage = (function stamp() { b.$contextids.push(gui.$contextid); return gui.Broadcast.stringify(b); }()); this._propagateDown(postmessage); this._propagateUp(postmessage, b.type); }
javascript
{ "resource": "" }
q37067
train
function(type, time, sig) { var map = this._tempname; var types = map.types; var tick = new gui.Tick(type); time = time || 0; if (!types[type]) { // !!!!!!!!!!!!!!!!!!!!!!! types[type] = true; var that = this, id = null; if (!time) { id = setImmediate(function() { delete types[type]; that._doit(tick); }); } else { id = setTimeout(function() { delete types[type]; that._doit(tick); }, time); } } return tick; }
javascript
{ "resource": "" }
q37068
train
function(spirit) { var prefixes = [], plugins = spirit.life.plugins; gui.Object.each(plugins, function(prefix, instantiated) { if (instantiated) { if (prefix !== "life") { prefixes.push(prefix); } } else { Object.defineProperty(spirit, prefix, { enumerable: true, configurable: true, get: function() {}, set: function() {} }); } }); plugins = prefixes.map(function(key) { return spirit[key]; }, this); if (!gui.unloading) { this.$nukeplugins(plugins, false); gui.Tick.next(function() { // TODO: organize this at some point... this.$nukeplugins(plugins, true); this.$nukeelement(spirit); this.$nukeallofit(spirit); }, this); } }
javascript
{ "resource": "" }
q37069
train
function(plugins, nuke) { if (nuke) { plugins.forEach(function(plugin) { this.$nukeallofit(plugin); }, this); } else { plugins.map(function(plugin) { plugin.ondestruct(); return plugin; }).forEach(function(plugin) { plugin.$ondestruct(); }); } }
javascript
{ "resource": "" }
q37070
train
function(thing) { var nativeprops = Object.prototype; if (!gui.unloading && !thing.$destructed) { thing.$destructed = true; for (var prop in thing) { if (thing.hasOwnProperty(prop) || gui.debug) { if (nativeprops[prop] === undefined) { if (prop !== '$destructed') { var desc = Object.getOwnPropertyDescriptor(thing, prop); if (!desc || desc.configurable) { if (gui.debug) { this._definePropertyItentified(thing, prop); } else { Object.defineProperty(thing, prop, this.DENIED); } } } } } } } }
javascript
{ "resource": "" }
q37071
train
function(message) { var stack, e = new Error( gui.GreatSpirit.DENIAL + (message ? ": " + message : "") ); if (!gui.Client.isExplorer && (stack = e.stack)) { if (gui.Client.isWebKit) { stack = stack.replace(/^[^\(]+?[\n$]/gm, ""). replace(/^\s+at\s+/gm, ""). replace(/^Object.<anonymous>\s*\(/gm, "{anonymous}()@"). split("\n"); } else { stack = stack.split("\n"); } stack.shift(); stack.shift(); // @TODO: shift one more now? console.warn(e.message + "\n" + stack); } else { console.warn(e.message); } }
javascript
{ "resource": "" }
q37072
train
function(thing, prop) { Object.defineProperty(thing, prop, { enumerable: true, configurable: true, get: function() { gui.GreatSpirit.DENY(thing); }, set: function() { gui.GreatSpirit.DENY(thing); } }); }
javascript
{ "resource": "" }
q37073
train
function() { var spirit, spirits = this._spirits.slice(); if (window.gui) { // hotfix IE window unloaded scenario... while ((spirit = spirits.shift())) { this.$nuke(spirit); } this._spirits = []; } }
javascript
{ "resource": "" }
q37074
train
function() { var that = this, add = function(target, events, capture) { events.split(' ').forEach(function(type) { target.addEventListener(type, that, capture); }); }; add(document, 'DOMContentLoaded'); add(document, 'click mousedown mouseup', true); add(window, 'load hashchange'); if (!gui.hosted) { add(window, 'resize orientationchange'); } if (!(window.chrome && chrome.app && chrome.runtime)) { add(window, 'unload'); } /* if (document.readyState === "complete") { // TODO: IE cornercase? if (!this._loaded) { this._ondom(); this._onload(); } } */ }
javascript
{ "resource": "" }
q37075
train
function() { this._loaded = true; dobrodcast(gui.BROADCAST_TOLOAD, gui.BROADCAST_ONLOAD); doaction(gui.ACTION_DOC_ONLOAD, location.href); }
javascript
{ "resource": "" }
q37076
train
function() { if (!gui.hosted) { clearTimeout(this._timeout); this._timeout = setTimeout(function() { gui.broadcastGlobal(gui.BROADCAST_RESIZE_END); }, gui.TIMEOUT_RESIZE_END); } }
javascript
{ "resource": "" }
q37077
train
function(spaces) { var prop, def, metas = document.querySelectorAll('meta[name]'); Array.forEach(metas, function(meta) { prop = meta.getAttribute('name'); spaces.forEach(function(ns) { if (prop.startsWith(ns + '.')) { def = gui.Object.lookup(prop); if (gui.Type.isDefined(def)) { gui.Object.assert(prop, gui.Type.cast(meta.getAttribute('content')) ); } else { console.error('No definition for "' + prop + '"'); } } }); }); }
javascript
{ "resource": "" }
q37078
train
function(callback, thisp) { this._callback = callback ? callback : null; this._pointer = thisp ? thisp : null; if (this._now) { this.now(); } }
javascript
{ "resource": "" }
q37079
train
function() { var c = this._callback; var p = this._pointer; if (c) { this.then(null, null); c.apply(p, arguments); } else { this._now = true; } }
javascript
{ "resource": "" }
q37080
train
function(markup, targetdoc) { return this.parseToNodes(markup, targetdoc).filter(function(node) { return node.nodeType === Node.ELEMENT_NODE; }); }
javascript
{ "resource": "" }
q37081
train
function(markup, targetdoc) { var elm, doc = this._document || (this._document = document.implementation.createHTMLDocument("")); return gui.Guide.suspend(function() { doc.body.innerHTML = this._unsanitize(markup); elm = doc.querySelector("." + this._classname) || doc.body; return Array.map(elm.childNodes, function(node) { return (targetdoc || document).importNode(node, true); }); }, this); }
javascript
{ "resource": "" }
q37082
train
function(markup) { markup = markup || ""; return gui.Guide.suspend(function() { var doc = document.implementation.createHTMLDocument(""); if (markup.toLowerCase().contains("<!doctype")) { try { doc.documentElement.innerHTML = markup; } catch (ie9exception) { doc = new ActiveXObject("htmlfile"); doc.open(); doc.write(markup); doc.close(); } } else { doc.body.innerHTML = markup; } return doc; }); }
javascript
{ "resource": "" }
q37083
train
function(markup) { var match, fix; markup = markup.trim().replace(this._comments, ""); if ((match = markup.match(this._firsttag))) { if ((fix = this._unsanestructures[match[1]])) { markup = fix. replace("${class}", this._classname). replace("${markup}", markup); } } return markup; }
javascript
{ "resource": "" }
q37084
train
function(start, handler) { this.direction = gui.Crawler.ASCENDING; var supports = gui.hasModule('gui-spirits@wunderbyte.com'); var isspirit = supports && start instanceof gui.Spirit; var win, elm = isspirit ? start.element : start; do { if (elm.nodeType === Node.DOCUMENT_NODE) { if (this.global) { win = elm.defaultView; if (win.gui.hosted) { // win.parent !== win /* * @TODO: iframed document might have navigated elsewhere, stamp this in localstorage * @TODO: sit down and wonder if localstorage is even available in sandboxed iframes... */ if (win.gui.xhost) { elm = null; if (gui.Type.isFunction(handler.transcend)) { handler.transcend(win.parent, win.gui.xhost, win.gui.$contextid); } } else { elm = win.frameElement; } } else { elm = null; } } else { elm = null; } } if (elm) { var directive = this._handleElement(elm, handler); switch (directive) { case gui.Crawler.STOP: elm = null; break; default: elm = elm.parentNode; break; } } } while (elm); }
javascript
{ "resource": "" }
q37085
train
function(start, handler, arg) { this.direction = gui.Crawler.DESCENDING; var elm = start instanceof gui.Spirit ? start.element : start; if (elm.nodeType === Node.DOCUMENT_NODE) { elm = elm.documentElement; } this._descend(elm, handler, arg, true); }
javascript
{ "resource": "" }
q37086
train
function(start, handler, arg) { this.global = true; this.descend(start, handler, arg); this.global = false; }
javascript
{ "resource": "" }
q37087
train
function(element, handler, arg) { var hasspirit = gui.hasModule('gui-spirits@wunderbyte.com'); var directive = gui.Crawler.CONTINUE; var spirit = hasspirit ? element.spirit : null; if (spirit) { directive = spirit.oncrawler(this); } if (!directive) { if (handler) { if (gui.Type.isFunction(handler.handleElement)) { directive = handler.handleElement(element, arg); } if (directive !== gui.Crawler.STOP) { if (spirit && gui.Type.isFunction(handler.handleSpirit)) { directive = this._handleSpirit(spirit, handler); } } } } if (!directive) { directive = gui.Crawler.CONTINUE; } return directive; }
javascript
{ "resource": "" }
q37088
train
function(text) { var result = text; try { switch (this._headers.Accept) { case "application/json": result = JSON.parse(text); break; case "text/xml": result = new DOMParser().parseFromString(text, "text/xml"); break; } } catch (exception) { if (gui.debug) { console.error( this._headers.Accept + " dysfunction at " + this._url ); } } return result; }
javascript
{ "resource": "" }
q37089
supports
train
function supports(feature) { var root = document.documentElement; var fixt = feature[0].toUpperCase() + feature.substring(1); return !["", "Webkit", "Moz", "O", "ms"].every(function(prefix) { return root.style[prefix ? prefix + fixt : feature] === undefined; }); }
javascript
{ "resource": "" }
q37090
train
function(elm) { var res = null; if (elm.nodeType === Node.ELEMENT_NODE) { var doc = elm.ownerDocument; var win = doc.defaultView; if (win.gui) { if (win.gui.attributes.every(function(fix) { res = this._evaluateinline(elm, win, fix); return res === null; }, this)) { if (gui.hasChannels()) { win.gui._channels.every(function(def) { var select = def[0]; var spirit = def[1]; if (gui.CSSPlugin.matches(elm, select)) { res = spirit; } return res === null; }, this); } } } } return res; }
javascript
{ "resource": "" }
q37091
train
function(spirit) { var all = this._spirits; var key = spirit.$instanceid; delete all.inside[key]; delete all.outside[key]; this._stoptracking(spirit); }
javascript
{ "resource": "" }
q37092
train
function() { this.spiritualized = true; var list = this._readycallbacks; if (list) { while (list.length) { list.shift()(); } this._readycallbacks = null; } }
javascript
{ "resource": "" }
q37093
train
function(action) { var list = this._trackedtypes[action.type]; if (list) { list.forEach(function(checks) { var handler = checks[0]; var matches = checks[1] === action.global; var hacking = handler === this.spirit && this.$handleownaction; if (matches && (handler !== action.target || hacking)) { handler.onaction(action); } }, this); } }
javascript
{ "resource": "" }
q37094
train
function(action, time, thisp) { return gui.Tick.time(action, time, thisp || this.spirit); }
javascript
{ "resource": "" }
q37095
train
function(type, handler, one) { var sig = this.spirit.$contextid; if (one) { if (this._global) { gui.Tick.oneGlobal(type, handler); } else { gui.Tick.one(type, handler, sig); } } else { if (this._global) { gui.Tick.addGlobal(type, handler); } else { gui.Tick.add(type, handler, sig); } } }
javascript
{ "resource": "" }
q37096
train
function(type, handler) { var sig = this.spirit.$contextid; if (this._global) { gui.Tick.removeGlobal(type, handler); } else { gui.Tick.remove(type, handler, sig); } }
javascript
{ "resource": "" }
q37097
train
function(type, checks) { var handler = checks[0]; var bglobal = checks[1]; if (this._remove(type, [handler])) { if (bglobal) { gui.Tick.removeGlobal(type, handler); } else { gui.Tick.remove(type, handler, this.$contextid); } } }
javascript
{ "resource": "" }
q37098
train
function(arg, handler) { handler = handler ? handler : this.spirit; gui.Array.make(arg).forEach(function(type) { if (this._addchecks(type, [handler])) { if (!this._handlers[type]) { this._handlers[type] = []; } this._handlers[type].push(handler); } }, this); return this.spirit; }
javascript
{ "resource": "" }
q37099
train
function(arg, handler) { handler = handler ? handler : this.spirit; gui.Array.make(arg).forEach(function(type) { if (this._removechecks(type, [handler])) { if (this._handlers[type]) { // weirdo Gecko condition... var index = this._handlers[type].indexOf(type); gui.Array.remove(this._handlers[type], index); if (this._handlers[type].length === 0) { delete this._handlers[type]; } } } }, this); return this.spirit; }
javascript
{ "resource": "" }