_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
language
stringclasses
1 value
meta_information
dict
q12000
buildServer
train
function buildServer() { console.log(); console.log(`${chalk.cyan('SERVER-SIDE')}`); console.log('==========================================================='); fs.emptyDirSync(paths.appServerBuild); console.log('Creating a server-side production build...'); let compiler = webpack(serverlize(paths, config)...
javascript
{ "resource": "" }
q12001
rebuildAttribute
train
function rebuildAttribute (attrib, data, itemSize) { if (attrib.itemSize !== itemSize) return true if (!attrib.array) return true var attribLength = attrib.array.length if (Array.isArray(data) && Array.isArray(data[0])) { // [ [ x, y, z ]
javascript
{ "resource": "" }
q12002
bridge
train
function bridge(destination, options) { return transformer function transformer(node, file, next) { destination.run(mdast2hast(node, options),
javascript
{ "resource": "" }
q12003
drawDonutHole
train
function drawDonutHole(layer) { if (options.series.pie.innerRadius > 0) { // subtract the center layer.save(); var innerRadius = options.series.pie.innerRadius > 1 ? options.series.pie.innerRadius : maxRadius * options.series.pie.innerRadius; layer.globalCompositeOperation = "destination-out"; // t...
javascript
{ "resource": "" }
q12004
makeUtcWrapper
train
function makeUtcWrapper(d) { function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) { sourceObj[sourceMethod] = function() { return targetObj[targetMethod].apply(targetObj, arguments); }; }; var utc = { date: d }; // support strftime, if found if (d.strftime != undefined)...
javascript
{ "resource": "" }
q12005
dateGenerator
train
function dateGenerator(ts, opts) { if (opts.timezone == "browser") { return new Date(ts); } else if (!opts.timezone || opts.timezone == "utc") { return makeUtcWrapper(new Date(ts)); } else if (typeof timezoneJS != "undefined" && typeof timezoneJS.Date != "undefined") { var d = new timezoneJS.Date();
javascript
{ "resource": "" }
q12006
processOptions
train
function processOptions(plot, options) { if (options.series.curvedLines.active) {
javascript
{ "resource": "" }
q12007
processDatapoints
train
function processDatapoints(plot, series, datapoints) { var nrPoints = datapoints.points.length / datapoints.pointsize; var EPSILON = 0.005; //detects missplaced legacy parameters (prior v1.x.x) in the options object //this can happen if somebody upgrades to v1.x.x without adjusting the parameters or uses o...
javascript
{ "resource": "" }
q12008
train
function(apiKey) { return function(path, data, done) { var url = apiBase + path + '?' + querystring.stringify(_.extend({ 'key': apiKey }, data));
javascript
{ "resource": "" }
q12009
buffer
train
function buffer(arr) { if (!Array.isArray(arr)) { return; } var l = new List(); arr.forEach(function(el) {
javascript
{ "resource": "" }
q12010
map
train
function map(arr) { var hm = new HashMap(); Object.keys(arr).forEach(function(k) {
javascript
{ "resource": "" }
q12011
svgUrl
train
function svgUrl(name, collection) { for (var i = 0, result; i < COLLECTION_FILTERS.length; i++) { if (COLLECTION_FILTERS[i][0].test(collection)) { result = COLLECTION_FILTERS[i][1]; collection = _.isFunction(result)? result(collection) : result;
javascript
{ "resource": "" }
q12012
createGlyph
train
function createGlyph(name, collection, id, colors, fileFormat) { var glyph = Object.create(Glyph); if (!colors) colors = { 'black': 'rgb(0,0,0)' }; if (!fileFormat) fileFormat = "{0}-{1}-{2}.svg"; if (!id) id = name; glyph.id = id; glyph.name =
javascript
{ "resource": "" }
q12013
glyphCreator
train
function glyphCreator() { var unique = nodupes(); return function(name,
javascript
{ "resource": "" }
q12014
allGlyphs
train
function allGlyphs(rawGlyphs, colors, fileFormat) { var unique = nodupes(); rawGlyphs = fixNames(rawGlyphs); return rawGlyphs.map(function(rawGlyph)
javascript
{ "resource": "" }
q12015
missingGlyphs
train
function missingGlyphs(glyphs, svgDir, cb) { async.reject(glyphs, function(glyph, cb) { var filenames = glyph.filenames().map(function(filename) {
javascript
{ "resource": "" }
q12016
BigNumber
train
function BigNumber(initialNumber) { var index; if (!(this instanceof BigNumber)) { return new BigNumber(initialNumber); } this.number = []; this.sign = 1; this.rest = 0; // The initial number can be an array, string, number of another big number ...
javascript
{ "resource": "" }
q12017
train
function(viewClass) { var t = this, newIdNum = 1, components = t.get('components'), classParts = viewClass.split('.'), appName = classParts[0], appView = classParts[1]; // Instantiate and add the component var component = new Component({ id: M...
javascript
{ "resource": "" }
q12018
train
function(options) { var t = this, opts = _.extend({trim:true, deep:true}, options),
javascript
{ "resource": "" }
q12019
train
function() { var t = this; t.$el.append(template.apply({})); t.editor = t.$('.nm-cs-source-edit'); t.sourceButton = t.$('.nm-cs-view-source'); // Get bindings to 'name=' attributes before custom views
javascript
{ "resource": "" }
q12020
train
function(model, componentView, customView) { var t = this, componentPane = t.$('.nm-cs-component'); // Remember the model state on entry t.model = model; t.componentView = componentView; t.monitor = model.get('monitor'); t.originalModel = t.model.toJSON({trim:false}); ...
javascript
{ "resource": "" }
q12021
train
function(e) { var t = this; // Make view options changes immediately on keydown // Note: Don't be so aggressive with monitor initParams, because that // could result in backend round-trips for each keystroke.
javascript
{ "resource": "" }
q12022
train
function() { var t = this; // Add the component to the model, then to the page view var copy = t.model.toJSON(); delete copy.id; var component = t.pageView.model.addComponent(copy.viewClass); component.set(copy); // Position the component on top left var cv = t.pageView...
javascript
{ "resource": "" }
q12023
train
function(dirpath, file) { var templateFile = Path.join(__dirname, '../template/app', dirpath, file), outputFile = Path.join(appPath, dirpath, file); try { var template = new Template({text: FS.readFileSync(templateFile).toString(),
javascript
{ "resource": "" }
q12024
train
function(dirpath) { try { // Make the directory under the app if (dirpath !== '/') { FS.mkdirSync(Path.join('.', appPath, dirpath)); } // Read the template directory var templateDir = Path.join(__dirname, '../template/app', dirpath); var files = FS.readdirSync(templateD...
javascript
{ "resource": "" }
q12025
buildClasses
train
function buildClasses (db) { const classes = data.findClasses(db).order('name') return classes.map(function (klass) { const fns = data .findChildFunctions(db, [klass])
javascript
{ "resource": "" }
q12026
train
function() { var t = this; if (t.dirWatcher) { t.dirWatcher.close(); t.dirWatcher = null; } for (var pageId
javascript
{ "resource": "" }
q12027
train
function(dirs, callback) { var t = this, numLeft = dirs.length, fileRegexp = /.json$/, trimmed = []; // Already trimmed if (numLeft === 0) { return callback(null, dirs); } // Process each directory dirs.forEach(function(dir) { t.hasCont...
javascript
{ "resource": "" }
q12028
train
function(dirname, fileRegexp, callback) { var t = this; // Get the directory at this level FS.readdir(dirname, function(error, fileNames) { // Process errors if (error) { console.error('Read dir error', error); return callback(error); } // Process...
javascript
{ "resource": "" }
q12029
train
function(fileNames, callback) { var t = this, stats = [], didError = false, numLeft = fileNames.length; // No files to process if (fileNames.length === 0) { return callback(null, stats); } // Call stat on each file fileNames.forEach(function(fi...
javascript
{ "resource": "" }
q12030
train
function() { var t = this, branches = t.model.get('branches'), leaves = t.model.get('leaves'), hash = ""; // The hash is the text of the branches & leaves branches && branches.forEach(function(node) { var label = node.get('label') || node.id, descript...
javascript
{ "resource": "" }
q12031
train
function() { var t = this, branches = t.model.get('branches'), leaves = t.model.get('leaves'); // Determine if we should connect a monitor to this node // // Connect a monitor if: // * There isn't one already connected, and // * There's a monitor definition avail...
javascript
{ "resource": "" }
q12032
train
function() { var t = this, json = t.model.toJSON({trim:false});
javascript
{ "resource": "" }
q12033
train
function(params, options) { var t = this, port = t.get('port'), server = t.get('server'), templates = t.get('templates'), siteDbPath = t.get('siteDbPath'), parentPath = siteDbPath.indexOf('.') === 0 ? process.cwd() : ''; // Distribute the site path to probe...
javascript
{ "resource": "" }
q12034
train
function(request, response, next) { var t = this; // URL rewrites var url = URL.resolve('', request.url); if (url === '/favicon.ico') { var faviconUrl = t.site.get('favicon'); url = request.url = faviconUrl || request.url; } // Remove the leading slash for page mani...
javascript
{ "resource": "" }
q12035
train
function(request, response, next) { var t = this, url = request.url, searchStart = url.indexOf('?'), templates = t.get('templates'); // Remove any URL params if (searchStart > 0) { url = url.substr(0, searchStart); } // Get the page model t._ge...
javascript
{ "resource": "" }
q12036
train
function(url, callback) { var t = this, originalUrl = url, page = null; // Change urls that end in / to /index if (url.substr(-1) === '/') { url = url + 'index'; } // Return if it's in cache page = pageCache.get(url); if (page) { return cal...
javascript
{ "resource": "" }
q12037
train
function(callback) { callback = callback || function(){}; var t = this, server = t.get('server'), port = t.get('port'), allowExternalConnections = t.get('allowExternalConnections'); // Allow connections from INADDR_ANY or LOCALHOST only var host = allowExternalConn...
javascript
{ "resource": "" }
q12038
train
function() { var t = this; // Test an app directory to see if it's a monitor app var testAppDir = function(dir) { // Load the package.json if it exists (and remove relative refs) var pkg; dir = Path.resolve(dir); try { pkg = JSON.parse(FS.readFileSync(dir + ...
javascript
{ "resource": "" }
q12039
train
function(dir) { // Load the package.json if it exists (and remove relative refs) var pkg; dir = Path.resolve(dir); try { pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8')); } catch (e) { // Report an error if the package.json has a parse proble...
javascript
{ "resource": "" }
q12040
train
function(dir) { // Return if the node_modules directory doesn't exist. try { FS.statSync(dir); } catch (e) {return;} // Check each direcory for a monitor-dashboard app FS.readdirSync(dir).forEach(function(moduleName) {
javascript
{ "resource": "" }
q12041
train
function(callback) { var t = this, server = t.get('server'); callback = callback || function(){}; // Unwatch all template files t.get('templates').forEach(function(template) { template.unWatchFile(); }); // Don't stop more than once.
javascript
{ "resource": "" }
q12042
train
function() { var t = this; t.$el.append(template.apply({})); t.dialog = t.$('.modal'); // Build the tour tree view t.tv = new UI.TreeView({ preFetch: true, monitorParams: {probeClass: 'ToursProbe'} }); t.tv.render().appendTo(t.$('.nm-tsv-tree')); // Sele...
javascript
{ "resource": "" }
q12043
train
function(e) { var t = this, item = $(e.currentTarget),
javascript
{ "resource": "" }
q12044
train
function() { var t = this; // Set the current tour pages t.pages = t.tour.get('pages'); // Tour fields t.$('.nm-tsv-id').val(t.tour.get('id')); t.$('.nm-tsv-title').val(t.tour.get('title')); t.$('.nm-tsv-description').val(t.tour.get('description')); t.$('.nm-tsv-auto-ne...
javascript
{ "resource": "" }
q12045
train
function() { var t = this; // Show the modal dialog t.dialog.centerBox().css({top:40}).modal('show'); // Set the cursor when the dialog fades in
javascript
{ "resource": "" }
q12046
train
function() { var t = this; for (var i in t.tv.orderedNodes) { var node = t.tv.orderedNodes[i];
javascript
{ "resource": "" }
q12047
train
function(e) { var t = this; // Scrape the form var params = { title: t.$('.nm-tsv-title').val(), description: t.$('.nm-tsv-description').val(), autoNextSec: t.$('.nm-tsv-auto-next-sec').val() }; if (!parseInt(params.autoNextSec)) { // Assure blank, NaN, un...
javascript
{ "resource": "" }
q12048
train
function() { var t = this, modal = t.newTourPage.$('.modal'); UI.hideToolTips(); modal.centerBox().css({top:20, left:modal.css('left').replace(/px/,'')
javascript
{ "resource": "" }
q12049
train
function(page) { var t = this, newPages = t.pages.slice(0); newPages.push(page); t.tour.set('pages', newPages);
javascript
{ "resource": "" }
q12050
setAttr
train
function setAttr(setModel, newValue, setOptions) { var oldValue = model._containedModels[attrName]; // Pass through if removing if (newValue === undefined || newValue === null) { model._containedModels[attrName] = newValue; return; } // Is the new value the correct type? ...
javascript
{ "resource": "" }
q12051
train
function(params, options) { var t = this; // If raw text was sent to the template, compile and return if (t.get('text')) { t.compile(); return; } // Watch for changes in the text element t.on('change:text', t.compile, t); // Process a file template var ...
javascript
{ "resource": "" }
q12052
train
function() { var t = this, path = t.get('path'); t.watcher = FileProbe.watchLoad(path, {persistent: true}, function(error, content) {
javascript
{ "resource": "" }
q12053
train
function(params) { var t = this, text = t.get('text'), compiled = t.get('compiled'); // Convert parameters to JS object if they're a backbone model if (params instanceof Backbone.Model) { params = params.toJSON(); } // Compile the template if necessary
javascript
{ "resource": "" }
q12054
train
function() { var t = this, text = t.get('text'); var compiled
javascript
{ "resource": "" }
q12055
train
function() { var styles = {}, viewOptions = component.get('viewOptions'), title = viewOptions.get('title') || '', background = viewOptions.get('background'), css = component.get('css'); for (var selector in css) { styles['#' + component.id + ' ' ...
javascript
{ "resource": "" }
q12056
train
function() { // Don't continue if the probe portion was what changed. var thisMonitor = JSON.stringify(monitor.toMonitorJSON()); if (thisMonitor === t.priorMonitor) { return; } // Remove the component listeners log.info('render.monitorChange', t.logCtxt); ...
javascript
{ "resource": "" }
q12057
train
function() { var t = this; UI.hideToolTips(); UI.pageView.model.get('components').remove(t.model);
javascript
{ "resource": "" }
q12058
train
function(connect, callback) { callback = callback || function(){}; var t = this, needsConnecting = false, logMethod = (connect ? 'connectMonitor' : 'disconnectMonitor'), originalParams = null, monitor = t.model.get('monitor'), isConnected = monitor.isConnect...
javascript
{ "resource": "" }
q12059
train
function(e) { var t = this; UI.pauseTour(); // Set the component model into the settings view settingsView.setModel(t.model, t, t.viewClass['SettingsView']); // Center and show the settings $('#nm-cv-settings').centerBox().css({top:40}).modal('show'); e.stopPropagation();
javascript
{ "resource": "" }
q12060
train
function() { var t = this, pageView = UI.pageView, pageModel = pageView.model, view = t.view, getMonitor = function(id) {return pageView.getMonitor(id);}, monitor = t.model.get('monitor'); // Execute the onInit try {
javascript
{ "resource": "" }
q12061
train
function(persist) { var t = this, viewElem = t.$('.nm-cv'), thisZIndex = (viewElem.css('zIndex') === 'auto' ? 0 : +viewElem.css('zIndex')), components = UI.pageView.model.get('components'), maxZIndex = 0; // Get the maximum z-index (disregarding this) component...
javascript
{ "resource": "" }
q12062
train
function() { var t = this, viewElem = t.$('.nm-cv'), width = viewElem.outerWidth() + 10; // Change the model CSS. var css = _.clone(t.model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || '');
javascript
{ "resource": "" }
q12063
train
function() { var t = this; t.saveChanges(); // Open the new component dialog if no components exist
javascript
{ "resource": "" }
q12064
train
function() { var t = this; if (window.confirm('Are you sure you want to permanently delete this page?')) { t.pageView.exiting = true;
javascript
{ "resource": "" }
q12065
train
function(e) { var t = this, item = $(e.currentTarget), id = item.attr('data-id'), path = item.attr('data-path'); // Process a tour selection if ($(e.currentTarget).parents('.nm-sb-tours').length) {
javascript
{ "resource": "" }
q12066
train
function(e) { var t = this; UI.hideToolTips(); UI.pauseTour(); // Tell the settings it's about to be shown UI.pageView.$('#nm-pv-new').centerBox().css({top:100}).modal('show');
javascript
{ "resource": "" }
q12067
train
function(e) { var t = this; UI.hideToolTips(); UI.pauseTour(); // Tell the settings it's about to be shown t.tourSettingsView.show();
javascript
{ "resource": "" }
q12068
train
function(e) { var t = this, sidebar = $('.nm-sb'), newWidth = startWidth = sidebar.width(), startX = e.pageX; function drag(e) { newWidth = startWidth + (e.pageX - startX); sidebar.css({width:newWidth}); t.tour.css({left: newWidth + t.handleWidth}); ...
javascript
{ "resource": "" }
q12069
train
function() { var t = this, sbJSON = t.sidebar.toJSON({deep:true, trim:true}); // Function to trim closed sub-branches from a tree var trimSubBranch = function(tree) { var branches = tree.branches; for (var i in branches) { var subTree = branches[i]; if (s...
javascript
{ "resource": "" }
q12070
train
function(tree) { var branches = tree.branches; for (var i in branches) { var subTree = branches[i]; if (subTree.isOpen && !subTree.isLoading) {
javascript
{ "resource": "" }
q12071
train
function(size) { var t = this, css = _.clone(t.get('css')), parsedCss = $.parseStyleString(css['.nm-cv-viewport'] || ''); if (!parsedCss.height && !parsedCss.width) { parsedCss.height = size.height + 'px';
javascript
{ "resource": "" }
q12072
train
function(options) { var t = this, opts = _.extend({trim:true, deep:true, monitorOnly:true}, options), raw = Backbone.Model.prototype.toJSON.call(t, opts); // Keep only the monitor portion (strip the probe portion)?
javascript
{ "resource": "" }
q12073
train
function(e) { var code = e.keyCode; // Hotkeys while a tour is present if (UI.pageView.tourView) { // 1-9 direct page navigation var target; if (code >= 49 && code <=57) { target = $('.nm-tv-page[data-index="' + (code - 49) + '"]'); } // Pause / Run ...
javascript
{ "resource": "" }
q12074
train
function(e) { var t = this, box = t.getComponentArea(), sidebarWidth = t.sidebar.width(), canvasWidth = t.$el.width() - sidebarWidth, canvasCenter = canvasWidth / 2; // No components if (!box.width) {return;} // Obtain the center point, and offset the ca...
javascript
{ "resource": "" }
q12075
train
function() { var t = this, box = t.getComponentArea(); // Shift all components by the furthest left if (box.left) { t.$('.nm-pv-component').each(function() { var elem = $(this).find('.nm-cv'), left = (parseInt(elem.css('left'), 10)),
javascript
{ "resource": "" }
q12076
train
function(model) { var t = this, componentView = new ComponentView({model: model}); componentView.$el .addClass('nm-pv-component') .data('view', componentView); componentView.render();
javascript
{ "resource": "" }
q12077
train
function() { var t = this, components = t.model.get('components'), canvas = t.$('.nm-pv-canvas'); // Remove components not in the data model canvas.find('.nm-pv-component').each(function() { var component = $(this); if (!components.get(component.attr('id'))) { ...
javascript
{ "resource": "" }
q12078
train
function() { var t = this, pageView = t, getMonitor = function(id){return t.getMonitor(id);}; pageModel = t.model; // Execute the onInit try { eval(t.model.get('onInit')); } catch (e) {
javascript
{ "resource": "" }
q12079
train
function() { var t = this, raw = t.model.toJSON({trim:false});
javascript
{ "resource": "" }
q12080
train
function(isDirty) { var t = this; // Pause a tour if the page turns dirty if (isDirty) { UI.pauseTour(); } // Change the view
javascript
{ "resource": "" }
q12081
train
function() { // Remember the current page state var t = this; t.pageSettingsView.originalModel = t.model.toJSON({trim:false});
javascript
{ "resource": "" }
q12082
train
function() { var t = this, components = t.model.get('components');
javascript
{ "resource": "" }
q12083
train
function(id) { var t = this, components
javascript
{ "resource": "" }
q12084
train
function(id) { var t = this; // Is there a tour running already? if (t.tourView) { t.tourView.stop(); } // Load the Tour and start it var tour = new UI.Tour({id:id}); tour.fetch(function(err){ if (err) { alert("Error: Cannot open tour id: " + id); ...
javascript
{ "resource": "" }
q12085
train
function() { var t = this, isEditMode = t.$el.hasClass('edit-mode'), text = isEditMode ? 'Lock Components' : 'Edit Components', icon = isEditMode ? 'lock'
javascript
{ "resource": "" }
q12086
train
function() { var t = this; // Show if loaded if (aboutTemplate) { return t.showDialog('#nm-pv-about'); } UI.loadTemplate('', 'About', function(error, template)
javascript
{ "resource": "" }
q12087
train
function() { var t = this; UI.hideToolTips(); t.leftJustify(); t.centerPage(); t.model.save(function(error){ if (error) {
javascript
{ "resource": "" }
q12088
train
function() { var t = this; t.$el.html(''); // Output the heading if specified if (t.options.heading) { $(t.template.heading({value:t.options.heading})).appendTo(t.$el); } // If a non-object, just print it t.json = t.isBackbone ? t.model.toJSON() : t.model; if (t...
javascript
{ "resource": "" }
q12089
train
function(elemName) { var t = this; if (t.isBackbone) { return t.model instanceof Backbone.Collection ? t.model.at(elemName)
javascript
{ "resource": "" }
q12090
train
function(elem) { var t = this, strValue; // Catch recursive stringify try {strValue = JSON.stringify(elem.value);} catch (e) {strValue = "{object}";} // Set if the value changed if (strValue !== elem.strValue) { var priorStrValue = elem.strValue; elem.strV...
javascript
{ "resource": "" }
q12091
train
function() { // Compute the amount of play left to go t.playLeft = t.playEnd - Date.now(); // Done playing
javascript
{ "resource": "" }
q12092
train
function(e) { var t = this, target = $(e.currentTarget), index = target.attr('data-index'); // Save the index. If a tour has many instances of the // same page, it needs
javascript
{ "resource": "" }
q12093
train
function(options) { var t = this; t.options = options; t.monitor = options.monitor; // Call this to set the initial height/width to something // other than the size of the inner view elements. options.component.setDefaultSize({ width: 400, height: 300 }); ...
javascript
{ "resource": "" }
q12094
train
function() { var t = this; // Append a monitor picker t.monitorPicker = new UI.MonitorPicker({ el: t.$el, hideProbe: true,
javascript
{ "resource": "" }
q12095
train
function() { var t = this, map = {}, router = Monitor.getRouter(), hostName = Monitor.getRouter().getHostName(), appName = Monitor.Config.Monitor.appName, appInstance = process.env.NODE_APP_INSTANCE; // Add this process to the map map[hostName] = {}; ...
javascript
{ "resource": "" }
q12096
Flint
train
function Flint(options) { EventEmitter.call(this); this.id = options.id || u.genUUID64(); /** * Options Object * * @memberof Flint * @instance * @namespace options * @property {string} token - Spark Token. * @property {string} webhookUrl - URL that is used for SPark API to send callbacks. ...
javascript
{ "resource": "" }
q12097
runActions
train
function runActions(matched, bot, trigger, id) { // process preference logic if(matched.length > 1) { matched = _.sortBy(matched, match => match.preference); var prefLow = matched[0].preference; var prefHigh = matched[matched.length - 1].preference; i...
javascript
{ "resource": "" }
q12098
markdownFormat
train
function markdownFormat(str) { // if string... if(str && typeof str === 'string') { // process characters that do not render visibly in markdown
javascript
{ "resource": "" }
q12099
Bot
train
function Bot(flint) { EventEmitter.call(this); this.id = u.genUUID64(); this.flint = flint; this.options = flint.options; this.debug = function(message) { message = util.format.apply(null, Array.prototype.slice.call(arguments)); if(typeof flint.debugger === 'function') { flint.debugger(messa...
javascript
{ "resource": "" }