_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
language
stringclasses
1 value
meta_information
dict
q9900
train
function(options) { options = options || {}; return this.append([ 'thumbnail:width=' + (options.width || 50), 'height=' +
javascript
{ "resource": "" }
q9901
train
function(options) { options = options || {}; var params = [ 'position=' + (options.position || 'top-left'), 'x=' + toInt(options.x || 0), 'y=' + toInt(options.y || 0) ]; if (options.imageIdentifier) { params.push('img=' + options.imageIde...
javascript
{ "resource": "" }
q9902
train
function() { return new ImageUrl({ transformations: this.transformations.slice(0), baseUrl: this.rootUrl, user: this.user, publicKey: this.publicKey, privateKey: this.privateKey,
javascript
{ "resource": "" }
q9903
train
function(encode) { var query = this.queryString || '', transformations = this.transformations, transformationKey = encode ? 't%5B%5D=' : 't[]='; if (encode) { transformations = transformations.map(encodeURIComponent); } if (this.transformations.lengt...
javascript
{ "resource": "" }
q9904
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Identifiers)){ return new Identifiers(json); } // If the given object
javascript
{ "resource": "" }
q9905
train
function ( value ) { if ( this.isObject(value) ) { //$('.touch_area').get(0).constructor.toString() return !!( value && value.nodeType === 1 && value.nodeName ); } else {
javascript
{ "resource": "" }
q9906
train
function ( type ) { if ( /pointerdown/i.test(type) ) { type = 'touchstart'; } else if ( /pointermove/i.test(type) ) { type = 'touchmove'; } else if ( /pointerup/i.test(type) ) {
javascript
{ "resource": "" }
q9907
train
function(anyConfig) { var result = {}; result.userName = anyConfig.user || anyConfig.userName || defaultConfig.userName; result.password = anyConfig.password || defaultConfig.password; result.server = anyConfig.host || anyConfig.server || defaultConfig.host; result.options = any...
javascript
{ "resource": "" }
q9908
train
function(request, parameters) { if (!parameters) { return; } var keys = Object.keys(parameters); var type = false; var value = null; var options = null; for (var i = keys.length - 1; i >= 0; i--) { value = parameters[keys[i]]; options = null; if (value instanceof Object && value.type && value.hasOwnPro...
javascript
{ "resource": "" }
q9909
train
function(target) { target.adapter = exports; target.query = execQuery.bind(target); // Tedious cannot execute more than one query at a time, so we have to // implement a queue for queries, just in case someone tries to set // multiple queries in a row (like node-any-db-adapter-spec tests do). target._queue = [];...
javascript
{ "resource": "" }
q9910
htmlCloseError
train
function htmlCloseError(options) { options = options || {}; options.debugLocalNetwork = options.debugLocalNetwork == null ? true : options.debugLocalNetwork; return function (err, req, res, next) { var msg = err.message || err.code; res.statusCode = err.status || err.statusCode || 500; ...
javascript
{ "resource": "" }
q9911
jsonCloseError
train
function jsonCloseError(options) { if (options === void 0) { options = {}; } options.debugLocalNetwork = options.debugLocalNetwork == null ? true : options.debugLocalNetwork; return function (err, req, res, next) { try { err = toError(err); var statusMessage = err.message || ...
javascript
{ "resource": "" }
q9912
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Attribution)){ return new Attribution(json); } // If the given object
javascript
{ "resource": "" }
q9913
adaptModulePath
train
function adaptModulePath(modulePath, state) { // const fileName = state.file.opts.filename; const options = getStateOptions(state); const filesMap = createFilesMap(options); const rootPath = getRootPath(options); let module = determineContext(modulePath, options); // Do not generate infinite cyrcular refe...
javascript
{ "resource": "" }
q9914
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Conclusion)){ return new Conclusion(json); } // If the given object
javascript
{ "resource": "" }
q9915
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof EventRole)){ return new EventRole(json); } // If the given object is already an
javascript
{ "resource": "" }
q9916
train
function(finishedCallback){ self.getUARTProtocolVersion(function(data,error){ self.deviceData.uartProtocolVersion
javascript
{ "resource": "" }
q9917
train
function(finishedCallback){ self.getHardwareModel(function(data,error){ self.deviceData.hardwareModel
javascript
{ "resource": "" }
q9918
train
function(finishedCallback){ self.getHardwareVersion(function(data,error){ self.deviceData.hardwareVersion
javascript
{ "resource": "" }
q9919
train
function(finishedCallback){ self.getFirmwareVersion(function(data,error){ self.deviceData.firmwareVersion
javascript
{ "resource": "" }
q9920
train
function (path) { if (fs.existsSync(path) && fs.statSync(path).isDirectory())
javascript
{ "resource": "" }
q9921
needFix
train
function needFix (stylecowSupport, task, method) { const taskSupport = task[method]; if (!taskSupport || !stylecowSupport) { return true; } for (let browser in taskSupport) { if (stylecowSupport[browser] === false) { continue; } if (method === 'forBrowsersL...
javascript
{ "resource": "" }
q9922
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof AtomSource)){ return new AtomSource(json); } //
javascript
{ "resource": "" }
q9923
transformPropertiesToCamelCase
train
function transformPropertiesToCamelCase (object) { var output = {} for (var _key in object) { if (typeof object === 'string') { return object.replace(' !important', '') } var key = _key var value = object[_key] if (~key.indexOf('-')) { var splittedKeys = key.split('-') splittedKeys = sp...
javascript
{ "resource": "" }
q9924
Item
train
function Item(jid, node, name) { Element.call(this, 'item', 'http://jabber.org/protocol/disco#items'); this.jid =
javascript
{ "resource": "" }
q9925
copyIcon
train
function copyIcon() { var dest = path.join(process.env.PWD, 'res'); // Make sure the destination exists mkdir(dest); return pify(fs.copy.bind(fs),
javascript
{ "resource": "" }
q9926
copyHooks
train
function copyHooks() { var src = path.join(__dirname, 'hooks'); var dest = path.join(process.env.PWD, 'hooks'); return pify(fs.copy.bind(fs), Promise)(path.join(__dirname, 'platforms.json'), path.join(dest, 'platforms.json')) .then(function () { memFsEditor.copyTpl(src, dest, options); return pify(me...
javascript
{ "resource": "" }
q9927
installHookDependencies
train
function installHookDependencies() { return Promise.all(hookDependencies.map(function
javascript
{ "resource": "" }
q9928
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Note)){ return new Note(json); } // If the given
javascript
{ "resource": "" }
q9929
makeWorker
train
function makeWorker(worker) { return { seneca: Seneca().client(worker), id: worker.id, up: undefined, lastCallDuration: -1,
javascript
{ "resource": "" }
q9930
nextWorker
train
function nextWorker(cb) { seneca.act('role:loadbalance,hook:balance', { workers: workers, lastWorker: lastWorker }, function (err, worker) { if (!worker)
javascript
{ "resource": "" }
q9931
addWorker
train
function addWorker(worker, cb) { function ping() { // A thing to keep in mind that right now it can take very long // (I think default is 22222 ms) for a request to time out, even // in scenarios like remote side breaking the connection and // ECONNREFUSED on reconnect. madeWorker.sene...
javascript
{ "resource": "" }
q9932
getSubtitlesByFilename
train
async function getSubtitlesByFilename (filename) { // TODO: revamp this + add unit tests return getSubtitlesList(filename) .then(parseSearchResults)
javascript
{ "resource": "" }
q9933
getSubtitlesList
train
async function getSubtitlesList (filename) { return request({ method: 'GET', uri: SUBSCENE_URL + '/subtitles/release', qs: { q: filename, // search query
javascript
{ "resource": "" }
q9934
parseSearchResults
train
function parseSearchResults (html) { const $ = cheerio.load(html) return $('a') .filter(function (index, element) { const spans = $(element).find('span') return spans.length === 2 && spans.eq(0).text().trim() === 'English' }) .map(function (index, element) {
javascript
{ "resource": "" }
q9935
downloadZip
train
async function downloadZip (href) { return request({ method: 'GET',
javascript
{ "resource": "" }
q9936
extractSrt
train
function extractSrt (buffer) { const zip = new AdmZip(buffer) const srtZipEntry = zip
javascript
{ "resource": "" }
q9937
train
function (e) { var self = this; if (e) { self.stopPropagation(e); } // Get current filter var currentFilter = self.filterStateModel.getActiveFilter();
javascript
{ "resource": "" }
q9938
train
function (e) { var self = this; if (self.isOpen !==
javascript
{ "resource": "" }
q9939
train
function (e) { var self = this; clearTimeout(self.closeTimeout); clearTimeout(self.deferCloseTimeout); if (e) { if (e.stopPropagation) { e.stopPropagation(); } if (e.preventDefault) { e.preventDefault(); } e.cancelBubble = true; }
javascript
{ "resource": "" }
q9940
train
function (e) { var self = this; // Don't do anything if already closed if (!self.isOpen) { return; }
javascript
{ "resource": "" }
q9941
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Address)){ return new Address(json); } // If the given
javascript
{ "resource": "" }
q9942
train
function(...path) { path = pathify(path); return noUndef(path)
javascript
{ "resource": "" }
q9943
train
function(params) { /** * Reckon version * @type {String} */ this.version = '0.1.0'; /** * Define delimiter that marks beginning of interpolation * @type {String} */ this.delimStart = settings.delimStart; /** * Define delimiter that marks end of interpolation * @type {String} */ ...
javascript
{ "resource": "" }
q9944
train
function(param) { /** * Reference the instance */ var rInstance = this; if (typeof param !== "undefined") { rInstance.text = param.text; rInstance.scopes = [].concat(param.scope); } /** * The required regexp computed using delims in settings * @type {RegExp} */ var re =...
javascript
{ "resource": "" }
q9945
train
function(expr, localScope) { var variables = ''; /** * If scope is a window object, no need to scopebox it */ if (typeof window !== "undefined" ? localScope !== window : true) { for(var i in localScope) { variables += 'var ' + i + ' = localScope.' +
javascript
{ "resource": "" }
q9946
train
function(setting) { if (typeof setting === "undefined") { if (typeof window !== "undefined") { if (typeof window.reckonSettings !== "undefined") { if (typeof window.reckonSettings.delimStart) { settings.delimStart = window.reckonSettings.delimStart; } if (typeof window.reckonSetting...
javascript
{ "resource": "" }
q9947
hash
train
async function hash (file) { const filesize = await fileUtil.getFileSize(file) const chunkSize = 64 * 1024 const firstBytesPromise = fileUtil.readBytes({ file, chunkSize, start: 0 }) const lastBytesPromise = fileUtil.readBytes({ file, chunkSize, start: filesize - chunkSize }) c...
javascript
{ "resource": "" }
q9948
controllerTemplateRouteResponse
train
function controllerTemplateRouteResponse() { if (this.template) { let match = this.template.toString().match(/!doctype ([a-z]+)/i), mime; // In the context where MIME type is not set, but we have a // DOCTYPE tag, we can force set the MIME // We want this here instead of...
javascript
{ "resource": "" }
q9949
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof GDate)){ return new GDate(json); } // If the given
javascript
{ "resource": "" }
q9950
loadProjectName
train
function loadProjectName(callback) { try { var contents = fs.readFileSync(path.join(__dirname, '../../config.xml'), 'utf-8'); if (contents) { // Windows is the BOM. Skip the Byte Order Mark. contents = contents.substring(contents.indexOf('<')); } var doc = new et.ElementTree(et.XML(contents)); var roo...
javascript
{ "resource": "" }
q9951
updateConfig
train
function updateConfig(target) { try { var contents = fs.readFileSync(path.join(__dirname, '../../config.xml'), 'utf-8'); if (contents) { // Windows is the BOM. Skip the Byte Order Mark. contents = contents.substring(contents.indexOf('<')); } var doc = new et.ElementTree(et.XML(contents)); var root = d...
javascript
{ "resource": "" }
q9952
train
function (cb) { // If the hook has been deactivated, just return if (!sails.config[this.configKey].check) { sails.log.verbose('Eslint hook deactivated.'); return cb(); } else { var format = sails.config[this.configKey].formatter || 'stylish'; var patterns = sails.con...
javascript
{ "resource": "" }
q9953
getParamAccessor
train
function getParamAccessor(id, params) { // easy access var paramGet = function (prop, alt, required) { if (arguments.length < 1) { throw (new Error('expected at least 1 argument')); } if (arguments.length < 2) { required = true; } if (params && hasOwnProp(params, prop)) { retur...
javascript
{ "resource": "" }
q9954
train
function(inDir, outDir){ var name = this.bundleOptions.name; var opts = this._generateEsperantoOptions(name); var transpilerName = formatToFunctionName[this.format]; var targetExtension = this.targetExtension; return esperanto.bundle({ base: inDir, entry: this.bundleOptions.entry })...
javascript
{ "resource": "" }
q9955
train
function(inDir, outDir, relativePath, newCache) { var ext = this._matchingFileExtension(relativePath); var moduleName = relativePath.slice(0, relativePath.length - (ext.length + 1)); var fullInputPath = path.join(inDir, relativePath);
javascript
{ "resource": "" }
q9956
train
function(moduleName, source, newCache) { var key = helpers.hashStrings([moduleName, source]); var entry = this._transpilerCache[key]; if (entry) { return newCache[key] = entry; } try { return newCache[key] = { output: this.toFormat(
javascript
{ "resource": "" }
q9957
train
function () { var me = this; me.callParent.apply(me, arguments);
javascript
{ "resource": "" }
q9958
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof TextValue)){ return new TextValue(json); } // If the given object
javascript
{ "resource": "" }
q9959
runProc
train
function runProc(args, cb) { var stoutBuffer = '', sterrBuffer = ''; var proc = cp.spawn('java', args, { cwd: config.rootDir + '/bin' }); proc.stdout.on('data', function(data) { stoutBuffer += data; }); proc.stderr.on('data', function(data) { sterrBuffer += data; ...
javascript
{ "resource": "" }
q9960
runCMD
train
function runCMD(options, cb) { if (options.cb) { cb = options.cb; } var args = ["-cp", ".", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1", "TerminalRunner"]; args.push(options.name); args.push(options.program); args.push(options.timeLimit);
javascript
{ "resource": "" }
q9961
runInServlet
train
function runInServlet(request, cb) { // log("waitingQueue:"+waitingQueue.length+", runningQueue:"+runningQueue.length); // log("pushed into running"); if (request.cb) { cb = request.cb; } // program to run var post_data = querystring.stringify({ 'name': request.name, 'cod...
javascript
{ "resource": "" }
q9962
classCase
train
function classCase(input) { return input.toUpperCase().replace(/[\-\s](.)/g, function(match, group1) {
javascript
{ "resource": "" }
q9963
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof Base)){ return new Base(json); } // If the given
javascript
{ "resource": "" }
q9964
enter
train
function enter(path, state) { regex = state.opts.regex; if (!regex) { throw new TypeError("A regex option is required."); }
javascript
{ "resource": "" }
q9965
train
function(realm, key, ssl) { // Initialize with a specified realm, key, and a boolean indicating wther // SSL should be enabled or disabled. var scheme = 'https'; if (typeof ssl !== 'undefined' && !ssl) { scheme = 'http'; } var uri = scheme + '://api.fanout.io/realm/' + realm;
javascript
{ "resource": "" }
q9966
buildOrigin
train
function buildOrigin(src, href) { try { const url = new URL(src,
javascript
{ "resource": "" }
q9967
checkOlderIE
train
function checkOlderIE() { const ua = navigator.userAgent; const isIE = ua.indexOf('MSIE') !== -1 || ua.indexOf('Trident') !== -1; if (!isIE) { return false; } const version = ua.match(/(MSIE\s|Trident.*rv:)([\w.]+)/)[2];
javascript
{ "resource": "" }
q9968
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof AtomPerson)){ return new AtomPerson(json); } //
javascript
{ "resource": "" }
q9969
polygonToPSLG
train
function polygonToPSLG(loops, options) { if(!Array.isArray(loops)) { throw new Error('poly-to-pslg: Error, invalid polygon') } if(loops.length === 0) { return { points: [], edges: [] } } options = options || {} var nested = true if('nested' in options) { nested = !!options.n...
javascript
{ "resource": "" }
q9970
sourcemapify
train
function sourcemapify (browserify, options) { options = options || browserify._options || {}; function write (data) { if (options.base) { // Determine the relative path // from the bundle file's directory to the source file let base = path.resolve(process.cwd(), options.base); data.sour...
javascript
{ "resource": "" }
q9971
joinURL
train
function joinURL (urlA, urlB) { urlA = urlA || ""; urlB = urlB || ""; let endsWithASlash = urlA.substr(-1) === "/" || urlA.substr(-1) === "\\"; let startsWithASlash = urlB[0] === "/" || urlB[0] === "\\"; if
javascript
{ "resource": "" }
q9972
ToggleAnimation
train
function ToggleAnimation(target, animation) { var preset = { hide: { hide: 'hide', focus: 'show', restore: 'show', blur: 'hide' }, scale: { hide: 'minimize', focus: 'focus', restore: 'restore', } }; this._preset = preset[animation]; this._target
javascript
{ "resource": "" }
q9973
togglify
train
function togglify(win, opts) { // extend options for toggle window opts = oassign({ animation: 'hide' }, opts); win._toggleAction = new ToggleAnimation(win, opts.animation); // patch toggle function to window win.toggle = function () { if (this.isVisible() && this.isFocused()) { this._toggleAction.hide()...
javascript
{ "resource": "" }
q9974
train
function(json){ // Protect against forgetting the new keyword when calling the constructor if(!(this instanceof SourceCitation)){ return new SourceCitation(json); } // If the given object is
javascript
{ "resource": "" }
q9975
wrapper
train
function wrapper(matcherName, legacyMatcher){ return function(util, customEqualityTesters){ return { compare: function(actual, expected){ var scope = {actual: actual}, message, result; result = legacyMatcher.call(scope, expected)
javascript
{ "resource": "" }
q9976
applySuperMethod
train
function applySuperMethod (fn, sup) { return function () { var prev, result; prev = this.sup; this.sup = sup; result = fn.apply(this, arguments); this.sup = prev;
javascript
{ "resource": "" }
q9977
parseCommandLine
train
function parseCommandLine(args) { var parsed_cmds = []; if (args.length <= 2) { parsed_cmds.push(defaultCommand()); } else { var cli = args.slice(2); var pos = 0; var cmd; cli.forEach(function(element, index, array) { //replace alias name with real n...
javascript
{ "resource": "" }
q9978
defaultCommand
train
function defaultCommand() { if (keys.length <= 0) { throw new Error("Error: there is no command at all!"); }; for (var p in commands) { if (commands[p]["default"]) { return commands[p]; };
javascript
{ "resource": "" }
q9979
Entry
train
function Entry(key, val, index) { this.key
javascript
{ "resource": "" }
q9980
train
function (key, val) { var entry = this._byKey.get(key); // reuse entry if the key exists if (entry) { this._touch(entry); entry.val = val; return; } entry =
javascript
{ "resource": "" }
q9981
train
function (key) { var entry = this._byKey.del(key); if (!entry) return; delete this._byOrder[entry.index]; this._len--; if (this._len === 0) { this._head = this._tail = 0; } else { // update most index if it was most lecently used entry
javascript
{ "resource": "" }
q9982
train
function (key) { var entry = this._byKey.get(key);
javascript
{ "resource": "" }
q9983
train
function (max) { if (typeof max !== 'number') return this._max; if (max < 1) throw new TypeError('max should be a positive number');
javascript
{ "resource": "" }
q9984
train
function () { var count = 0 , tail = this._tail , head = this._head , keys = new Array(this._len); for (var i = tail; i < head; i++) {
javascript
{ "resource": "" }
q9985
train
function (entry) { // update most number to key if (entry.index !== this._head - 1) { var isTail = entry.index === this._tail; delete this._byOrder[entry.index];
javascript
{ "resource": "" }
q9986
train
function () { var tail = this._tail , head = this._head; for (var i = tail; i < head; i++) { var entry = this._byOrder[i];
javascript
{ "resource": "" }
q9987
train
function () { var tail = this._tail , head = this._head; for (var i = head - 1; i >= tail; i--) { var headEntry = this._byOrder[i];
javascript
{ "resource": "" }
q9988
generateMachineKey
train
async function generateMachineKey () { let parts = await Promise.all([ randomHex(8), randomHex(4), randomHex(4), randomHex(4), randomHex(12) ])
javascript
{ "resource": "" }
q9989
train
function() { if (typeof window.Worker === 'undefined' || typeof window.URL === 'undefined') { return false; } try { /* eslint-disable no-new */ new Worker(window.URL.createObjectURL(
javascript
{ "resource": "" }
q9990
train
function(buffer, callback) { if (supportsWorkers) { // We have a worker queue, push an item into it and start processing workerQueue.push({ buffer: buffer, callback: callback }); nextMd5Task(); } else { // We don't have any Web Worker support,
javascript
{ "resource": "" }
q9991
train
function(key, data) { var shaObj = new Sha('SHA-256', 'TEXT');
javascript
{ "resource": "" }
q9992
train
function(buffer, callback, options) { if (options && options.type === 'url') { readers.getContentsFromUrl(buffer, function(err, data) { if (err) { return callback(err); } module.exports.md5(data, callback, { binary: true }); ...
javascript
{ "resource": "" }
q9993
template
train
function template(pattern) { return app.src(pattern, { cwd: path.join(__dirname, 'templates') }) .pipe(app.renderFile('*')).on('error', console.error)
javascript
{ "resource": "" }
q9994
$$safeEvalFn
train
function $$safeEvalFn(str) { let keyStr = ''; // Perform any parsing that needs to be performed on the scope value for (let key in this) { let val = this[ key ]; if (!val && val !== 0 && val !== '') { continue; } else if ( typeof val === 'symbol' || ...
javascript
{ "resource": "" }
q9995
train
function(callback){ var msg = ubeacon.getCommandString( false, ubeacon.uartCmd.led, new Buffer('03','hex') , false );
javascript
{ "resource": "" }
q9996
train
function(org) { var url = decodeURIComponent(org.toString()); urlOutput.empty().attr('href', url); url = url.replace(/.*?\/users\//g, '/users/'); url = url.replace(/Token=(.{10}).*/g, 'Token=$1...'); var parts = url.split('?'), param; var params = parts[1].replace(/t\[\...
javascript
{ "resource": "" }
q9997
train
function(err, imageIdentifier, res) { // Remove progress bar bar.css('width', '100%'); progress.animate({ opacity: 0}, { duration: 1000, complete: function() { $(this).remove(); } }); // Check for any XHR errors (200 means imag...
javascript
{ "resource": "" }
q9998
train
function(data, callback) { var set = _assembleTask(data, workFlow[meth][url].merg); if (set.err) throw new Error('Invalid workflow: ' + set.tasks); async.series(set.tasks, function(err, results)
javascript
{ "resource": "" }
q9999
render
train
function render(view, options) { var self = this; options = options || {}; for (var name in settings._filters) { options[name] = settings._filters[name]; } if (settings.helpers) { for (var k in settings.helpers) { var helper = settings.helpers[k]; if (typeof helper === 'function') { ...
javascript
{ "resource": "" }