_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q24300
chunkArray
train
function chunkArray(myArray, chunk_size){ var results = []; while (myArray.length) { results.push(myArray.splice(0, chunk_size)); } return results; }
javascript
{ "resource": "" }
q24301
train
function() { var args = [], arg; arg = $(this.expression); while (arg) { args.push(arg); if (! $(',')) { break; } arg = $(this.expression); } return args; }
javascript
{ "resource": "" }
q24302
train
function() { var c = input.charCodeAt(i); if ((c > 57 || c < 45) || c === 47) return; var value = $(/^(-?\d*\.?\d+(?:[eE][-+]?\d+)?)(\%|\w+)?/); if (value) { return new tree.Dimension(value[1], value[2], memo, env.filename); } }
javascript
{ "resource": "" }
q24303
train
function() { var a, attachment, e, elements = [], f, filters = new tree.Filterset(), z, zooms = [], segments = 0, conditions = 0; while ( (e = $(this.element)) || (z = $(this.zoom)) || (f = $(this.filter)) || (a = $(this.attachment)) ) { segments++; if (e) { elements.push(e); } else if (z) { zooms.push(z); conditions++; } else if (f) { var err = filters.add(f); if (err) { util.error(env, { message: err, index: i - 1, filename: env.filename }); throw new Error('N/A'); } conditions++; } else if (attachment) { util.error(env, { message: 'Encountered second attachment name.\n', index: i - 1, filename: env.filename }); throw new Error('N/A'); } else { attachment = a; } var c = input.charAt(i); if (c === '{' || c === '}' || c === ';' || c === ',') { break; } } if (segments) { return new tree.Selector(filters, zooms, elements, attachment, conditions, memo); } }
javascript
{ "resource": "" }
q24304
train
function() { var m, a, op, operation; m = $(this.operand); if (m) { while ((op = ($('/') || $('*') || $('%'))) && (a = $(this.operand))) { operation = new tree.Operation(op, [operation || m, a], memo, env.filename); } return operation || m; } }
javascript
{ "resource": "" }
q24305
train
function() { var e, entities = []; e = $(this.addition); while (e || $(this.entity)) { entities.push(e); e = $(this.addition); } if (entities.length > 0) { return new tree.Expression(entities); } }
javascript
{ "resource": "" }
q24306
train
function (val) { var color, mode; if (arguments.length > 1) color = arguments[1]; if (arguments.length > 2) mode = arguments[2]; return { is: 'tag', val: val, color: color, mode: mode, toString: function(env) { var attr = {}; _.set(attr, 'value', val.ev(env).toString()); if (color) { _.set(attr, 'color', color.ev(env).toString()); } if (mode) { _.set(attr, 'mode', mode.ev(env).toString()); } return { '_name': 'stop', '_attributes': attr }; } }; }
javascript
{ "resource": "" }
q24307
addRules
train
function addRules(current, definition, byFilter) { var newFilters = definition.filters, newRules = definition.rules, updatedFilters, clone, previous; // The current definition might have been split up into // multiple definitions already. for (var k = 0; k < current.length; k++) { updatedFilters = current[k].filters.cloneWith(newFilters); if (updatedFilters) { previous = byFilter[updatedFilters]; if (previous) { // There's already a definition with those exact // filters. Add the current definitions' rules // and stop processing it as the existing rule // has already gone down the inheritance chain. previous.addRules(newRules); } else { clone = current[k].clone(updatedFilters); // Make sure that we're only maintaining the clone // when we did actually add rules. If not, there's // no need to keep the clone around. if (clone.addRules(newRules)) { // We inserted an element before this one, so we need // to make sure that in the next loop iteration, we're // not performing the same task for this element again, // hence the k++. byFilter[updatedFilters] = clone; current.splice(k, 0, clone); k++; } } } else if (updatedFilters === null) { // if updatedFilters is null, then adding the filters doesn't // invalidate or split the selector, so we addRules to the // combined selector // Filters can be added, but they don't change the // filters. This means we don't have to split the // definition. // // this is cloned here because of shared classes, see // sharedclass.mss current[k] = current[k].clone(); current[k].addRules(newRules); } // if updatedFeatures is false, then the filters split the rule, // so they aren't the same inheritance chain } return current; }
javascript
{ "resource": "" }
q24308
inheritDefinitions
train
function inheritDefinitions(definitions, env) { var inheritTime = +new Date(); // definitions are ordered by specificity, // high (index 0) to low var byAttachment = {}, byFilter = {}; var result = []; var current, attachment; // Evaluate the filters specified by each definition with the given // environment to correctly resolve variable references definitions.forEach(function(d) { d.filters.ev(env); }); for (var i = 0; i < definitions.length; i++) { attachment = definitions[i].attachment; current = [definitions[i]]; if (!byAttachment[attachment]) { byAttachment[attachment] = []; byAttachment[attachment].attachment = attachment; byFilter[attachment] = {}; result.push(byAttachment[attachment]); } // Iterate over all subsequent rules. for (var j = i + 1; j < definitions.length; j++) { if (definitions[j].attachment === attachment) { // Only inherit rules from the same attachment. current = addRules(current, definitions[j], byFilter[attachment]); } } for (var k = 0; k < current.length; k++) { byFilter[attachment][current[k].filters] = current[k]; byAttachment[attachment].push(current[k]); } } if (env.benchmark) console.warn('Inheritance time: ' + ((new Date() - inheritTime)) + 'ms'); return result; }
javascript
{ "resource": "" }
q24309
foldStyle
train
function foldStyle(style) { for (var i = 0; i < style.length; i++) { for (var j = style.length - 1; j > i; j--) { if (style[j].filters.cloneWith(style[i].filters) === null) { style.splice(j, 1); } } } return style; }
javascript
{ "resource": "" }
q24310
train
function(env) { for (var i = 0; i < this.selectors.length; i++) { var zval = tree.Zoom.all; for (var z = 0; z < this.selectors[i].zoom.length; z++) { zval = zval & this.selectors[i].zoom[z].ev(env).zoom; } this.selectors[i].zoom = zval; } }
javascript
{ "resource": "" }
q24311
symbolizerList
train
function symbolizerList(sym_order) { return sym_order.sort(function(a, b) { return a[1] - b[1]; }) .map(function(v) { return v[0]; }); }
javascript
{ "resource": "" }
q24312
train
function() { if (this.hsl !== null) { if (this.alpha < 1.0) { if (this.perceptual) { return 'rgba(' + hsluv.hsluvToRgb([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]).map(function(c) { return Math.round(c * 255); }).concat(this.round(this.alpha, 2)).join(', ') + ')'; } else { return 'rgba(' + chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).rgb().map(function(c) { return Math.round(c); }).concat(this.round(this.alpha, 2)).join(', ') + ')'; } } else { if (this.perceptual) { return hsluv.hsluvToHex([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]); } else { return chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).hex(); } } } return ''; }
javascript
{ "resource": "" }
q24313
train
function(env, op, other) { var result = [], rgb2; if (other instanceof tree.Color) { rgb2 = chroma(other.toString()).rgb(); } else if (_.isArray(other)) { rgb2 = _.slice(other, 0, Math.max(other.length, 3)); } else if (_.isObject(other)) { if (_.has(other, 'value')) { rgb2 = [other.value, other.value, other.value]; } else { return; } } else { rgb2 = [other, other, other]; } var rgb1 = chroma(this.toString()).rgb(); for (var c = 0; c < 3; c++) { result[c] = tree.operate(op, rgb1[c] , rgb2[c]); } if (this.perceptual) { var normalize = function (x) { return x / 255; }; result = hsluv.rgbToHsluv(_.map(result, normalize)); result[1] = result[1] / 100; result[2] = result[2] / 100; } else { result = chroma(result).hsl(); } return new tree.Color(result, this.alpha, this.perceptual); }
javascript
{ "resource": "" }
q24314
train
function(vcal) { var allsubs, properties, vtimezones, reqTzid, i, tzid; if (!vcal || vcal.name !== "vcalendar") { //not a top-level vcalendar component return vcal; } //Store vtimezone subcomponents in an object reference by tzid. //Store properties from everything else in another array allsubs = vcal.getAllSubcomponents(); properties = []; vtimezones = {}; for (i = 0; i < allsubs.length; i++) { if (allsubs[i].name === "vtimezone") { tzid = allsubs[i].getFirstProperty("tzid").getFirstValue(); vtimezones[tzid] = allsubs[i]; } else { properties = properties.concat(allsubs[i].getAllProperties()); } } //create an object with one entry for each required tz reqTzid = {}; for (i = 0; i < properties.length; i++) { if ((tzid = properties[i].getParameter("tzid"))) { reqTzid[tzid] = true; } } //delete any vtimezones that are not on the reqTzid list. for (i in vtimezones) { if (vtimezones.hasOwnProperty(i) && !reqTzid[i]) { vcal.removeSubcomponent(vtimezones[i]); } } //create any missing, but registered timezones for (i in reqTzid) { if ( reqTzid.hasOwnProperty(i) && !vtimezones[i] && ICAL.TimezoneService.has(i) ) { vcal.addSubcomponent(ICAL.TimezoneService.get(i).component); } } return vcal; }
javascript
{ "resource": "" }
q24315
train
function(string) { var result = parseInt(string, 10); if (ICAL.helpers.isStrictlyNaN(result)) { throw new Error( 'Could not extract integer from "' + string + '"' ); } return result; }
javascript
{ "resource": "" }
q24316
formatClassType
train
function formatClassType(data, type) { if (typeof(data) === 'undefined') { return undefined; } if (data instanceof type) { return data; } return new type(data); }
javascript
{ "resource": "" }
q24317
train
function(buffer, search, pos) { while ((pos = buffer.indexOf(search, pos)) !== -1) { if (pos > 0 && buffer[pos - 1] === '\\') { pos += 1; } else { return pos; } } return -1; }
javascript
{ "resource": "" }
q24318
train
function(list, seekVal, cmpfunc) { if (!list.length) return 0; var low = 0, high = list.length - 1, mid, cmpval; while (low <= high) { mid = low + Math.floor((high - low) / 2); cmpval = cmpfunc(seekVal, list[mid]); if (cmpval < 0) high = mid - 1; else if (cmpval > 0) low = mid + 1; else break; } if (cmpval < 0) return mid; // insertion is displacing, so use mid outright. else if (cmpval > 0) return mid + 1; else return mid; }
javascript
{ "resource": "" }
q24319
train
function() { if (!ICAL.debug) { return; } if (typeof (console) !== 'undefined' && 'log' in console) { ICAL.helpers.dumpn = function consoleDumpn(input) { console.log(input); }; } else { ICAL.helpers.dumpn = function geckoDumpn(input) { dump(input + '\n'); }; } ICAL.helpers.dumpn(arguments[0]); }
javascript
{ "resource": "" }
q24320
train
function(aSrc, aDeep) { if (!aSrc || typeof aSrc != "object") { return aSrc; } else if (aSrc instanceof Date) { return new Date(aSrc.getTime()); } else if ("clone" in aSrc) { return aSrc.clone(); } else if (Array.isArray(aSrc)) { var arr = []; for (var i = 0; i < aSrc.length; i++) { arr.push(aDeep ? ICAL.helpers.clone(aSrc[i], true) : aSrc[i]); } return arr; } else { var obj = {}; for (var name in aSrc) { // uses prototype method to allow use of Object.create(null); /* istanbul ignore else */ if (Object.prototype.hasOwnProperty.call(aSrc, name)) { if (aDeep) { obj[name] = ICAL.helpers.clone(aSrc[name], true); } else { obj[name] = aSrc[name]; } } } return obj; } }
javascript
{ "resource": "" }
q24321
foldline
train
function foldline(aLine) { var result = ""; var line = aLine || ""; while (line.length) { result += ICAL.newLineChar + " " + line.substr(0, ICAL.foldLength); line = line.substr(ICAL.foldLength); } return result.substr(ICAL.newLineChar.length + 1); }
javascript
{ "resource": "" }
q24322
pad
train
function pad(data) { if (typeof(data) !== 'string') { // handle fractions. if (typeof(data) === 'number') { data = parseInt(data); } data = String(data); } var len = data.length; switch (len) { case 0: return '00'; case 1: return '0' + data; default: return data; } }
javascript
{ "resource": "" }
q24323
train
function(base, child, extra) { function F() {} F.prototype = base.prototype; child.prototype = new F(); if (extra) { ICAL.helpers.extend(extra, child.prototype); } }
javascript
{ "resource": "" }
q24324
train
function(source, target) { for (var key in source) { var descr = Object.getOwnPropertyDescriptor(source, key); if (descr && !Object.getOwnPropertyDescriptor(target, key)) { Object.defineProperty(target, key, descr); } } return target; }
javascript
{ "resource": "" }
q24325
train
function(componentName) { var isInDesign = componentName && componentName in design.components; return isInDesign ? design.components[componentName] : design.defaultSet; }
javascript
{ "resource": "" }
q24326
ParserError
train
function ParserError(message) { this.message = message; this.name = 'ParserError'; try { throw new Error(); } catch (e) { if (e.stack) { var split = e.stack.split('\n'); split.shift(); this.stack = split.join('\n'); } } }
javascript
{ "resource": "" }
q24327
train
function(name) { if (name) { var i = 0; var comps = this.jCal[COMPONENT_INDEX]; var len = comps.length; for (; i < len; i++) { if (comps[i][NAME_INDEX] === name) { var result = this._hydrateComponent(i); return result; } } } else { if (this.jCal[COMPONENT_INDEX].length) { return this._hydrateComponent(0); } } // ensure we return a value (strict mode) return null; }
javascript
{ "resource": "" }
q24328
train
function(name) { var jCalLen = this.jCal[COMPONENT_INDEX].length; var i = 0; if (name) { var comps = this.jCal[COMPONENT_INDEX]; var result = []; for (; i < jCalLen; i++) { if (name === comps[i][NAME_INDEX]) { result.push( this._hydrateComponent(i) ); } } return result; } else { if (!this._components || (this._hydratedComponentCount !== jCalLen)) { for (; i < jCalLen; i++) { this._hydrateComponent(i); } } return this._components || []; } }
javascript
{ "resource": "" }
q24329
train
function(name) { var props = this.jCal[PROPERTY_INDEX]; var len = props.length; var i = 0; for (; i < len; i++) { // 0 is property name if (props[i][NAME_INDEX] === name) { return true; } } return false; }
javascript
{ "resource": "" }
q24330
train
function(name) { if (name) { var i = 0; var props = this.jCal[PROPERTY_INDEX]; var len = props.length; for (; i < len; i++) { if (props[i][NAME_INDEX] === name) { var result = this._hydrateProperty(i); return result; } } } else { if (this.jCal[PROPERTY_INDEX].length) { return this._hydrateProperty(0); } } return null; }
javascript
{ "resource": "" }
q24331
train
function(name) { var jCalLen = this.jCal[PROPERTY_INDEX].length; var i = 0; if (name) { var props = this.jCal[PROPERTY_INDEX]; var result = []; for (; i < jCalLen; i++) { if (name === props[i][NAME_INDEX]) { result.push( this._hydrateProperty(i) ); } } return result; } else { if (!this._properties || (this._hydratedPropertyCount !== jCalLen)) { for (; i < jCalLen; i++) { this._hydrateProperty(i); } } return this._properties || []; } }
javascript
{ "resource": "" }
q24332
train
function(component) { if (!this._components) { this._components = []; this._hydratedComponentCount = 0; } if (component.parent) { component.parent.removeSubcomponent(component); } var idx = this.jCal[COMPONENT_INDEX].push(component.jCal); this._components[idx - 1] = component; this._hydratedComponentCount++; component.parent = this; return component; }
javascript
{ "resource": "" }
q24333
train
function(name, value) { var prop = new ICAL.Property(name); prop.setValue(value); this.addProperty(prop); return prop; }
javascript
{ "resource": "" }
q24334
train
function(name, value) { var prop = this.getFirstProperty(name); if (prop) { prop.setValue(value); } else { prop = this.addPropertyWithValue(name, value); } return prop; }
javascript
{ "resource": "" }
q24335
train
function() { var designSet = this._designSet; if (this.type in designSet.value) { var designType = designSet.value[this.type]; if ('decorate' in designSet.value[this.type]) { this.isDecorated = true; } else { this.isDecorated = false; } if (this.name in designSet.property) { this.isMultiValue = ('multiValue' in designSet.property[this.name]); this.isStructuredValue = ('structuredValue' in designSet.property[this.name]); } } }
javascript
{ "resource": "" }
q24336
train
function(value, index) { if (!this._values) { this._values = []; } if (typeof(value) === 'object' && 'icaltype' in value) { // decorated value this.jCal[VALUE_INDEX + index] = this._undecorate(value); this._values[index] = value; } else { // undecorated value this.jCal[VALUE_INDEX + index] = value; this._values[index] = this._decorate(value); } }
javascript
{ "resource": "" }
q24337
train
function(name, value) { var lcname = name.toLowerCase(); if (typeof value === "string" && lcname in this._designSet.param && 'multiValue' in this._designSet.param[lcname]) { value = [value]; } this.jCal[PROP_INDEX][name] = value; }
javascript
{ "resource": "" }
q24338
train
function() { var name = this.jCal[NAME_INDEX]; var designSet = this._designSet; if (name in designSet.property) { var details = designSet.property[name]; if ('defaultType' in details) { return details.defaultType; } } return design.defaultType; }
javascript
{ "resource": "" }
q24339
train
function() { var len = this.jCal.length - VALUE_INDEX; if (len < 1) { // its possible for a property to have no value. return []; } var i = 0; var result = []; for (; i < len; i++) { result[i] = this._hydrateValue(i); } return result; }
javascript
{ "resource": "" }
q24340
train
function(values) { if (!this.isMultiValue) { throw new Error( this.name + ': does not not support mulitValue.\n' + 'override isMultiValue' ); } var len = values.length; var i = 0; this.removeAllValues(); if (len > 0 && typeof(values[0]) === 'object' && 'icaltype' in values[0]) { this.resetType(values[0].icaltype); } if (this.isDecorated) { for (; i < len; i++) { this._setDecoratedValue(values[i], i); } } else { for (; i < len; i++) { this.jCal[VALUE_INDEX + i] = values[i]; } } }
javascript
{ "resource": "" }
q24341
train
function(value) { this.removeAllValues(); if (typeof(value) === 'object' && 'icaltype' in value) { this.resetType(value.icaltype); } if (this.isDecorated) { this._setDecoratedValue(value, 0); } else { this.jCal[VALUE_INDEX] = value; } }
javascript
{ "resource": "" }
q24342
icaltime_compare
train
function icaltime_compare(other) { var a = this.toSeconds(); var b = other.toSeconds(); return (a > b) - (b > a); }
javascript
{ "resource": "" }
q24343
train
function() { return ICAL.Period.fromData({ start: this.start ? this.start.clone() : null, end: this.end ? this.end.clone() : null, duration: this.duration ? this.duration.clone() : null }); }
javascript
{ "resource": "" }
q24344
toSeconds
train
function toSeconds() { var seconds = this.seconds + 60 * this.minutes + 3600 * this.hours + 86400 * this.days + 7 * 86400 * this.weeks; return (this.isNegative ? -seconds : seconds); }
javascript
{ "resource": "" }
q24345
compare
train
function compare(aOther) { var thisSeconds = this.toSeconds(); var otherSeconds = aOther.toSeconds(); return (thisSeconds > otherSeconds) - (thisSeconds < otherSeconds); }
javascript
{ "resource": "" }
q24346
parseDurationChunk
train
function parseDurationChunk(letter, number, object) { var type; switch (letter) { case 'P': if (number && number === '-') { object.isNegative = true; } else { object.isNegative = false; } // period break; case 'D': type = 'days'; break; case 'W': type = 'weeks'; break; case 'H': type = 'hours'; break; case 'M': type = 'minutes'; break; case 'S': type = 'seconds'; break; default: // Not a valid chunk return 0; } if (type) { if (!number && number !== 0) { throw new Error( 'invalid duration value: Missing number before "' + letter + '"' ); } var num = parseInt(number, 10); if (ICAL.helpers.isStrictlyNaN(num)) { throw new Error( 'invalid duration value: Invalid number "' + number + '" before "' + letter + '"' ); } object[type] = num; } return 1; }
javascript
{ "resource": "" }
q24347
utcOffset
train
function utcOffset(tt) { if (this == ICAL.Timezone.utcTimezone || this == ICAL.Timezone.localTimezone) { return 0; } this._ensureCoverage(tt.year); if (!this.changes.length) { return 0; } var tt_change = { year: tt.year, month: tt.month, day: tt.day, hour: tt.hour, minute: tt.minute, second: tt.second }; var change_num = this._findNearbyChange(tt_change); var change_num_to_use = -1; var step = 1; // TODO: replace with bin search? for (;;) { var change = ICAL.helpers.clone(this.changes[change_num], true); if (change.utcOffset < change.prevUtcOffset) { ICAL.Timezone.adjust_change(change, 0, 0, 0, change.utcOffset); } else { ICAL.Timezone.adjust_change(change, 0, 0, 0, change.prevUtcOffset); } var cmp = ICAL.Timezone._compare_change_fn(tt_change, change); if (cmp >= 0) { change_num_to_use = change_num; } else { step = -1; } if (step == -1 && change_num_to_use != -1) { break; } change_num += step; if (change_num < 0) { return 0; } if (change_num >= this.changes.length) { break; } } var zone_change = this.changes[change_num_to_use]; var utcOffset_change = zone_change.utcOffset - zone_change.prevUtcOffset; if (utcOffset_change < 0 && change_num_to_use > 0) { var tmp_change = ICAL.helpers.clone(zone_change, true); ICAL.Timezone.adjust_change(tmp_change, 0, 0, 0, tmp_change.prevUtcOffset); if (ICAL.Timezone._compare_change_fn(tt_change, tmp_change) < 0) { var prev_zone_change = this.changes[change_num_to_use - 1]; var want_daylight = false; // TODO if (zone_change.is_daylight != want_daylight && prev_zone_change.is_daylight == want_daylight) { zone_change = prev_zone_change; } } } // TODO return is_daylight? return zone_change.utcOffset; }
javascript
{ "resource": "" }
q24348
train
function(name, timezone) { if (name instanceof ICAL.Component) { if (name.name === 'vtimezone') { timezone = new ICAL.Timezone(name); name = timezone.tzid; } } if (timezone instanceof ICAL.Timezone) { zones[name] = timezone; } else { throw new TypeError('timezone must be ICAL.Timezone or ICAL.Component'); } }
javascript
{ "resource": "" }
q24349
icaltime_fromJSDate
train
function icaltime_fromJSDate(aDate, useUTC) { if (!aDate) { this.reset(); } else { if (useUTC) { this.zone = ICAL.Timezone.utcTimezone; this.year = aDate.getUTCFullYear(); this.month = aDate.getUTCMonth() + 1; this.day = aDate.getUTCDate(); this.hour = aDate.getUTCHours(); this.minute = aDate.getUTCMinutes(); this.second = aDate.getUTCSeconds(); } else { this.zone = ICAL.Timezone.localTimezone; this.year = aDate.getFullYear(); this.month = aDate.getMonth() + 1; this.day = aDate.getDate(); this.hour = aDate.getHours(); this.minute = aDate.getMinutes(); this.second = aDate.getSeconds(); } } this._cachedUnixTime = null; return this; }
javascript
{ "resource": "" }
q24350
icaltime_dayOfWeek
train
function icaltime_dayOfWeek() { var dowCacheKey = (this.year << 9) + (this.month << 5) + this.day; if (dowCacheKey in ICAL.Time._dowCache) { return ICAL.Time._dowCache[dowCacheKey]; } // Using Zeller's algorithm var q = this.day; var m = this.month + (this.month < 3 ? 12 : 0); var Y = this.year - (this.month < 3 ? 1 : 0); var h = (q + Y + ICAL.helpers.trunc(((m + 1) * 26) / 10) + ICAL.helpers.trunc(Y / 4)); /* istanbul ignore else */ if (true /* gregorian */) { h += ICAL.helpers.trunc(Y / 100) * 6 + ICAL.helpers.trunc(Y / 400); } else { h += 5; } // Normalize to 1 = sunday h = ((h + 6) % 7) + 1; ICAL.Time._dowCache[dowCacheKey] = h; return h; }
javascript
{ "resource": "" }
q24351
dayOfYear
train
function dayOfYear() { var is_leap = (ICAL.Time.isLeapYear(this.year) ? 1 : 0); var diypm = ICAL.Time.daysInYearPassedMonth; return diypm[is_leap][this.month - 1] + this.day; }
javascript
{ "resource": "" }
q24352
startDoyWeek
train
function startDoyWeek(aFirstDayOfWeek) { var firstDow = aFirstDayOfWeek || ICAL.Time.SUNDAY; var delta = this.dayOfWeek() - firstDow; if (delta < 0) delta += 7; return this.dayOfYear() - delta; }
javascript
{ "resource": "" }
q24353
train
function(aDayOfWeek, aPos) { var dow = this.dayOfWeek(); if (aPos === 0 && dow === aDayOfWeek) { return true; } // get pos var day = this.nthWeekDay(aDayOfWeek, aPos); if (day === this.day) { return true; } return false; }
javascript
{ "resource": "" }
q24354
weekNumber
train
function weekNumber(aWeekStart) { var wnCacheKey = (this.year << 12) + (this.month << 8) + (this.day << 3) + aWeekStart; if (wnCacheKey in ICAL.Time._wnCache) { return ICAL.Time._wnCache[wnCacheKey]; } // This function courtesty of Julian Bucknall, published under the MIT license // http://www.boyet.com/articles/publishedarticles/calculatingtheisoweeknumb.html // plus some fixes to be able to use different week starts. var week1; var dt = this.clone(); dt.isDate = true; var isoyear = this.year; if (dt.month == 12 && dt.day > 25) { week1 = ICAL.Time.weekOneStarts(isoyear + 1, aWeekStart); if (dt.compare(week1) < 0) { week1 = ICAL.Time.weekOneStarts(isoyear, aWeekStart); } else { isoyear++; } } else { week1 = ICAL.Time.weekOneStarts(isoyear, aWeekStart); if (dt.compare(week1) < 0) { week1 = ICAL.Time.weekOneStarts(--isoyear, aWeekStart); } } var daysBetween = (dt.subtractDate(week1).toSeconds() / 86400); var answer = ICAL.helpers.trunc(daysBetween / 7) + 1; ICAL.Time._wnCache[wnCacheKey] = answer; return answer; }
javascript
{ "resource": "" }
q24355
icaltime_add
train
function icaltime_add(aDuration) { var mult = (aDuration.isNegative ? -1 : 1); // because of the duration optimizations it is much // more efficient to grab all the values up front // then set them directly (which will avoid a normalization call). // So we don't actually normalize until we need it. var second = this.second; var minute = this.minute; var hour = this.hour; var day = this.day; second += mult * aDuration.seconds; minute += mult * aDuration.minutes; hour += mult * aDuration.hours; day += mult * aDuration.days; day += mult * 7 * aDuration.weeks; this.second = second; this.minute = minute; this.hour = hour; this.day = day; this._cachedUnixTime = null; }
javascript
{ "resource": "" }
q24356
icaltime_subtract_abs
train
function icaltime_subtract_abs(aDate) { var unixTime = this.toUnixTime(); var other = aDate.toUnixTime(); return ICAL.Duration.fromSeconds(unixTime - other); }
javascript
{ "resource": "" }
q24357
icaltime_compare
train
function icaltime_compare(other) { var a = this.toUnixTime(); var b = other.toUnixTime(); if (a > b) return 1; if (b > a) return -1; return 0; }
javascript
{ "resource": "" }
q24358
icaltime_compareDateOnlyTz
train
function icaltime_compareDateOnlyTz(other, tz) { function cmp(attr) { return ICAL.Time._cmp_attr(a, b, attr); } var a = this.convertToZone(tz); var b = other.convertToZone(tz); var rc = 0; if ((rc = cmp("year")) != 0) return rc; if ((rc = cmp("month")) != 0) return rc; if ((rc = cmp("day")) != 0) return rc; return rc; }
javascript
{ "resource": "" }
q24359
convertToZone
train
function convertToZone(zone) { var copy = this.clone(); var zone_equals = (this.zone.tzid == zone.tzid); if (!this.isDate && !zone_equals) { ICAL.Timezone.convert_time(copy, this.zone, zone); } copy.zone = zone; return copy; }
javascript
{ "resource": "" }
q24360
train
function() { var string = this.toString(); if (string.length > 10) { return ICAL.design.icalendar.value['date-time'].toICAL(string); } else { return ICAL.design.icalendar.value.date.toICAL(string); } }
javascript
{ "resource": "" }
q24361
toJSDate
train
function toJSDate() { if (this.zone == ICAL.Timezone.localTimezone) { if (this.isDate) { return new Date(this.year, this.month - 1, this.day); } else { return new Date(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, 0); } } else { return new Date(this.toUnixTime() * 1000); } }
javascript
{ "resource": "" }
q24362
fromUnixTime
train
function fromUnixTime(seconds) { this.zone = ICAL.Timezone.utcTimezone; var epoch = ICAL.Time.epochTime.clone(); epoch.adjust(0, 0, 0, seconds); this.year = epoch.year; this.month = epoch.month; this.day = epoch.day; this.hour = epoch.hour; this.minute = epoch.minute; this.second = Math.floor(epoch.second); this._cachedUnixTime = null; }
javascript
{ "resource": "" }
q24363
toUnixTime
train
function toUnixTime() { if (this._cachedUnixTime !== null) { return this._cachedUnixTime; } var offset = this.utcOffset(); // we use the offset trick to ensure // that we are getting the actual UTC time var ms = Date.UTC( this.year, this.month - 1, this.day, this.hour, this.minute, this.second - offset ); // seconds this._cachedUnixTime = ms / 1000; return this._cachedUnixTime; }
javascript
{ "resource": "" }
q24364
train
function() { var copy = [ 'year', 'month', 'day', 'hour', 'minute', 'second', 'isDate' ]; var result = Object.create(null); var i = 0; var len = copy.length; var prop; for (; i < len; i++) { prop = copy[i]; result[prop] = this[prop]; } if (this.zone) { result.timezone = this.zone.tzid; } return result; }
javascript
{ "resource": "" }
q24365
train
function() { var res = Object.create(null); res.freq = this.freq; if (this.count) { res.count = this.count; } if (this.interval > 1) { res.interval = this.interval; } for (var k in this.parts) { /* istanbul ignore if */ if (!this.parts.hasOwnProperty(k)) { continue; } var kparts = this.parts[k]; if (Array.isArray(kparts) && kparts.length == 1) { res[k.toLowerCase()] = kparts[0]; } else { res[k.toLowerCase()] = ICAL.helpers.clone(this.parts[k]); } } if (this.until) { res.until = this.until.toString(); } if ('wkst' in this && this.wkst !== ICAL.Time.DEFAULT_WEEK_START) { res.wkst = ICAL.Recur.numericDayToIcalDay(this.wkst); } return res; }
javascript
{ "resource": "" }
q24366
icalrecur_toString
train
function icalrecur_toString() { // TODO retain order var str = "FREQ=" + this.freq; if (this.count) { str += ";COUNT=" + this.count; } if (this.interval > 1) { str += ";INTERVAL=" + this.interval; } for (var k in this.parts) { /* istanbul ignore else */ if (this.parts.hasOwnProperty(k)) { str += ";" + k + "=" + this.parts[k]; } } if (this.until) { str += ';UNTIL=' + this.until.toICALString(); } if ('wkst' in this && this.wkst !== ICAL.Time.DEFAULT_WEEK_START) { str += ';WKST=' + ICAL.Recur.numericDayToIcalDay(this.wkst); } return str; }
javascript
{ "resource": "" }
q24367
train
function(options) { this.rule = ICAL.helpers.formatClassType(options.rule, ICAL.Recur); if (!this.rule) { throw new Error('iterator requires a (ICAL.Recur) rule'); } this.dtstart = ICAL.helpers.formatClassType(options.dtstart, ICAL.Time); if (!this.dtstart) { throw new Error('iterator requires a (ICAL.Time) dtstart'); } if (options.by_data) { this.by_data = options.by_data; } else { this.by_data = ICAL.helpers.clone(this.rule.parts, true); } if (options.occurrence_number) this.occurrence_number = options.occurrence_number; this.days = options.days || []; if (options.last) { this.last = ICAL.helpers.formatClassType(options.last, ICAL.Time); } this.by_indices = options.by_indices; if (!this.by_indices) { this.by_indices = { "BYSECOND": 0, "BYMINUTE": 0, "BYHOUR": 0, "BYDAY": 0, "BYMONTH": 0, "BYWEEKNO": 0, "BYMONTHDAY": 0 }; } this.initialized = options.initialized || false; if (!this.initialized) { this.init(); } }
javascript
{ "resource": "" }
q24368
icalrecur_iterator_next
train
function icalrecur_iterator_next() { var before = (this.last ? this.last.clone() : null); if ((this.rule.count && this.occurrence_number >= this.rule.count) || (this.rule.until && this.last.compare(this.rule.until) > 0)) { //XXX: right now this is just a flag and has no impact // we can simplify the above case to check for completed later. this.completed = true; return null; } if (this.occurrence_number == 0 && this.last.compare(this.dtstart) >= 0) { // First of all, give the instance that was initialized this.occurrence_number++; return this.last; } var valid; do { valid = 1; switch (this.rule.freq) { case "SECONDLY": this.next_second(); break; case "MINUTELY": this.next_minute(); break; case "HOURLY": this.next_hour(); break; case "DAILY": this.next_day(); break; case "WEEKLY": this.next_week(); break; case "MONTHLY": valid = this.next_month(); break; case "YEARLY": this.next_year(); break; default: return null; } } while (!this.check_contracting_rules() || this.last.compare(this.dtstart) < 0 || !valid); // TODO is this valid? if (this.last.compare(before) == 0) { throw new Error("Same occurrence found twice, protecting " + "you from death by recursion"); } if (this.rule.until && this.last.compare(this.rule.until) > 0) { this.completed = true; return null; } else { this.occurrence_number++; return this.last; } }
javascript
{ "resource": "" }
q24369
check_set_position
train
function check_set_position(aPos) { if (this.has_by_data('BYSETPOS')) { var idx = this.by_data.BYSETPOS.indexOf(aPos); // negative numbers are not false-y return idx !== -1; } return false; }
javascript
{ "resource": "" }
q24370
train
function() { var result = Object.create(null); result.initialized = this.initialized; result.rule = this.rule.toJSON(); result.dtstart = this.dtstart.toJSON(); result.by_data = this.by_data; result.days = this.days; result.last = this.last.toJSON(); result.by_indices = this.by_indices; result.occurrence_number = this.occurrence_number; return result; }
javascript
{ "resource": "" }
q24371
train
function() { var iter; var ruleOfDay; var next; var compare; var maxTries = 500; var currentTry = 0; while (true) { if (currentTry++ > maxTries) { throw new Error( 'max tries have occured, rule may be impossible to forfill.' ); } next = this.ruleDate; iter = this._nextRecurrenceIter(this.last); // no more matches // because we increment the rule day or rule // _after_ we choose a value this should be // the only spot where we need to worry about the // end of events. if (!next && !iter) { // there are no more iterators or rdates this.complete = true; break; } // no next rule day or recurrence rule is first. if (!next || (iter && next.compare(iter.last) > 0)) { // must be cloned, recur will reuse the time element. next = iter.last.clone(); // move to next so we can continue iter.next(); } // if the ruleDate is still next increment it. if (this.ruleDate === next) { this._nextRuleDay(); } this.last = next; // check the negative rules if (this.exDate) { compare = this.exDate.compare(this.last); if (compare < 0) { this._nextExDay(); } // if the current rule is excluded skip it. if (compare === 0) { this._nextExDay(); continue; } } //XXX: The spec states that after we resolve the final // list of dates we execute exdate this seems somewhat counter // intuitive to what I have seen most servers do so for now // I exclude based on the original date not the one that may // have been modified by the exception. return this.last; } }
javascript
{ "resource": "" }
q24372
train
function() { function toJSON(item) { return item.toJSON(); } var result = Object.create(null); result.ruleIterators = this.ruleIterators.map(toJSON); if (this.ruleDates) { result.ruleDates = this.ruleDates.map(toJSON); } if (this.exDates) { result.exDates = this.exDates.map(toJSON); } result.ruleDateInc = this.ruleDateInc; result.exDateInc = this.exDateInc; result.last = this.last.toJSON(); result.dtstart = this.dtstart.toJSON(); result.complete = this.complete; return result; }
javascript
{ "resource": "" }
q24373
train
function(component, propertyName) { function handleProp(prop) { idx = ICAL.helpers.binsearchInsert( result, prop, compareTime ); // ordered insert result.splice(idx, 0, prop); } var result = []; var props = component.getAllProperties(propertyName); var len = props.length; var i = 0; var prop; var idx; for (; i < len; i++) { props[i].getValues().forEach(handleProp); } return result; }
javascript
{ "resource": "" }
q24374
train
function(component) { this.ruleIterators = []; this.last = this.dtstart.clone(); // to provide api consistency non-recurring // events can also use the iterator though it will // only return a single time. if (!isRecurringComponent(component)) { this.ruleDate = this.last.clone(); this.complete = true; return; } if (component.hasProperty('rdate')) { this.ruleDates = this._extractDates(component, 'rdate'); // special hack for cases where first rdate is prior // to the start date. We only check for the first rdate. // This is mostly for google's crazy recurring date logic // (contacts birthdays). if ((this.ruleDates[0]) && (this.ruleDates[0].compare(this.dtstart) < 0)) { this.ruleDateInc = 0; this.last = this.ruleDates[0].clone(); } else { this.ruleDateInc = ICAL.helpers.binsearchInsert( this.ruleDates, this.last, compareTime ); } this.ruleDate = this.ruleDates[this.ruleDateInc]; } if (component.hasProperty('rrule')) { var rules = component.getAllProperties('rrule'); var i = 0; var len = rules.length; var rule; var iter; for (; i < len; i++) { rule = rules[i].getFirstValue(); iter = rule.iterator(this.dtstart); this.ruleIterators.push(iter); // increment to the next occurrence so future // calls to next return times beyond the initial iteration. // XXX: I find this suspicious might be a bug? iter.next(); } } if (component.hasProperty('exdate')) { this.exDates = this._extractDates(component, 'exdate'); // if we have a .last day we increment the index to beyond it. this.exDateInc = ICAL.helpers.binsearchInsert( this.exDates, this.last, compareTime ); this.exDate = this.exDates[this.exDateInc]; } }
javascript
{ "resource": "" }
q24375
train
function() { var iters = this.ruleIterators; if (iters.length === 0) { return null; } var len = iters.length; var iter; var iterTime; var iterIdx = 0; var chosenIter; // loop through each iterator for (; iterIdx < len; iterIdx++) { iter = iters[iterIdx]; iterTime = iter.last; // if iteration is complete // then we must exclude it from // the search and remove it. if (iter.completed) { len--; if (iterIdx !== 0) { iterIdx--; } iters.splice(iterIdx, 1); continue; } // find the most recent possible choice if (!chosenIter || chosenIter.last.compare(iterTime) > 0) { // that iterator is saved chosenIter = iter; } } // the chosen iterator is returned but not mutated // this iterator contains the most recent event. return chosenIter; }
javascript
{ "resource": "" }
q24376
train
function(obj) { if (this.isRecurrenceException()) { throw new Error('cannot relate exception to exceptions'); } if (obj instanceof ICAL.Component) { obj = new ICAL.Event(obj); } if (this.strictExceptions && obj.uid !== this.uid) { throw new Error('attempted to relate unrelated exception'); } var id = obj.recurrenceId.toString(); // we don't sort or manage exceptions directly // here the recurrence expander handles that. this.exceptions[id] = obj; // index RANGE=THISANDFUTURE exceptions so we can // look them up later in getOccurrenceDetails. if (obj.modifiesFuture()) { var item = [ obj.recurrenceId.toUnixTime(), id ]; // we keep them sorted so we can find the nearest // value later on... var idx = ICAL.helpers.binsearchInsert( this.rangeExceptions, item, compareRangeException ); this.rangeExceptions.splice(idx, 0, item); } }
javascript
{ "resource": "" }
q24377
train
function(time) { if (!this.rangeExceptions.length) { return null; } var utc = time.toUnixTime(); var idx = ICAL.helpers.binsearchInsert( this.rangeExceptions, [utc], compareRangeException ); idx -= 1; // occurs before if (idx < 0) { return null; } var rangeItem = this.rangeExceptions[idx]; /* istanbul ignore next: sanity check only */ if (utc < rangeItem[0]) { return null; } return rangeItem[1]; }
javascript
{ "resource": "" }
q24378
train
function() { var rules = this.component.getAllProperties('rrule'); var i = 0; var len = rules.length; var result = Object.create(null); for (; i < len; i++) { var value = rules[i].getFirstValue(); result[value.freq] = true; } return result; }
javascript
{ "resource": "" }
q24379
train
function(ical) { //TODO: this is sync now in the future we will have a incremental parser. if (typeof(ical) === 'string') { ical = ICAL.parse(ical); } if (!(ical instanceof ICAL.Component)) { ical = new ICAL.Component(ical); } var components = ical.getAllSubcomponents(); var i = 0; var len = components.length; var component; for (; i < len; i++) { component = components[i]; switch (component.name) { case 'vtimezone': if (this.parseTimezone) { var tzid = component.getFirstPropertyValue('tzid'); if (tzid) { this.ontimezone(new ICAL.Timezone({ tzid: tzid, component: component })); } } break; case 'vevent': if (this.parseEvent) { this.onevent(new ICAL.Event(component)); } break; default: continue; } } //XXX: ideally we should do a "nextTick" here // so in all cases this is actually async. this.oncomplete(); }
javascript
{ "resource": "" }
q24380
deployMQTrigger
train
function deployMQTrigger(mqType, name, namespace, topic, options) { const opts = _.defaults({}, options, { log: console.log, }); const trigger = { apiVersion: 'kubeless.io/v1beta1', kind: `${mqType}Trigger`, metadata: { name: _.kebabCase(`${name}-${topic}`), namespace, labels: { 'created-by': 'kubeless', }, }, spec: { functionSelector: { matchLabels: { 'created-by': 'kubeless', function: name, }, }, topic, }, }; const triggerApi = new CRD( 'apis/kubeless.io', 'v1beta1', namespace, `${mqType.toLowerCase()}triggers` ); opts.log(`Deploying ${mqType} trigger: ${trigger.metadata.name}`); return triggerApi.getItem(trigger.metadata.name) .then((res) => { if (res.code === 404) { return triggerApi.post({ body: trigger }); } opts.log(`Updating existing ${mqType} trigger`); return triggerApi.put(trigger.metadata.name, { body: trigger }); }); }
javascript
{ "resource": "" }
q24381
handleMQTDeployment
train
function handleMQTDeployment(trigger, name, namespace, options) { let mqTrigger = trigger; // If only a string is passed, expect it to be the subject if (typeof mqTrigger === 'string') { // Defaults to Kafka mqTrigger = { queue: 'kafka', topic: mqTrigger, }; } else { // Otherwise expect type and subject to be set if (_.isEmpty(mqTrigger.queue)) { throw new Error('You should specify a queue for the trigger event (i.e. kafka, nats)'); } if (_.isEmpty(mqTrigger.topic)) { throw new Error('You should specify a topic for the trigger event'); } } return deployMQTrigger( MQTypes[mqTrigger.queue.toLowerCase()], name, namespace, mqTrigger.topic, { log: options.log } ); }
javascript
{ "resource": "" }
q24382
train
function (elements) { elements.forEach(function(element) { document.getElementById(element).innerHTML = '' document.getElementById(element).value = '' }) }
javascript
{ "resource": "" }
q24383
train
function (newTokens, oldTokens) { var i; var token; var replacedTokens = {}; var removedTokens = subtractAsSets(oldTokens, newTokens); for (i = 0; i < removedTokens.length; i++) { var removedToken = removedTokens[i]; var el = map[removedToken]; delete map[removedToken]; var newToken = tokenFn(el); // if the element wasn't removed but simply got a new token, its old token will be different from the current one if (newToken === removedToken) { self.onRemoved(el); } else { replacedTokens[newToken] = removedToken; self.onChanged(el); } } var addedTokens = subtractAsSets(newTokens, oldTokens); for (i = 0; i < addedTokens.length; i++) { token = addedTokens[i]; if (!replacedTokens[token]) { self.onAdded(map[token]); } } }
javascript
{ "resource": "" }
q24384
train
function (data) { // convert {0: "Jan", 1: "Feb", ...} to ["Jan", "Feb", ...] return (Object.keys(data) || []).reduce( function (rslt, el) { rslt.push(data[el]); return rslt; }, [] ); }
javascript
{ "resource": "" }
q24385
createButtonClassName
train
function createButtonClassName(props) { return createClassName( props.noDefaultClassName ? null : 'button', props.className, props.size, props.color, { 'hollow': props.isHollow, 'clear': props.isClear, 'expanded': props.isExpanded, 'disabled': props.isDisabled, 'dropdown': props.isDropdown, 'arrow-only': props.isArrowOnly }, generalClassNames(props) ); }
javascript
{ "resource": "" }
q24386
FeedMessage
train
function FeedMessage(properties) { this.entity = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24387
FeedHeader
train
function FeedHeader(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24388
FeedEntity
train
function FeedEntity(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24389
TripUpdate
train
function TripUpdate(properties) { this.stopTimeUpdate = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24390
StopTimeEvent
train
function StopTimeEvent(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24391
StopTimeUpdate
train
function StopTimeUpdate(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24392
VehiclePosition
train
function VehiclePosition(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24393
Alert
train
function Alert(properties) { this.activePeriod = []; this.informedEntity = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24394
TimeRange
train
function TimeRange(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24395
Position
train
function Position(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24396
TripDescriptor
train
function TripDescriptor(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24397
VehicleDescriptor
train
function VehicleDescriptor(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24398
EntitySelector
train
function EntitySelector(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }
q24399
TranslatedString
train
function TranslatedString(properties) { this.translation = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; }
javascript
{ "resource": "" }