_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
language
stringclasses
1 value
meta_information
dict
q13600
ParseWithConfig
train
function ParseWithConfig(config, argv) { const debug = false; const parser = dashdash.createParser({ options : config }); const helpText = parser.help({ includeEnv : true }).trimRight(); try { const opts = parser.parse(argv, 2); const innerOptions = parser.options; const key...
javascript
{ "resource": "" }
q13601
hasEscapeFirst
train
function hasEscapeFirst (data, offset) { isBuffer = (!isQuiet && typeof data !== 'string') escaped = (this.prev.idx > 0) return escaped ? ( escapeOffset = offset - escLength, -1
javascript
{ "resource": "" }
q13602
train
function (config) { 'use strict'; //If is not instance of SaySomething return a new instance if (false === (this instanceof SaySomething)) { return new SaySomething(config); } events.EventEmitter.call(this);
javascript
{ "resource": "" }
q13603
executeController
train
function executeController(server, controller, req, res) { try { const promise = controller.call(server, req, res); if (promise && typeof
javascript
{ "resource": "" }
q13604
findMatchingExample
train
function findMatchingExample(req, code, type) { const swagger = req.swagger.root; const responses = req.swagger.rel.responses; // if no responses then exit const responseKeys = responses && typeof responses === 'object' ? Object.keys(responses) : []; if (responseKeys.length === 0) return { code: 50...
javascript
{ "resource": "" }
q13605
loadController
train
function loadController(controllersDirectory, controller, development) { const filePath = path.resolve(controllersDirectory, controller); try { return require(filePath); } catch (e)
javascript
{ "resource": "" }
q13606
full_uri_encode
train
function full_uri_encode(string) { string = encodeURIComponent(string); string =
javascript
{ "resource": "" }
q13607
train
function(err, privkey, pubkey) { if (err) throw err; this.pubkey = pubkey; this.privkey = privkey;
javascript
{ "resource": "" }
q13608
train
function(err, r, b) { if (err) throw err; try { fs.unlink(keyname, this.parallel()); fs.unlink(keyname + ".pub", this.parallel()); } catch(e) { // do nothing }; console.log("Heroku SSH
javascript
{ "resource": "" }
q13609
preparePackage
train
function preparePackage() { var ignoreFiles = ['package.json', 'README.md', 'LICENSE.md', '.gitignore', '.npmignore']; var ignoreCopyFiles = []; var copyRecursiveSync = function(src, dest) { var exists = fs.existsSync(src); var stats = exists && fs.statSync(src); var isDirectory = ex...
javascript
{ "resource": "" }
q13610
describe
train
function describe( object ) { return Object.getOwnPropertyNames( object ) .reduce( function( desc, key ) {
javascript
{ "resource": "" }
q13611
inherit
train
function inherit( ctor, sctor ) { ctor.prototype = Object.create(
javascript
{ "resource": "" }
q13612
CommandAsker
train
function CommandAsker(questions, options) { options = options || {}; if (!_.isArray(questions)) { throw "there are no questions available :'("; } this.questions = questions;
javascript
{ "resource": "" }
q13613
train
function( editor ) { // Backward compatibility. if ( editor instanceof CKEDITOR.dom.document ) return applyStyleOnSelection.call( this, editor.getSelection() ); if ( this.checkApplicable( editor.elementPath(), editor )
javascript
{ "resource": "" }
q13614
train
function( elementPath, editor, filter ) { // Backward compatibility. if ( editor && editor instanceof CKEDITOR.filter ) filter = editor; if ( filter && !filter.check( this )
javascript
{ "resource": "" }
q13615
train
function( element, fullMatch ) { var def = this._.definition; if ( !element || !def.ignoreReadonly && element.isReadOnly() ) return false; var attribs, name = element.getName(); // If the element name is the same as the style name. if ( typeof this.element == 'string' ? name == this.element : ...
javascript
{ "resource": "" }
q13616
checkIfNodeCanBeChildOfStyle
train
function checkIfNodeCanBeChildOfStyle( def, currentNode, lastNode, nodeName, dtd, nodeIsNoStyle, nodeIsReadonly, includeReadonly ) { // Style can be applied to text node. if ( !nodeName ) return 1; // Style definitely cannot be applied if DTD or data-nostyle do not allow. if ( !dtd[ nodeName ] || nodeIsNoSt...
javascript
{ "resource": "" }
q13617
checkIfStyleCanBeChildOf
train
function checkIfStyleCanBeChildOf( def, currentParent, elementName, isUnknownElement ) { return currentParent && ( ( currentParent.getDtd() || CKEDITOR.dtd.span
javascript
{ "resource": "" }
q13618
checkPositionAndRule
train
function checkPositionAndRule( nodeA, nodeB, def, posBitFlags ) { return (
javascript
{ "resource": "" }
q13619
applyStyleOnNestedEditables
train
function applyStyleOnNestedEditables( editablesContainer ) { var editables = findNestedEditables( editablesContainer ), editable, l = editables.length, i = 0, range = l && new CKEDITOR.dom.range( editablesContainer.getDocument() );
javascript
{ "resource": "" }
q13620
checkIfAllowedInEditable
train
function checkIfAllowedInEditable( editable, style ) { var filter = CKEDITOR.filter.instances[ editable.data( 'cke-filter'
javascript
{ "resource": "" }
q13621
toPre
train
function toPre( block, newBlock ) { var bogus = block.getBogus(); bogus && bogus.remove(); // First trim the block content. var preHtml = block.getHtml(); // 1. Trim head/tail spaces, they're not visible. preHtml = replace( preHtml, /(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '' ); // 2. Delete ANSI whitespaces...
javascript
{ "resource": "" }
q13622
getAttributesForComparison
train
function getAttributesForComparison( styleDefinition ) { // If we have already computed it, just return it. var attribs = styleDefinition._AC; if ( attribs ) return attribs; attribs = {}; var length = 0; // Loop through all defined attributes. var styleAttribs = styleDefinition.attributes; if ( st...
javascript
{ "resource": "" }
q13623
train
function( callback ) { if ( !this._.stylesDefinitions ) { var editor = this, // Respect the backwards compatible definition entry configStyleSet = editor.config.stylesCombo_stylesSet || editor.config.stylesSet; // The false value means that none styles should be loaded. if ( configStyleSet === false...
javascript
{ "resource": "" }
q13624
walk
train
function walk (directoryPath, filter, collector) { var defer = Q.defer() fs.stat(directoryPath, function (err, stat) { if (err) { if (err.code === 'ENOENT') { // Like q-io/fs, return an empty array, if the directory does not exist return defer.resolve([]) } return defer.reject(...
javascript
{ "resource": "" }
q13625
doesEscapeRoot
train
function doesEscapeRoot(root,file) { if (file.indexOf(path.normalize(root+"/")) === 0)
javascript
{ "resource": "" }
q13626
httpOk
train
function httpOk(response,isHead,body) { response.setHeader(HTTP_CONTENT_TYPE,MIME_TYPE_JAVASCRIPT); response.setHeader(HTTP_CONTENT_LENGTH,body.length);
javascript
{ "resource": "" }
q13627
closeConnection
train
function closeConnection(options) { //no options, close/delete all connection references if (!options) { try { mssql.close(); } catch(err){} //create list to track items to close let closeList = []; //iterate through each connection for (let key in promises) { //if there's a cl...
javascript
{ "resource": "" }
q13628
train
function (_data, cb) { if(!db.data) return cb(new Error('kiddb not open')) if(!writing) return db._update(_data, cb) db.__data = _data qcb.push(cb) onWrote = function () { onWrote = null var cbs = qcb; qcb = []
javascript
{ "resource": "" }
q13629
train
function (key, cb) { if(!db.data) return cb(new Error('kiddb not open')) if(db.data[key]) cb(null,
javascript
{ "resource": "" }
q13630
downloadArchive
train
function downloadArchive(id, call, options, done) { grunt.log.write('Downloading '.gray + id.yellow + ' ... '.gray); request(call, function(err, response, body) { if (err) return done(err); var result = JSON.parse(body); if (!result.success) { return done(result.error + ' with game "' + id + ...
javascript
{ "resource": "" }
q13631
train
function(dest, src) { if(src.indexOf('.js') > -1) { return dest + src.replace('.js','.' + tsPrefix + newTS + '.js'); }
javascript
{ "resource": "" }
q13632
isEscapeingAt
train
function isEscapeingAt(string, index) { if (index === 0) { return false; }
javascript
{ "resource": "" }
q13633
parse
train
function parse (defaultValue, data) { try { return JSON.parse(data) } catch (error) {
javascript
{ "resource": "" }
q13634
load
train
function load(fromPath, relativePaths, opts) { opts = opts || {}; var ignores = opts.ignores || []; if (typeof ignores === 'string') ignores = [ignores]; var conf = {}; relativePaths.forEach(function(relativePath) { var path = Path.resolve(fromPath, relativePath); var config = loadF...
javascript
{ "resource": "" }
q13635
create
train
function create() { var args = Array.prototype.slice.call(arguments); var conf = {}; args.forEach(function(config) { extend(conf, config);
javascript
{ "resource": "" }
q13636
SettingsFile
train
function SettingsFile(app, options) { if (!app) { throw new TypeError('SettingsFile must accept an app name'); } else if (typeof app !== 'string') { throw new TypeError('SettingsFile app name must
javascript
{ "resource": "" }
q13637
train
function (content) { var fileContent = self._readFileSync(); fileContent.instances = fileContent.instances || {};
javascript
{ "resource": "" }
q13638
train
function(id, params) { return req.standardRequest(`${config.host}/teams/${id}/teams?${req
javascript
{ "resource": "" }
q13639
train
function(id, projectId, body) { return req.standardRequest(`${config.host}/teams/${id
javascript
{ "resource": "" }
q13640
createStream
train
function createStream (options) { options = options || {} var stream = through2.obj(function transform (chunk, encoding, cb) { stream.push(options.objectMode ? chunk : JSON.stringify(chunk)+'\n') cb() }) stream.close = function close () { setImmediate...
javascript
{ "resource": "" }
q13641
feed
train
function feed(op, pnode) { if (numStreams > 0)
javascript
{ "resource": "" }
q13642
setPnodeData
train
function setPnodeData (pnode, value) { if (!pnode.exists) { pnode._data = value persistPnode(pnode) } else if (pnode._data !== value) { pnode._data = value
javascript
{ "resource": "" }
q13643
unsetPnodeData
train
function unsetPnodeData (pnode) { if (pnode.hasOwnProperty('_data') && pnode._data !== undefined) { pnode._data = undefined incTransaction()
javascript
{ "resource": "" }
q13644
incPnodeVersion
train
function incPnodeVersion (pnode) { pnode._version = pnode._version ? pnode._version + 1 : 1 pnode._mtxid = ptree.txid pnode._mtime = new Date
javascript
{ "resource": "" }
q13645
incChildrenVersion
train
function incChildrenVersion (pnode) { if (pnode && pnode._childrenVersion) pnode._childrenVersion++
javascript
{ "resource": "" }
q13646
addChild
train
function addChild(parent, child) { parent._children.push(child)
javascript
{ "resource": "" }
q13647
removeChild
train
function removeChild(parent, child) { var parentChildIdx = parent._children.indexOf(child) parent._children.splice(parentChildIdx,
javascript
{ "resource": "" }
q13648
pnodeParents
train
function pnodeParents (pnode) { if (!pnode.valid) return undefined var parentPaths = parents(pnode.path), list = [] for (var i = 0; i
javascript
{ "resource": "" }
q13649
pnodeParent
train
function pnodeParent (pnode) { if (!pnode.valid) return undefined var parentPath
javascript
{ "resource": "" }
q13650
parameters
train
function parameters (spec) { var defs = {} var envs = {} return function (params) { init(spec, defs, envs) var opts = cat(defs, envs, params) var errs = [] def(opts, spec, errs)
javascript
{ "resource": "" }
q13651
init
train
function init (spec, defs, envs) { for (var key in spec || {}) { if (spec[key].def) defs[key] = spec[key].def if
javascript
{ "resource": "" }
q13652
def
train
function def (params, spec, errs) { for (var key
javascript
{ "resource": "" }
q13653
req
train
function req (params, spec, errs) { for (var key in spec)
javascript
{ "resource": "" }
q13654
val
train
function val (params, spec, errs) { for (var key in params) { if (key in spec &&
javascript
{ "resource": "" }
q13655
header
train
function header(length) { var res = [0x09, 0x09, 0x00, 0x00]; res.push((length & 0x000000FF) >> 0); res.push((length & 0x0000FF00) >> 8); res.push((length & 0x00FF0000) >> 16);
javascript
{ "resource": "" }
q13656
train
function (emit) { ipc.send({ cmd : 'setup', emit: emit,
javascript
{ "resource": "" }
q13657
resolveObjectName
train
function resolveObjectName(view){ return cache[view] || (cache[view] = view .split('/') .slice(-1)[0] .split('.')[0] .replace(/^_/, '') .replace(/[^a-zA-Z0-9 ]+/g, ' ')
javascript
{ "resource": "" }
q13658
block
train
function block(name, html) { // bound to the blocks object in renderFile var blk = this[name]; if (!blk) { // always create, so if we request a // non-existent block we'll get a new
javascript
{ "resource": "" }
q13659
script
train
function script(path, type) { if (path) { var html = '<script src="'+path+'"'+(type ? 'type="'+type+'"' : '')+'></script>';
javascript
{ "resource": "" }
q13660
stylesheet
train
function stylesheet(path, media) { if (path) { var html = '<link rel="stylesheet" href="'+path+'"'+(media
javascript
{ "resource": "" }
q13661
insertAds
train
function insertAds(adUnit, ads, adLoadedCallback) { var adContainers = page.getAdContainers(adUnit); if (!adContainers.length) { logger.error("No ad containers could be found. stopping insertion for adUnit " + adUnit.name); return []; //Ad can't be inserted } var adBuilder = new Ad...
javascript
{ "resource": "" }
q13662
handleImageLoad
train
function handleImageLoad(adElement, adLoadedCallback) { var adImage = adElement.querySelector("img"); if (adImage) { (function (adToInsert, adImage) { adImage.onload = function () { adLoadedCallback(adToInsert,
javascript
{ "resource": "" }
q13663
train
function (powder) { var callback = function (err) { shooting--; if (err) { // Only emit error if a listener exists // This is mainly to prevent silent errors in promises if (machinegun.listenerCount('error')) machinegun.emit('error', err); if (opt.giveUpOnError) machinegun.giveUp(err); ...
javascript
{ "resource": "" }
q13664
callPromise
train
function callPromise(fn, args) { return new Promise((resolve, reject) => { // promisified callback function callback(err,other) { // check if the 'err' is boolean, if so then this is a 'exists' callback special case if (err && (typeof err !== 'boolean')) return
javascript
{ "resource": "" }
q13665
makePromise
train
function makePromise(fn) { return function() { var args = Array.prototype.slice.call(arguments); if (hasCallback(args)) { // argument list has callback, so call method with callback return callCallback(fn, args);
javascript
{ "resource": "" }
q13666
standardizeAddress
train
function standardizeAddress(address, callback) { var url = address_url + encodeURIComponent(address) + '?format=json'; request(url, function(err, resp, body) { var
javascript
{ "resource": "" }
q13667
getAddressDetails
train
function getAddressDetails(body, callback) { var addresses = JSON.parse(body).addresses if(addresses.length == 0) { callback(new Error('No property information
javascript
{ "resource": "" }
q13668
isValidPackageName
train
function isValidPackageName(name) { const stats = validateName(name); return stats.validForNewPackages
javascript
{ "resource": "" }
q13669
isValidPlatform
train
function isValidPlatform() { if (appSettings.overrides && appSettings.overrides.platform) { return true; //If a platform override is set, it's always valid
javascript
{ "resource": "" }
q13670
detectFormFactor
train
function detectFormFactor() { var viewPortWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); var displaySettings = appSettings.displaySettings; //convenience variable var formFactor; if (viewPortWidth >= displaySettings.mobile.minWidth && viewPortWidth <= displaySettings.m...
javascript
{ "resource": "" }
q13671
train
function () { var pkgJson = grunt.file.readJSON("package.json"); if (pkgJson.jspm && pkgJson.jspm.directories
javascript
{ "resource": "" }
q13672
train
function(treeRoot) { var stat = fs.statSync(treeRoot); if (stat.isDirectory()) { return buildTree(treeRoot); }
javascript
{ "resource": "" }
q13673
train
function(tree, options) { if (!options) { options = { ext: '.css', importFormat: null, // to be initialized just bellow encoding: 'utf-8' }; } if (!options.ext) { options.ext = '.css'; } if (!options.importFormat) { if (option...
javascript
{ "resource": "" }
q13674
validateBemDecl
train
function validateBemDecl(bemDecl, fileName) { let errors = []; bemDecl.forEach((decl)
javascript
{ "resource": "" }
q13675
validateBemDeclItem
train
function validateBemDeclItem(decl, fileName) { let errors = []; Object.keys(decl).forEach((key) => { const val = decl[key]; if (val === '[object Object]') { errors.push(new Error('Error
javascript
{ "resource": "" }
q13676
_getToken
train
function _getToken( /*klass, klass1, klass2*/ ) { if ( !tokens ) { throw new Error( 'no tokens found' ); } var _args = [ ].slice.call( arguments ).join( ' ' ).split( ' ' ); var _result = _args.map( function ( klass ) { var token = tokens[ klass ]; ...
javascript
{ "resource": "" }
q13677
handleBuffer
train
function handleBuffer (file, encoding, cb) { const config = configParser(String(file.contents));
javascript
{ "resource": "" }
q13678
handleStream
train
function handleStream (file, encoding, cb) { let config = ''; file.contents.on('data', chunk => { config += chunk; }); file.contents.on('end', () => { config
javascript
{ "resource": "" }
q13679
gulpHolograph
train
function gulpHolograph () { return through.obj(function (file, encoding, cb) { // Handle any non-supported types. // This covers directories and symlinks as well, as they have to be null. if (file.isNull()) {
javascript
{ "resource": "" }
q13680
JModelError
train
function JModelError(obj) { this.message = obj['message']; this.propertyName
javascript
{ "resource": "" }
q13681
normalize
train
function normalize(filepath) { // resolve to an absolute ppath if (!path.isAbsolute || !path.isAbsolute(filepath)) filepath =
javascript
{ "resource": "" }
q13682
parse
train
function parse(contents, retained, parser) { var errors = [], data = [], lines = 0; // optional parser if (!parser) parser = JSON; // process each line of the file contents.toString().split('\n').forEach(function(line) { if (!line) return; lines++; try { data.pu...
javascript
{ "resource": "" }
q13683
createTranspiler
train
function createTranspiler ({ mappers = {}, initialScopeData } = {}) { const config = {
javascript
{ "resource": "" }
q13684
MatchPath
train
function MatchPath() { var defaultAction = 'welcome', defaultMethod = 'index'; /** * Resolve uri * @param request * @returns {*} */ this.resolve = function (request) { var action = defaultAction; var method = defaultMethod; if ('/' != request.url) { var uriComponents = request...
javascript
{ "resource": "" }
q13685
resolveTemplateFiles
train
function resolveTemplateFiles(name) { // Create paths for resolving var customFile = customDir + '/' + name + '.js', customTemplateDir = customDir + '/' + name + '/**/*', stdFile = stdDir + '/' + name + '.js', stdTemplateDir = stdDir + '/' + name + '/**/*'; // Grab any and all files...
javascript
{ "resource": "" }
q13686
rotate
train
function rotate(angle, cx, cy) { var cosAngle = cos(angle); var sinAngle = sin(angle); var rotationMatrix = { a: cosAngle, c: -sinAngle, e: 0, b: sinAngle, d: cosAngle,
javascript
{ "resource": "" }
q13687
rotateDEG
train
function rotateDEG(angle) { var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
javascript
{ "resource": "" }
q13688
reload
train
function reload(args) { if (args !== undefined) { if (args.l !== undefined) { fs.closeSync(1); fs.openSync(args.l, 'a+'); } if (args.e !== undefined)
javascript
{ "resource": "" }
q13689
setupHandlers
train
function setupHandlers() { function terminate(err) { util.log('Uncaught Error: ' + err.message); console.log(err.stack); if (proc.shutdownHook) { proc.shutdownHook(err, gracefulShutdown); } }
javascript
{ "resource": "" }
q13690
enableCommand
train
function enableCommand(consoleService, moduleId, msg, cb) { if (!moduleId) { logger.error(`fail to enable admin module for ${moduleId}`); cb('empty moduleId'); return; } const modules = consoleService.modules; if (!modules[moduleId]) { cb(null, protocol.PRO_FAIL); ...
javascript
{ "resource": "" }
q13691
registerRecord
train
function registerRecord(service, moduleId, module) { const record = { moduleId: moduleId, module: module, enable: false }; if (module.type && module.interval) { if (!service.master && record.module.type === 'push' || service.master && record.module.type !== 'push') {// eslin...
javascript
{ "resource": "" }
q13692
addToSchedule
train
function addToSchedule(service, record) { if (record && record.schedule) { record.jobId = schedule.scheduleJob({ start: Date.now() + record.delay, period: record.interval },
javascript
{ "resource": "" }
q13693
exportEvent
train
function exportEvent(outer, inner, event) { inner.on(event, (...args) => {
javascript
{ "resource": "" }
q13694
add_group
train
function add_group() { server.EntryGroupNew(function(err, path) { if (err) { sails.log.error('DBus: Could not call org.freedesktop.Avahi.Server.EntryGroupNew'); return; } service.getInterface( path,
javascript
{ "resource": "" }
q13695
add_service
train
function add_service() { // Default configuration. Overrides can be defined in `config/avahi.js`. sails.log.info('Publishing service ' + config.name + ' (' + config.type + ') on port '+ config.port); group.AddService( avahi.IF_UNSPEC.value,
javascript
{ "resource": "" }
q13696
triggerEvent
train
function triggerEvent(eventType, options) { var event, key; options = options || {}; eventType = 'opbeat' + eventType.substr(0,1).toUpperCase() + eventType.substr(1); if (document.createEvent) { event = document.createEvent('HTMLEvents'); event.initEvent(eventType, true, true); } ...
javascript
{ "resource": "" }
q13697
train
function(url, method = 'get', body = undefined) { var deferred = Q.defer(); this.extendedRequest(url, method, body) .then((res) => { deferred.resolve(res.body);
javascript
{ "resource": "" }
q13698
bowerPackageURL
train
function bowerPackageURL(packageName, cb) { if (typeof cb !== 'function') { throw new TypeError('cb must be a function'); } if (typeof packageName !== 'string') { cb(new TypeError('packageName must be a string')); return; } http.get('https://bower.herokuapp.com/packages/' + ...
javascript
{ "resource": "" }
q13699
addPoints
train
function addPoints (x1, y1, x2, y2, cb) { var
javascript
{ "resource": "" }