_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
language
stringclasses
1 value
meta_information
dict
q10000
browserSpecific
train
function browserSpecific() { var data = ''; return through( function(buf) { data += buf;
javascript
{ "resource": "" }
q10001
setMiddleware
train
function setMiddleware(Model, modelName, path) { var RefModel; // We only apply the middleware on the provided // paths in the plugin options. if (opts.onDeleteRestrict.indexOf(path) === -1) { return; } RefModel = models[modelName]; RefModel.schema....
javascript
{ "resource": "" }
q10002
train
function (start, end, force) { var bytesRead; if (end - start > config.bufferSize) { return reject(new Error("Range exceeds the max buffer size")); } if (force || start < currentRange.start || (start > currentRange.end)) { bytesRead = fs.readSync(fd, buffer, 0,
javascript
{ "resource": "" }
q10003
train
function (start, end) { var offsetStart; var offsetEnd; loadBufferIfRequired(start, end);
javascript
{ "resource": "" }
q10004
train
function (index) { var rawItem; var position = positions[index]; try { rawItem = readEntry(position.start, position.end); return JSON.parse(rawItem);
javascript
{ "resource": "" }
q10005
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof AtomContent)){ return new AtomContent(json); } // If
javascript
{ "resource": "" }
q10006
isValidWIF
train
function isValidWIF (key, network) { try { let dec = wif.decode(key); if (network) { return dec.version === network.wif }
javascript
{ "resource": "" }
q10007
_cleanObserver
train
function _cleanObserver(observer) { if (!attachedNotifierCountMap.get(observer) && !pendingChangesMap.has(observer)) { attachedNotifierCountMap.delete(observer); var index = observerCallbacks.indexOf(observer);
javascript
{ "resource": "" }
q10008
train
function(callback) { if (self._cxnState !== self.cxnStates.CONNECTED) { callback(new Error("(2) Error occurred while attempting to lock "+ name)); return; } try { // client doesn't like paths ending in
javascript
{ "resource": "" }
q10009
$$
train
function $$(selector, ctx) { return Array.prototype.slice.call((ctx
javascript
{ "resource": "" }
q10010
toggleVisibility
train
function toggleVisibility(dom, show) { dom.style.display
javascript
{ "resource": "" }
q10011
setAttr
train
function setAttr(dom, name, val) { var xlink = XLINK_REGEX.exec(name); if (xlink
javascript
{ "resource": "" }
q10012
defineProperty
train
function defineProperty(el, key, value, options) { Object.defineProperty(el, key, extend({
javascript
{ "resource": "" }
q10013
handleEvent
train
function handleEvent(dom, handler, e) { var ptag = this.__.parent, item = this.__.item; if (!item) { while (ptag && !item) { item = ptag.__.item; ptag = ptag.__.parent; } } // override the event properties /* istanbul ignore next */ if (isWritable(e, 'currentTarget')) { e.currentTarg...
javascript
{ "resource": "" }
q10014
inheritFrom
train
function inheritFrom(target, propsInSyncWithParent) { var this$1 = this; each(Object.keys(target), function (k) { // some properties must be always in sync with the parent tag var mustSync = !isReservedName(k) && contains(propsInSyncWithParent, k); if (isUndefined(this$1[k]) || mustSync) {
javascript
{ "resource": "" }
q10015
unmountAll
train
function unmountAll(expressions) { each(expressions, function(expr) { if (expr instanceof Tag$1) { expr.unmount(true); } else
javascript
{ "resource": "" }
q10016
selectTags
train
function selectTags(tags) { // select all tags if (!tags) { var keys = Object.keys(__TAG_IMPL); return keys + selectTags(keys) } return tags .filter(function (t) { return !/[^-\w]/.test(t); }) .reduce(function (list,
javascript
{ "resource": "" }
q10017
safeRegex
train
function safeRegex (re) { var arguments$1 = arguments; var src = re.source; var opt = re.global ? 'g' : ''; if (re.ignoreCase) { opt += 'i'; } if (re.multiline) { opt += 'm'; }
javascript
{ "resource": "" }
q10018
globalEval
train
function globalEval (js, url) { if (typeof js === T_STRING) { var node = mkEl('script'), root = document.documentElement; // make the source available in the "(no domain)" tab // of Chrome DevTools, with a .js
javascript
{ "resource": "" }
q10019
parse
train
function parse(tokens) { var ast = []; var current = ast; var _line = 0; var _char = 0; var openCount = 0; var closeCount = 0; for (var i = 0; i < tokens.length; i++) { var token = tokens[i]; switch (token.type) { case TYPES.open: // Every tim...
javascript
{ "resource": "" }
q10020
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof NamePart)){ return new NamePart(json); } // If the given object
javascript
{ "resource": "" }
q10021
pathmap
train
function pathmap(path, spec, callback) { return spec.replace(regexp, function(match, replace, count, token) { var pattern; if (pattern = pathmap.patterns[token]) { return pattern.call(path, replace, count, callback);
javascript
{ "resource": "" }
q10022
train
function(replace, count, callback) { return pathmap.replace(
javascript
{ "resource": "" }
q10023
train
function(replace, count, callback) { return pathmap.replace(
javascript
{ "resource": "" }
q10024
train
function(replace, count, callback) { return pathmap.replace(
javascript
{ "resource": "" }
q10025
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof SourceReference)){ return new SourceReference(json); } // If the given object is
javascript
{ "resource": "" }
q10026
middleware
train
function middleware(fns) { return through.obj(function(file, enc, cb) { eachSeries(arrayify(fns), function(fn, next) { try { fn(file, next); } catch (err) {
javascript
{ "resource": "" }
q10027
toXML
train
function toXML(obj) { var xml = '' for (var prop in obj) { xml +=
javascript
{ "resource": "" }
q10028
go
train
function go() { return new Promise(handler) // Check for invalid `authCode`, this seems to happen at random intervals // within the neulion API, so we will only know when a request fails .catch(Errors.AuthenticationError, function(err) {
javascript
{ "resource": "" }
q10029
request
train
function request(meth, url, headers, query, data, cb) { var req = SA(meth, url); if (headers) req.set(headers); if (query) req.query(query); if (data) req.send(data); return
javascript
{ "resource": "" }
q10030
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Event)){ return new Event(json); } // If the given
javascript
{ "resource": "" }
q10031
loadNonCriticalCSS
train
function loadNonCriticalCSS (href) { var link = window.document.createElement('link'); link.rel = 'stylesheet'; link.href =
javascript
{ "resource": "" }
q10032
async
train
function async(value, bool) { var def = promise() setTimeout(function() { if(!bool) def.fulfill(value)
javascript
{ "resource": "" }
q10033
Registry
train
function Registry(options) { if (!(this instanceof Registry)) { return new Registry(options); } options = options || {}; debug('New Registry: %j', options); this.manager = options.manager || new UdpBroadcast(); this.services = {};
javascript
{ "resource": "" }
q10034
UdpBroadcastManager
train
function UdpBroadcastManager(options) { if (!(this instanceof UdpBroadcastManager)) { return new UdpBroadcastManager(options); } options = options || {}; Manager.call(this, options); debug('New UdpBroadcastManager: %j', options); this.dgramType = options.dgramType ? String(options.dgramType).toLower...
javascript
{ "resource": "" }
q10035
downloadSubtitles
train
async function downloadSubtitles (file) { const subtitles = await getSubtitles(file) const { dir, name } = path.parse(file) const subtitlesFile =
javascript
{ "resource": "" }
q10036
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Field)){ return new Field(json); }
javascript
{ "resource": "" }
q10037
_resolvePromises
train
function _resolvePromises (opts, val) { opts = opts || {} var duplicate = opts.duplicate if (is(Array, val)) {
javascript
{ "resource": "" }
q10038
_curry
train
function _curry (n, fn, args) { args = args || [] return function partial () { var rest = arrayFrom(arguments)
javascript
{ "resource": "" }
q10039
handleError
train
function handleError (task) { return function (err) { console.log(chalk.red(err));
javascript
{ "resource": "" }
q10040
Interpreter
train
function Interpreter(library, options, storage) { // What lengths I've gone to to use only 7-letter properties... this.library = new Library(CloneDeep(library || {})); this.options = Assign({}, Interpreter.DEFAULT_OPTIONS, options); this.balance = this.options.balance; this.timeout = Date.now() + th...
javascript
{ "resource": "" }
q10041
exec
train
function exec(inst, raw, argv, event, fin) { var after = nextup(inst, raw, argv, event, fin); return
javascript
{ "resource": "" }
q10042
nextup
train
function nextup(inst, orig, argv, event, cb) { return function nextupCallback(err, data) { if (err) return cb(err, null); if (_isQuoted(data)) return cb(null, _unquote(data)); if (_isValue(data)) return cb(null, _entityToValue(data, inst.library)); // Remove any nulls or undefineds f...
javascript
{ "resource": "" }
q10043
step
train
function step(inst, raw, argv, event, fin) { if (!_isPresent(raw)) return fin(_wrapError(_badInput(inst), inst, raw), null); var flat = _denestList(raw); preproc(inst, flat, argv, event, function postPreproc(err, data) {
javascript
{ "resource": "" }
q10044
preproc
train
function preproc(inst, prog, argv, event, fin) { var info = findPreprocs(inst, prog, [], []); function step(procs, parts, list) { if (!procs || procs.length < 1) { return fin(null, list); } var part = parts.shift(); var proc = procs.shift(); var ctx = { ...
javascript
{ "resource": "" }
q10045
findPreprocs
train
function findPreprocs(inst, list, procs, parts) { if (Array.isArray(list)) { while (list.length > 0) { var part = list.shift(); // Preprocessors must be the first elements in the list; // if we hit any non-preprocessors, immediately assume // we're done prepro...
javascript
{ "resource": "" }
q10046
branch
train
function branch(inst, list, argv, event, fin) { if (argv.length > 0) { // Append the argv for programs that return // a list that accepts them as parameters list = list.concat(argv.splice(0)); } // HACK HACK HACK. OK, so, when dealing with deeply recursive // functions in Runiq, ...
javascript
{ "resource": "" }
q10047
quote
train
function quote(inst, list, argv, event, fin) { // Remember to charge for the 'quote' function as a transaction if (!ok(inst, inst.options.quoteTransaction)) return exit(inst, list, fin); var entity = list[list.length - 1];
javascript
{ "resource": "" }
q10048
sequence
train
function sequence(inst, elems, argv, event, fin) { if (elems.length < 1) return fin(null, elems); // Running a sequence also costs some amount per element to sequence if (!ok(inst, inst.options.sequenceTransaction * elems.length)) {
javascript
{ "resource": "" }
q10049
parallel
train
function parallel(inst, elems, argv, event, fin, _postSequence) { var total = elems.length; var complete = 0; function check(err, list) { if (total === ++complete) { if (!_isFunc(list)) return _postSequence(list, fin);
javascript
{ "resource": "" }
q10050
postSequence
train
function postSequence(elems, fin) { // Treat the final value of a sequence as its return value var
javascript
{ "resource": "" }
q10051
edit
train
function edit(inst, list, index, argv, event, fin) { return function editCallback(err, data) { if (err) return fin(err);
javascript
{ "resource": "" }
q10052
_valuefyArgs
train
function _valuefyArgs(args, lib) { for (var i = 0; i < args.length; i++) {
javascript
{ "resource": "" }
q10053
_unquoteArgs
train
function _unquoteArgs(args) { for (var i = 0; i < args.length; i++) {
javascript
{ "resource": "" }
q10054
_entityToValue
train
function _entityToValue(item, lib) { if (typeof item === JS_STRING_TYPE) { // Only JSON-serializable entities may be put into a list var constant = lib.lookupConstant(item); if (constant !== undefined) return constant; } // Also unquote any item we got that also happens to be a
javascript
{ "resource": "" }
q10055
exec
train
function exec(query, config, done) { if(!query || (typeof query != 'string')){ throw new Error('Node-SQL: query was not in the correct format.'); return; } if(!config || (typeof config != 'object')){ throw new Error('Node-SQL: config was not in the correct format.'); return; } if(!done || (typ...
javascript
{ "resource": "" }
q10056
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Person)){ return new Person(json); } // If the given
javascript
{ "resource": "" }
q10057
train
function (str, n) { n = window.parseInt(n, 10); return new
javascript
{ "resource": "" }
q10058
train
function(callback){ ubeacon.setEddystoneURL( program.url , function(data,
javascript
{ "resource": "" }
q10059
train
function () { return new Promise((resolve, reject) => { var startTime = Date.now(); var size = fs.statSync(dataFile).size; var next = (readInfo, position) => { var jobs = [readNextChunk(readInfo)]; if (position) { jobs.push(readAndIndex(position, readInfo.readBuffer)); ...
javascript
{ "resource": "" }
q10060
train
function (indexName, key) { return new Promise((resolve, reject) => { if (index[indexName]) { resolve(index[indexName][key] || null);
javascript
{ "resource": "" }
q10061
train
function (id) { return typeof id === 'number' ? clear(id) : void(
javascript
{ "resource": "" }
q10062
animationLoop
train
function animationLoop() { var // grab current time t = time(), // calculate how many millisends we have fps = 1000 / next.minFPS, // used to flag overtime in case we exceed milliseconds overTime = false, // take current frame queue length length = getLength(qframe, qframex) ; // i...
javascript
{ "resource": "" }
q10063
create
train
function create(callback) { /* jslint validthis: true */ for (var queue = this, args = [], info = { id: {}, fn: callback, ar: args }, i = 1; i < arguments.length; i++
javascript
{ "resource": "" }
q10064
drop
train
function drop(queue, id) { var i = findIndex(queue, id),
javascript
{ "resource": "" }
q10065
findIndex
train
function findIndex(queue, id) { var i = queue.length; while (i--
javascript
{ "resource": "" }
q10066
getLength
train
function getLength(queue, queuex) { // if previous call didn't execute all callbacks return queuex.length ? // reprioritize the
javascript
{ "resource": "" }
q10067
idleLoop
train
function idleLoop(deadline) { var length = getLength(qidle, qidlex), didTimeout = deadline.didTimeout ; if (length) { // reschedule upfront next idle callback requestIdleCallback(idleLoop, {timeout: next.maxIdle}); // this prevents the need for a try/catch within the while loop // reassign...
javascript
{ "resource": "" }
q10068
infoId
train
function infoId(queue, info) { for (var i = 0, length = queue.length, tmp; i < length; i++) { tmp = queue[i]; if (
javascript
{ "resource": "" }
q10069
sameValues
train
function sameValues(a, b) { var i = a.length, j = b.length, k = i === j ; if (k) { while (i--) {
javascript
{ "resource": "" }
q10070
asPath
train
function asPath({ ancestors }) { const path = []; for (const { key } of ancestors) { if (key != null) { if (typeof
javascript
{ "resource": "" }
q10071
Identity
train
function Identity(category, type, name) { Element.call(this, 'identity', 'http://jabber.org/protocol/disco#info'); this.category =
javascript
{ "resource": "" }
q10072
Exception
train
function Exception(err, options) { if (!(this instanceof Exception)) return new Exception(err, options); if ('string' === typeof err) err = { stack: (new Error(err)).stack, message: err }; debug('generating a new exception for: %s', err.message); options = options || {}; this.initialize(options); ...
javascript
{ "resource": "" }
q10073
bytes
train
function bytes(b) { if (!readable) return b; var tb = ((1 << 30) * 1024) , gb = 1 << 30 , mb = 1 << 20 , kb = 1 << 10 , abs = Math.abs(b); if (abs >= tb) return (Math.round(b / tb * 100) / 100) + 'tb'; if (abs >= gb) return (Math.round(b / gb * 100) / 100) + 'gb'; if (abs >...
javascript
{ "resource": "" }
q10074
readBytes
train
async function readBytes ({ file, start, chunkSize }) { const buffer = Buffer.alloc(chunkSize) const fileDescriptor = await fs.open(file, 'r') const { bytesRead } = await fs.read( fileDescriptor, buffer,
javascript
{ "resource": "" }
q10075
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof AtomGenerator)){ return new AtomGenerator(json); } // If
javascript
{ "resource": "" }
q10076
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Relationship)){ return new Relationship(json); } // If the given object
javascript
{ "resource": "" }
q10077
LocalStorage
train
function LocalStorage (opts) { if (!isLocalStorageSupported()) { console.warn('localStorage not supported! (data will be stored in memory)') } var self = this Storage.call(self, opts) opts = _.extend({ keyName: 'blockchainjs_' + self.networkName }, opts) if (!this.compactMode) { throw new e...
javascript
{ "resource": "" }
q10078
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Links)){ return new Links(json); }
javascript
{ "resource": "" }
q10079
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof PlaceDisplayProperties)){ return new PlaceDisplayProperties(json); } // If
javascript
{ "resource": "" }
q10080
getDepartures
train
function getDepartures (fromStationId, toStationId, fromTime, toTime) { fromTime = fromTime || '-00:30:00' toTime = toTime || '03:00:00' let optionalFilters = '' if (toStationId) { optionalFilters += '<OR>' + `<EQ name="ViaToLocation.LocationName" value="${toStationId}"/>` + `<EQ name="ToLocati...
javascript
{ "resource": "" }
q10081
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Gender)){ return new Gender(json); } // If the given
javascript
{ "resource": "" }
q10082
on
train
function on(first, operator, second) { var data, bool = this._bool(); switch (arguments.length) { case 1: { if (typeof first === 'object' && typeof first.toSQL !== 'function') { var i = -1, keys = Object.keys(first); var method = bool === '...
javascript
{ "resource": "" }
q10083
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof RecordDescriptor)){ return new RecordDescriptor(json); } // If
javascript
{ "resource": "" }
q10084
emitData
train
function emitData() { for(var i=0;i<streamQueue.length;i++) { var dataQueue = streamQueue[i].dataQueue; if(streamQueue[i].pending) { return; } for(var j=0;j<dataQueue.length;j++) { var data = dataQueue[j]; if(!!data) {
javascript
{ "resource": "" }
q10085
store
train
function store (action) { if (!action || !isPlainObject(action)) { throw new Error('action parameter is required and must be a plain object') } if (!action.type || typeof action.type !== 'string') { throw new Error('type property of action is required and must be a string') } if (isEmi...
javascript
{ "resource": "" }
q10086
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Qualifier)){ return new Qualifier(json); } // If the given object
javascript
{ "resource": "" }
q10087
hasRemoteMethod
train
function hasRemoteMethod(model, methodName) { return model.sharedClass .methods({ includeDisabled: false })
javascript
{ "resource": "" }
q10088
addRemoteMethods
train
function addRemoteMethods(app) { return Object.keys(app.models).forEach(modelName => { const Model = app.models[modelName] if (typeof Model._templates !== 'function') { return null } return Object.keys(Model._templates()).forEach(templateName => { const fnName = `_template_${templateName...
javascript
{ "resource": "" }
q10089
addAcls
train
function addAcls(app, config) { config.acls = config.acls || [] return Promise.resolve(Object.keys(app.models)).mapSeries(modelName => { const Model = app.models[modelName] if (typeof Model._templates !== 'function') { return null } return Promise.resolve(Object.keys(Model._templates())) ...
javascript
{ "resource": "" }
q10090
match
train
function match(routes = [], path) { for (var i = 0; i < routes.length; i++) { var re = pathRegexps[routes[i].path] ||
javascript
{ "resource": "" }
q10091
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof DisplayProperties)){ return new DisplayProperties(json); } // If
javascript
{ "resource": "" }
q10092
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof AtomEntry)){ return new AtomEntry(json); } //
javascript
{ "resource": "" }
q10093
Dispatcher
train
function Dispatcher() { let lastId = 1; let prefix = "ID_"; let callbacks = {}; let isPending = {}; let isHandled = {}; let isDispatching = false; let pendingPayload = null; function invokeCallback(id) { isPending[id] = true; callbacks[id](pendingPayload); isHandled[id] = true; } this....
javascript
{ "resource": "" }
q10094
train
function () { if (sequence) { var localNodes = sequence.nodes; var localIndex = (localNodes) ? localNodes.indexOf(node) : null; if (localNodes) { if (localIndex ===
javascript
{ "resource": "" }
q10095
train
function (variation) { variation = variation || 0; var localNodes = sequence.nodes; var localIndex = (localNodes) ? localNodes.indexOf(node) : null; // If there are no additional nodes in this sequence, // advance to the next one if (localIndex === null || localIndex >= (localNodes.length - 1)) { ...
javascript
{ "resource": "" }
q10096
train
function () { var localNodes = sequence.nodes; var localIndex = (localNodes) ? localNodes.indexOf(node) : null; // Delete any variation forks at this point // TODO: Make this configurable... we should keep this if we're // remembering chosen paths delete this.path[this.path.m]; if (!localIndex ||...
javascript
{ "resource": "" }
q10097
train
function (path) { if (typeof path === 'string') { path = this.pathTransform(path, 'object'); } else if (typeof path === 'number') { path = { m: path }; } this.reset(); var n = node; for (var i = 0; i < path.m && n; i += 1) {
javascript
{ "resource": "" }
q10098
train
function () { var localSequence = this.game; var moves = 0; while(localSequence) { moves += localSequence.nodes.length; if (localSequence.sequences) { localSequence = localSequence.sequences[0]; } else { localSequence = null; } } // TODO: Right now we're *assuming* that the ro...
javascript
{ "resource": "" }
q10099
train
function (text) { if (typeof text === 'undefined') { // Unescape characters if (node.C) { return node.C.replace(/\\([\\:\]])/g, '$1'); } else { return '';
javascript
{ "resource": "" }