_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
language
stringclasses
1 value
meta_information
dict
q32000
date
train
function date(value) { var parsedDate = Date.parse(value); // couldn't parse it if (typeOf(parsedDate) != 'number') { return throwModifierError('date',
javascript
{ "resource": "" }
q32001
float
train
function float(value) { var parsedFloat = Number.parseFloat(value); // couldn't parse it if (typeOf(parsedFloat) != 'number') {
javascript
{ "resource": "" }
q32002
favicoIntegration
train
function favicoIntegration(options = defaultFavicoOptions) { // Create a new Favico integration. // Initially this was going to be a singleton object, but I realized there // may be cases where you want several different types of notifications. // The middleware does not yet support multiple instances, but it s...
javascript
{ "resource": "" }
q32003
parseTokens
train
function parseTokens(entry, env) { var found = 0; if (entry.indexOf('${') > -1) { entry = entry.replace(/\$\{([^}]+)\}/g, function(match, token) { var value = getVar.call(this, token, env); // need to have `found` counter // to see if any of the variables // in the
javascript
{ "resource": "" }
q32004
globs
train
function globs(sourcePath, ignore, commands, done) { var expression = /\$g\[(.+?)\]/g; var result = []; each(commands, function(command, next) { var map = {}; var match; var matches = []; while ((match = expression.exec(command))) matches.push(match); each(matches, function(patternMatch, next)...
javascript
{ "resource": "" }
q32005
loadConfig
train
function loadConfig(done) { fs.stat('package.json', function(err) { if (err) return done(undefined, {}); fs.readFile('package.json', function(err, contents) { if (err) return done(err);
javascript
{ "resource": "" }
q32006
loadOptions
train
function loadOptions(entries) { var options = new Command().version(require('../../package').version);
javascript
{ "resource": "" }
q32007
variables
train
function variables(root, config, done) { var expression = /\$v\[(.+?)\]/g; each(Object.keys(root), function(key, next) { var value = root[key]; if (typeof value === 'object') return variables(value, config, next); if (typeof value !== 'string') return next();
javascript
{ "resource": "" }
q32008
Observable
train
function Observable (subject, parent, prefix) { if ('object' != typeof subject) throw new TypeError('object expected. got: ' + typeof subject); if (!(this instanceof Observable)) return new Observable(subject, parent, prefix);
javascript
{ "resource": "" }
q32009
to64
train
function to64(index, count) { let result = ''; while (--count >= 0) { // Result char count. result += itoa64[index & 63]; // Get corresponding char.
javascript
{ "resource": "" }
q32010
getSalt
train
function getSalt(inputSalt) { let salt = ''; if (inputSalt) { // Remove $apr1$ token and extract salt. salt = inputSalt.split('$')[2]; } else { while(salt.length < 8) { // Random 8 chars. let
javascript
{ "resource": "" }
q32011
getPassword
train
function getPassword(final) { // Encrypted pass. let epass = ''; epass += to64((final.charCodeAt(0) << 16) | (final.charCodeAt(6) << 8) | final.charCodeAt(12), 4); epass += to64((final.charCodeAt(1) << 16) | (final.charCodeAt(7) << 8) | final.charCodeAt(13), 4); epass += to64((final.charCodeAt(2) <...
javascript
{ "resource": "" }
q32012
getElementTag
train
function getElementTag(node) { if (node.openingElement && t.isJSXIdentifier(node.openingElement.name)) {
javascript
{ "resource": "" }
q32013
transformSpecialAttribute
train
function transformSpecialAttribute(name, attribute) { if (t.isJSXExpressionContainer(attribute.value)) { let value = attribute.value.expression; switch (name) { case "ui5ControlData": renderer.renderControlData(value); break; ...
javascript
{ "resource": "" }
q32014
transformStyles
train
function transformStyles(value) { if (t.isStringLiteral(value)) { renderer.renderAttributeExpression("style", value); } else if (t.isJSXExpressionContainer(value)){
javascript
{ "resource": "" }
q32015
transformClasses
train
function transformClasses(value) { if (t.isStringLiteral(value)) { value.value.split(" ").forEach(function(cls) { renderer.addClass(cls); }); } else if (t.isJSXExpressionContainer(value)){
javascript
{ "resource": "" }
q32016
draw
train
function draw(c, frame) { const pixels = frame.data for (let y = 0; y < frame.height; y++) { for (let x = 0; x < frame.width; x++) { const color = pixels[x + y * frame.width] if (typeof color !== 'undefined') { let hex = color.toString(16) ...
javascript
{ "resource": "" }
q32017
taskNameFunc
train
function taskNameFunc() { var validParts = _.dropWhile(_.flatten([this.prefix,arguments]),function(item) { return !item;
javascript
{ "resource": "" }
q32018
sourceString
train
function sourceString(source) { var message = "<css input>" if (source) { if (source.input && source.input.file) { message = source.input.file }
javascript
{ "resource": "" }
q32019
scrollToBottom
train
function scrollToBottom(){ var it= jQuery('#testit'); var message= jQuery('#messages'); var newMessage= message.children('li:last-child') var clientH= it.prop('clientHeight'); var scrollTop=it.prop('scrollTop'); var scrollH=it.prop('scrollHeight'); var newMessageH=
javascript
{ "resource": "" }
q32020
train
function(res) { var author = _.get(res, 'envelope.user.id')
javascript
{ "resource": "" }
q32021
train
function(str) { var startsWith = !_.isNull(str.match(wOpsHeadRe))
javascript
{ "resource": "" }
q32022
train
function(str) { var startsWith = !_.isNull(str.match(sOpsHeadRe))
javascript
{ "resource": "" }
q32023
train
function(str) { var startsWith = !_.isNull(str.match(rOpsHeadRe))
javascript
{ "resource": "" }
q32024
train
function(str) { var startsWith = !_.isNull(str.match(pOpsHeadRe))
javascript
{ "resource": "" }
q32025
run
train
function run(commands, done) { var children = []; var pending = commands.length || 1; var err; each(commands, function(command, next) { children.push(childProcess.spawn(shell[0], [shell[1], command], { stdio: ['pipe', process.stdout, process.stderr] }).on('exit', function(code) { if (!err &&...
javascript
{ "resource": "" }
q32026
watch
train
function watch(sourcePath, patterns, commands) { var isBusy = false; var isPending = false; var runnable = function() { if (isBusy) return (isPending = true); isBusy = true; run(commands, function(err) { if (err) console.error(err.stack || err); isBusy = false; if (isPending) runnabl...
javascript
{ "resource": "" }
q32027
fail
train
function fail(status, description, response) { let body = status + ' ' + description; console.log(body); response.writeHead(status,
javascript
{ "resource": "" }
q32028
authorised
train
function authorised(request) { // JWT is usually passed via an HTTP header let token = request.headers.authorization; // For EventSource and WebSocket, JWT is passed as a URL parameter if (token === undefined) { let url = URL.parse(request.url, true); if (url.query)
javascript
{ "resource": "" }
q32029
ws_send
train
function ws_send(socket, data) { //console.log("send: " + data); let header; let payload = new Buffer.from(data); const len = payload.length; if (len <= 125) { header = new Buffer.alloc(2); header[1] = len; } else if (len <= 0xffff) { header = new Buffer.alloc(4); header[1] = 126; header[2] = (len >> ...
javascript
{ "resource": "" }
q32030
ws_receive
train
function ws_receive(raw) { let data = unpack(raw); // string to byte array let fin = (data[0] & 128) == 128; let opcode = data[0] & 15; let isMasked = (data[1] & 128) == 128; let dataLength = data[1] & 127; let start = 2; let length = data.length; let output = ""; if (dataLength == 126) star...
javascript
{ "resource": "" }
q32031
concat
train
function concat(divider, sourcePath, relativePaths, done) { var writeDivider = false; each(relativePaths, function(relativePath, next) { var absoluteSourcePath = path.resolve(sourcePath, relativePath);
javascript
{ "resource": "" }
q32032
train
function (path) { //There has to be an easier way to do this. var i, part, ary, firstChar = path.charAt(0); if (firstChar !== '/' && firstChar !== '\\' && path.indexOf(':') === -1) { ...
javascript
{ "resource": "" }
q32033
train
function(dest, source) { lang.eachProp(source, function (value, prop) { if (typeof value === 'object' && value && !lang.isArray(value) && !lang.isFunction(value) && !(value instanceof RegExp)) { if (!dest[prop]) { ...
javascript
{ "resource": "" }
q32034
SourceMap
train
function SourceMap(options) { options = defaults(options, { file : null, root : null, orig : null, orig_line_diff : 0, dest_line_diff : 0, }); var generator = new MOZ_SourceMap.SourceMapGenerator({ file : options.file, sourceRoot : options.root ...
javascript
{ "resource": "" }
q32035
can_mangle
train
function can_mangle(name) { if (unmangleable.indexOf(name) >= 0) return false; if (reserved.indexOf(name) >= 0) return false; if (options.only_cache) { return cache.props.has(name); }
javascript
{ "resource": "" }
q32036
traverse
train
function traverse(object, visitor) { var child; if (!object) { return; } if (visitor.call(null, object) === false) { return false; } for (var i = 0, keys = Object.keys(object); i < keys.length; i++) { child = object[keys[i]];
javascript
{ "resource": "" }
q32037
getValidDeps
train
function getValidDeps(node) { if (!node || node.type !== 'ArrayExpression' || !node.elements) { return; } var deps = []; node.elements.some(function (elem) { if (elem.type === 'Literal') {
javascript
{ "resource": "" }
q32038
train
function (obj, options, totalIndent) { var startBrace, endBrace, nextIndent, first = true, value = '', lineReturn = options.lineReturn, indent = options.indent, outDentRegExp = options.outDentRegExp, quote = opti...
javascript
{ "resource": "" }
q32039
addSemiColon
train
function addSemiColon(text, config) { if (config.skipSemiColonInsertion || endsWithSemiColonRegExp.test(text)) {
javascript
{ "resource": "" }
q32040
appendToFileContents
train
function appendToFileContents(fileContents, singleContents, path, config, module, sourceMapGenerator) { var refPath, sourceMapPath, resourcePath, pluginId, sourceMapLineNumber, lineCount, parts, i; if (sourceMapGenerator) { if (config.out) { refPath = config.baseUrl; ...
javascript
{ "resource": "" }
q32041
onError
train
function onError(error) { if (error.syscall !== 'listen') throw error; const bind = (typeof port === 'string') ? 'Pipe ' + port : 'Port ' + port; // handle specific listen errors with friendly messages switch (error.code) { case 'EACCES': console.error(bin...
javascript
{ "resource": "" }
q32042
addMultipartData
train
function addMultipartData (formData, data) { var key, arr, i; for (key in data) { if (data.hasOwnProperty(key) && key !== 'files') { if (data[key] instanceof Array) { arr = data[key]; for (i = 0; i < arr.length; i += 1) {
javascript
{ "resource": "" }
q32043
addFiles
train
function addFiles (formData, files) { var file, arr, key, i = 0, filename; for (key in files) { if (files.hasOwnProperty(key) && files[key]) { if (files[key] instanceof Array) { arr = files[key]; filename = getFilename(arr[i]) || null; for (...
javascript
{ "resource": "" }
q32044
wrap
train
function wrap (factory, node, tag) { // If there is a previous node that is not text, insert a new line to // for if (node.previousSibling != null && node.previousSibling.nodeType != 3)
javascript
{ "resource": "" }
q32045
text
train
function text (factory, node, cursor) { // Process a text node. var parentNode = node.parentNode; // If the node is CDATA convert it to text. if (node.nodeType == 4) { var text = factory.createTextNode(node.data); parentNode.insertBefore(text, node); parentNode.removeChild(node); ...
javascript
{ "resource": "" }
q32046
train
function (selector, context) { if (typeof selector === 'string') { if (context) { var cont; if (context.jquery) { cont = context[0]; if (!cont)
javascript
{ "resource": "" }
q32047
train
function (init) { var arr = []; if (!init) { arr.push('data'); } if (this.namespace.length > 0) {
javascript
{ "resource": "" }
q32048
train
function (dropdown, target, settings, position) { var sheet = Foundation.stylesheet, pip_offset_base = 8; if (dropdown.hasClass(settings.mega_class)) { pip_offset_base = position.left + (target.outerWidth() / 2) - 8; } else if (this.small()) { pip_offset_base += position.lef...
javascript
{ "resource": "" }
q32049
train
function (x1, y1, w, h, color, c) { _c = c || _c if (color) { _c.fillStyle = color }
javascript
{ "resource": "" }
q32050
train
function (x0, y0, radius, color, c) { _c = c || _c if (color) { _c.fillStyle = color } x0 *= _scale y0 *= _scale radius *= _scale let x = radius let y = 0 let decisionOver2 = 1 - x // Decision criterion divided by 2 evalua...
javascript
{ "resource": "" }
q32051
train
function (x0, y0, width, height, c) { _c = c || _c const data = _c.getImageData(x0, y0, width, height) const bits = data.data const pixels = [] for (let y = 0; y < height; y += _scale) { for (let x = 0; x < width; x += _scale) { ...
javascript
{ "resource": "" }
q32052
log
train
function log(arg) { var str = JSON.stringify(arg)
javascript
{ "resource": "" }
q32053
picker
train
function picker(iteratees) { iteratees = iteratees || ['name']
javascript
{ "resource": "" }
q32054
combineSplitters
train
function combineSplitters (splitters) { var l = splitters.length return function (str) { for (var i = 0; i < l; i++) {
javascript
{ "resource": "" }
q32055
reducePlugins
train
function reducePlugins (plugins) { var before = [] var split = [] var after = [] plugins.forEach(function (plugin) { if (plugin.before) before.push(plugin.before) if (plugin.split) split.push(plugin.split)
javascript
{ "resource": "" }
q32056
getSongArtistTitle
train
function getSongArtistTitle (str, options, plugins) { if (options) { if (options.defaultArtist) { plugins.push(fallBackToArtist(options.defaultArtist)) } if (options.defaultTitle) { plugins.push(fallBackToTitle(options.defaultTitle)) }
javascript
{ "resource": "" }
q32057
flatten
train
function flatten(test) { return { title: test.title,
javascript
{ "resource": "" }
q32058
BusinessRules
train
function BusinessRules(Data) { this.Data = Data; this.MainValidator = this.createMainValidator().CreateRule("Data");
javascript
{ "resource": "" }
q32059
clean
train
function clean(directoryPath, isRoot, done) { fs.stat(directoryPath, function(err, stat) { if (err) return done(isRoot ? undefined : err); if (stat.isFile()) return fs.unlink(directoryPath, done); fs.readdir(directoryPath, function(err, relativePaths) { if (err) return done(err); each(relative...
javascript
{ "resource": "" }
q32060
getDirective
train
function getDirective (options, name) { if (!options[name]) { return null; } if (typeof options[name] === 'string') { return name + ' ' + options[name]; } if (Array.isArray(options[name])) {
javascript
{ "resource": "" }
q32061
train
function (file_system) { if (file_system) { if (successCallback) { fileSystems.getFs(file_system.name, function (fs) { // This should happen only on platforms that haven't implemented requestAllFileSystems (windows) ...
javascript
{ "resource": "" }
q32062
PiGlow
train
function PiGlow() { var that = this; this._wire = null; this._currentState = null; Emitter.call(this);
javascript
{ "resource": "" }
q32063
buildErrorHandler
train
function buildErrorHandler(path) { return function(node, text) {
javascript
{ "resource": "" }
q32064
check_value
train
function check_value(val, min, max) { val = +val; if (typeof(val) != 'number' || val < min || val > max || Math.floor(val) !== val) {
javascript
{ "resource": "" }
q32065
check_bounds
train
function check_bounds(buf, offset, len) { if (offset < 0 ||
javascript
{ "resource": "" }
q32066
compareAst
train
function compareAst(actualSrc, expectedSrc, options) { var actualAst, expectedAst; options = options || {}; if (!options.comparators) { options.comparators = []; } /* * A collection of comparator functions that recognize equivalent nodes * that would otherwise be reported as unequal by simple object compar...
javascript
{ "resource": "" }
q32067
plugin
train
function plugin() { return function (files, metalsmith, done) { Object.keys(files).forEach(function (file) { setImmediate(done); var pathslash = process.platform === 'win32' ? '\\' : '/'; var rootPath = '';
javascript
{ "resource": "" }
q32068
getDetailedObjectType
train
function getDetailedObjectType(thing) { let prototype = Object.getPrototypeOf(thing) if (!prototype) return NO_PROTOTYPE
javascript
{ "resource": "" }
q32069
BusinessRules
train
function BusinessRules(Data) { this.Data = Data; this.InvoiceValidator =
javascript
{ "resource": "" }
q32070
train
function (args) { args.HasError = false; args.ErrorMessage = ""; if (this.Items !== undefined && this.Items.length === 0) {
javascript
{ "resource": "" }
q32071
createPiGlow
train
function createPiGlow(callback) { var myPiGlow = new PiGlowBackend(); var myInterface = piGlowInterface(myPiGlow); myPiGlow
javascript
{ "resource": "" }
q32072
calcSteps
train
function calcSteps (min, max, room, width) { var range = max - min var i = 0, e while(true) { var e = Math.pow(10, i++) if(e > 10000000000) throw new Error('oops') var re = range/e var space = width*1.25 if(room / (re) > space) return e
javascript
{ "resource": "" }
q32073
postQuery
train
function postQuery(statArr) { var options = { method: 'POST', baseUrl: this.NEO4J_BASEURL, url: this.NEO4J_ENDPT, headers: { 'Accept': 'application/json; charset=UTF-8', 'Content-type': 'application/json' }, json: { statements: statArr //
javascript
{ "resource": "" }
q32074
resolver
train
function resolver(obj) { return new Promise(function(resolve, reject)
javascript
{ "resource": "" }
q32075
processValue
train
function processValue(value) { if (isNaN(value)) return 0; value = Math.max(MIN_VALUE, Math.min(value, MAX_VALUE)); //value is between 0 and 1, thus is interpreted as percentage
javascript
{ "resource": "" }
q32076
train
function () { if (this.Data.ExcludedDays == undefined || this.Data.ExcludedDays.length == 0) return this.ExcludedWeekdays;
javascript
{ "resource": "" }
q32077
train
function (config, args) { var msg = config["Msg"]; var format = config["Format"]; if (format != undefined) { _.extend(args, { FormatedFrom: moment(args.From).format(format), FormatedTo: moment(args.To).f...
javascript
{ "resource": "" }
q32078
train
function (args) { args.HasError = false; args.ErrorMessage = ""; //no dates - > nothing to validate if (!_.isDate(this.From) || !_.isDate(this.To)) return; if (self.FromDatePart.isAfter(self.ToDatePart)) { ...
javascript
{ "resource": "" }
q32079
train
function (args) { args.HasError = false; args.ErrorMessage = ""; var greaterThanToday = new VacationApproval.FromToDateValidator(); greaterThanToday.FromOperator = 4 /* GreaterThanEqual */; greaterThanToday.From = new Date(); ...
javascript
{ "resource": "" }
q32080
onError
train
function onError (e) { switch (e.target.errorCode) { case 12: console.log('Error - Attempt to open db with a lower version than the ' + 'current one.'); break; default:
javascript
{ "resource": "" }
q32081
embed
train
function embed(sourcePath, relativePaths, name, done) { var items = ''; each(relativePaths, function(relativePath, next) { var fullPath = path.join(sourcePath, relativePath); fs.readFile(fullPath, 'utf8', function(err, text) { if (err) return next(err); items += ' $templateCache.put(\'' + ...
javascript
{ "resource": "" }
q32082
inline
train
function inline(text) { var result = ''; for (var i = 0; i < text.length; i += 1) { var value = text.charAt(i); if (value === '\'') result += '\\\''; else if (value === '\\') result += '\\\\'; else if (value === '\b') result += '\\b'; else if (value === '\f') result += '\\f'; else if (value ...
javascript
{ "resource": "" }
q32083
parseArray
train
function parseArray(str) { return R.filter(R.identity,
javascript
{ "resource": "" }
q32084
stringifyIndented
train
function stringifyIndented(value, chr, n) { return
javascript
{ "resource": "" }
q32085
train
function () { var done = this.async(); if(this.createMode) { // copy yoga-generator itself this.fs.copy(path.join(__dirname, '../'), this.destinationPath(), { globOptions: { dot: true, ignore: [ '**/.DS_Store', '**/.git', '**/.git/**...
javascript
{ "resource": "" }
q32086
parseManifest
train
function parseManifest(manifest, docroot, callback) { var inCache = false , lines = []; // get manifest file data fs.readFile(manifest, 'ascii', function(err, data) { var counter = 0; if (err) { // to prevent sudden continuation return callback(err); } ...
javascript
{ "resource": "" }
q32087
addWatcher
train
function addWatcher(file, handler, callback) { fs.stat(file, function(err, stat) {
javascript
{ "resource": "" }
q32088
watcher
train
function watcher(manifest) { return function(file) { return function(event) { if (event == 'change') { fs.stat(file, function(err, stat) { if (err) return; // do nothing at this point var mtime = stat.mtime.getTime();
javascript
{ "resource": "" }
q32089
Agent
train
function Agent (plugin) { var events = require('events') var util = require('util') var eventEmitter = new events.EventEmitter() var cluster = require('cluster') var workerId = 0 + '-' + process.pid // 0 == Master, default if (!cluster.isMaster) { workerId = cluster.worker.id + '-' + process.pid } v...
javascript
{ "resource": "" }
q32090
train
function (metric) { metric.workerId = workerId metric.pid = process.pid if (!metric.sct) { if (metric.name && /collectd/.test(metric.name)) { metric.sct = 'OS' } else { metric.sct = 'APP' } } if (!metric.ts) {
javascript
{ "resource": "" }
q32091
redirect
train
function redirect(id, prefix, suffix, res) { var validatedID = reelib.identifier.toIdentifierString(id); if(validatedID && (validatedID !== id)) {
javascript
{ "resource": "" }
q32092
main
train
function main(program) { program || (program = { args: [] }); if(program.args.length === 0) { program.outputHelp(); return process.exit(1); } return Promise .map(program.args, _.partial(exports.downloadPosting, program)) .map(function(html) {
javascript
{ "resource": "" }
q32093
mixAppend
train
function mixAppend(to) { var args = Array.prototype.slice.call(arguments) , i = 0 ; // it
javascript
{ "resource": "" }
q32094
train
function(rec, key) { return (function() { if (typeof key === "symbol") { return undefined; } if (key === scopeName) { return scope; } if (key === indicator) { return proxy; } if (key.sli...
javascript
{ "resource": "" }
q32095
prepareFunc
train
function prepareFunc(func, builder, basepath) { //Prepare an implied function for repeated use funcStringCache[func] = funcStringCache[func] || ('(function() { with (proxy(scope)) { return ('+func.toString()+')('+defaultScopeName+'); } })()'); return function(scope) { var scope = scope || {}; var builder =...
javascript
{ "resource": "" }
q32096
mixChain
train
function mixChain() { var args = Array.prototype.slice.call(arguments) , i = args.length ; while
javascript
{ "resource": "" }
q32097
train
function (remoteUrl) { if (remoteUrl.indexOf('http') !== 0) { grunt.log.error('Something seems wrong with this remote url: ' + remoteUrl); }
javascript
{ "resource": "" }
q32098
train
function (tplUrl, data) { if (urlPrefix) { tplUrl = urlPrefix + tplUrl; } if (urlSuffix) { tplUrl += urlSuffix; } var html = ''; debug(' retrieve remote content from ' + tplUrl); var remoteFragmentKey = getTemplateCacheKeyFromRemoteUrl(tplUrl); ...
javascript
{ "resource": "" }
q32099
train
function (tplName, data, ignoreEvaluation) { var files, templateData, html = ''; if (typeof data !== 'object') { ignoreEvaluation = data; data = {}; } data = _.extend({}, options.data, data); if (_.has(templates, tplName)) { debug(' include ' + templates[tp...
javascript
{ "resource": "" }