_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q33800 | train | function(autoset){
autoset = autoset !== void 0 ? autoset : true;
if(autoset && !this.current && this.targets.length){
this.sort();
this.setCurrent(this.targets[0]);
}
return this.current;
} | javascript | {
"resource": ""
} | |
q33801 | train | function(){
if(!this.current){
return this.getCurrent();
}
var index = this.targets.indexOf(this.current);
if(index === 0){
index = this.targets.length - 1;
} else {
index--;
}
this.setCu... | javascript | {
"resource": ""
} | |
q33802 | train | function(obj){
for(var i = this.typeSortPriority.length - 1; i >= 0; i--){
var type = this.typeSortPriority[i];
if(obj instanceof type){
return i;
}
}
} | javascript | {
"resource": ""
} | |
q33803 | train | function(){
var _this = this;
this.targets.sort(function(a, b){
var aTypeSortPriority = _this.getTypeSortPriority(a.value);
var bTypeSortPriority = _this.getTypeSortPriority(b.value);
if(aTypeSortPriority === bTypeSortPriority){
... | javascript | {
"resource": ""
} | |
q33804 | train | function(value){
for(var i = this.targets.length - 1; i >= 0; i--){
var target = this.targets[i];
if(target.value === value){
return target;
}
}
} | javascript | {
"resource": ""
} | |
q33805 | parseTitle | train | function parseTitle (node, nodeType, feedType) {
return utils.stripHtml(utils.get(node.title));
} | javascript | {
"resource": ""
} |
q33806 | parseDescription | train | function parseDescription (node, nodeType, feedType) {
var propOrder = nodeType === 'item' ?
['description', 'summary', 'itunes:summary', 'content:encoded', 'content'] :
['description', 'subtitle', 'itunes:summary'];
return utils.stripHtml(utils.getFirstFoundPropValue(node, propOrder));
} | javascript | {
"resource": ""
} |
q33807 | parseXmlUrl | train | function parseXmlUrl (node, nodeType, feedType) {
var getLink = function (linkNode) {
var link;
utils.parse(linkNode, function (linkEl) {
var linkAttr = linkEl['@'];
if (linkAttr.href && linkAttr.rel === 'self') {
link = linkAttr.href;
return;
}
}, this, true);
ret... | javascript | {
"resource": ""
} |
q33808 | parseOrigLink | train | function parseOrigLink (node, nodeType, feedType) {
var origLink;
if (origLink = utils.getFirstFoundPropValue(node, ['feedburner:origlink', 'pheedo:origlink'])) {
return origLink;
} else {
utils.parse(node.link, function (linkEl) {
var linkAttr = linkEl['@'];
if (linkAttr.href && linkAttr.re... | javascript | {
"resource": ""
} |
q33809 | parseAuthor | train | function parseAuthor (node, nodeType, feedType) {
var authorNode = node.author,
author;
//Both meta and item have author property as top priority and share parsing logic.
if (authorNode && (author = utils.get(authorNode))) {
author = addressparser(author)[0];
return author.name || author.address;
... | javascript | {
"resource": ""
} |
q33810 | parseLanguage | train | function parseLanguage (node, nodeType, feedType) {
return utils.get(node.language) || utils.getAttr(node, 'xml:lang') || utils.get(node['dc:language']);
} | javascript | {
"resource": ""
} |
q33811 | parseUpdateInfo | train | function parseUpdateInfo (node, nodeType, feedType) {
var updateInfo = {}, temp;
if (temp = utils.get(node['sy:updatefrequency'])) {
updateInfo.frequency = temp;
}
if (temp = utils.get(node['sy:updateperiod'])) {
updateInfo.period = temp;
}
if (temp = utils.get(node['sy:updatebase'])) {
updateI... | javascript | {
"resource": ""
} |
q33812 | parseImage | train | function parseImage (node, nodeType, feedType) {
var image, mediaGroup, mediaContent;
if (node.image && (image = utils.get(utils.get(node.image, 'url') || node.image))) {
return image;
} else if (nodeType === 'meta') {
return utils.getAttr(node['itunes:image'], 'href') || utils.getAttr(node['media:thumbn... | javascript | {
"resource": ""
} |
q33813 | parseCloud | train | function parseCloud (node, nodeType, feedType) {
var cloud,
temp = utils.getAttr(node.cloud) || {};
if (Object.keys(temp).length) {
cloud = temp;
cloud.type = 'rsscloud';
} else {
utils.parse(node.link, function (link) {
var attr = utils.getAttr(link);
if (attr && attr.href && attr.... | javascript | {
"resource": ""
} |
q33814 | parseCategories | train | function parseCategories (node, nodeType, feedType) {
var categoryMap = {};
var setCategory = function (category, attrProp) {
if (!category) {
return;
} else if (attrProp) {
category = utils.getAttr(category, attrProp);
}
if (!categoryMap[category]) {
categoryMap[category] = true... | javascript | {
"resource": ""
} |
q33815 | parseComments | train | function parseComments (node, nodeType, feedType) {
var comments = utils.get(node.comments);
if (!comments && feedType === 'atom') {
utils.parse(node.link, function (link) {
var linkAttr = link['@'];
if (linkAttr && linkAttr.rel === 'replies' && linkAttr.href) {
comments = linkAttr.href;
... | javascript | {
"resource": ""
} |
q33816 | parseEnclosures | train | function parseEnclosures (node, nodeType, feedType) {
var enclosuresMap = {};
['media:content', 'enclosure', 'link', 'enc:enclosure'].forEach(function (key) {
if (!node[key]) {
return;
}
utils.parse(node[key], function (enc) {
var enclosure,
encAttr = enc['@'];
if (!encAtt... | javascript | {
"resource": ""
} |
q33817 | parseSource | train | function parseSource (node, nodeType, feedType) {
var source = {},
sourceNode = node.source,
temp;
if (!sourceNode) {
return;
}
if (temp = (feedType === 'atom' && utils.get(sourceNode.title)) || utils.get(sourceNode)) {
source.title = temp;
}
if (temp = (feedType === 'atom' && utils.ge... | javascript | {
"resource": ""
} |
q33818 | get | train | function get(obj, subkey) {
if (!obj) { return; }
if (Array.isArray(obj)) {
obj = obj[0];
}
return obj[subkey || '#'];
} | javascript | {
"resource": ""
} |
q33819 | getAttr | train | function getAttr(obj, attr) {
if (!obj) { return; }
if (Array.isArray(obj)) {
obj = obj[0];
}
return (attr && obj['@']) ? obj['@'][attr] : obj['@'];
} | javascript | {
"resource": ""
} |
q33820 | parse | train | function parse (el, parseFn, context, canBreak) {
if (!el) { return; }
if (!Array.isArray(el)) {
parseFn.call(context, el);
} else if (canBreak) {
el.some(parseFn, context);
} else {
el.forEach(parseFn, context);
}
} | javascript | {
"resource": ""
} |
q33821 | strArrayToObj | train | function strArrayToObj (array) {
return array && array.reduce(function(o, v) {
o[v] = true;
return o;
}, {});
} | javascript | {
"resource": ""
} |
q33822 | createOpenTag | train | function createOpenTag (tagName, attrs) {
var attrString = Object.keys(attrs).map(function (key) {
return ' ' + key + '="' + attrs[key] + '"';
}).join('');
return '<' + tagName + attrString + '>';
} | javascript | {
"resource": ""
} |
q33823 | getStandardTimeOffset | train | function getStandardTimeOffset(date) {
var jan = new Date(date.getFullYear(), 0, 1);
var jul = new Date(date.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
} | javascript | {
"resource": ""
} |
q33824 | fixInvalidDate | train | function fixInvalidDate(dateString) {
if (!dateString) {
return;
}
//Convert invalid dates' timezones to GMT using timezoneMap
dateString = dateString.replace(/BST?/i, function (match) {
return timezoneMap[match];
});
//Some dates come in as ET, CT etc.. and some don't have the correct offset.
/... | javascript | {
"resource": ""
} |
q33825 | getDate | train | function getDate (dateString) {
var date = new Date(dateString);
if (Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime())) {
return date;
}
//try to fix invalid date
date = fixInvalidDate(dateString);
//if date still isn't valid there's not more we can do..
if (!isNaN(... | javascript | {
"resource": ""
} |
q33826 | makeConcat | train | function makeConcat(chunkType) {
switch (chunkType) {
case BUFFER:
return (a, b) => Buffer.concat([a, b]);
default:
return (a, b) => {
// console.log('[%d, %d]', a.length, b.length);
const t = new Uint8Array(a.length + b.length);
t.set(a);
t.set(b, a.length);
// console.log('%d: %s', t.length, new... | javascript | {
"resource": ""
} |
q33827 | isElementVisible | train | function isElementVisible(el) {
/*
* Checks if element (or an ancestor) is hidden via style properties.
* See https://stackoverflow.com/a/21696585/463471
*/
const isCurrentlyVisible = el.offsetParent !== null;
// Check if any part of the element is vertically within the viewport.
const position = el.g... | javascript | {
"resource": ""
} |
q33828 | Receiver | train | function Receiver() {
stream.Duplex.call(this, {
readableObjectMode: true
});
this._buffer = null;
this._frame = new Frame();
this._state = WAITING_FOR_HEADER;
} | javascript | {
"resource": ""
} |
q33829 | train | function(e){
if(e.type === 'mousemove' && this.onHover){
this.onHover(e.clientX, e.clientY);
}
else if(e.type === 'mouseenter' && this.onHover){
this.onHover(e.clientX, e.clientY);
}
else if(e.type === 'mouseleave' && this.onHov... | javascript | {
"resource": ""
} | |
q33830 | train | function(e) {
if(this.onHover){
var coords = this.game.renderer.mouseToTileCoords(e.clientX, e.clientY);
this.onHover(coords);
}
} | javascript | {
"resource": ""
} | |
q33831 | train | function(element){
if(this._boundElement){
this.stopListening();
}
element.addEventListener('mousemove', this);
element.addEventListener('mouseenter', this);
element.addEventListener('mouseleave', this);
element.addEventListener('c... | javascript | {
"resource": ""
} | |
q33832 | train | function(){
if(!this._boundElement){
return false;
}
var el = this._boundElement;
el.removeEventListener('mousemove', this);
el.removeEventListener('mouseenter', this);
el.removeEventListener('mouseleave', this);
el.remo... | javascript | {
"resource": ""
} | |
q33833 | train | function(array, json) {
var i;
if (typeof json === 'object' && typeof json.length === 'number') {
for (i = 0; i < json.length; ++i) {
array.push(json[i]);
}
} else {
array.push(json);
}
} | javascript | {
"resource": ""
} | |
q33834 | train | function(sender, evt)
{
var cand = graph.getSelectionCellsForChanges(evt.getProperty('edit').changes);
var model = graph.getModel();
var cells = [];
for (var i = 0; i < cand.length; i++)
{
if ((model.isVertex(cand[i]) || model.isEdge(cand[i])) && graph.view.getState(cand[i]) != null)
{
cells.pus... | javascript | {
"resource": ""
} | |
q33835 | end | train | function end (next) {
filenames(dir, obj).forEach(function (filename) {
sm.emit('file', filename)
})
next()
} | javascript | {
"resource": ""
} |
q33836 | train | function(n){
if(typeof n === 'number'){
return n;
}
if(typeof n !== 'string'){
n = JSON.stringify(n)
}
var res = 0;
n.split("").map(function(bit){
res += bit.charCodeAt(0);
});
return res;
} | javascript | {
"resource": ""
} | |
q33837 | train | function(size){
this.data = [];
if(typeof size === 'undefined'){
return; // Empty instance of a bit array
}
if(typeof size !== 'number'){
size = shred(size);
}
for(var i=0; i<Math.ceil(size/INTEGER_SIZE); ++i){
this.data.push(0);
}
} | javascript | {
"resource": ""
} | |
q33838 | bridge_fetch | train | function bridge_fetch(size) {
var bridge_time = new JuttleMoment(last_seen_timestamp);
var time_filter = {term: {}};
time_filter.term[timeField] = bridge_time.valueOf();
var body = make_body(filter, null, null, direction, time_filter, size, timeField);
body.from = bridge_offset... | javascript | {
"resource": ""
} |
q33839 | drop_last_time_stamp_and_maybe_bridge_fetch | train | function drop_last_time_stamp_and_maybe_bridge_fetch(processed, size) {
if (processed.eof) { return processed; }
var last = _.last(processed.points);
last_seen_timestamp = last && last.time;
var non_simultaneous_points = processed.points.filter(function(pt) {
return pt.time ... | javascript | {
"resource": ""
} |
q33840 | makeDecoder | train | function makeDecoder(chunkType) {
if (chunkType === BUFFER) {
return function (buf) {
return buf.toString('utf8');
};
}
if (isnode) {
return function (a) {
return new Buffer(a).toString('utf8');
};
}
var decoder = null;
return function (buf) {
if (!decoder) {
decoder = new TextDecoder();
}
... | javascript | {
"resource": ""
} |
q33841 | train | function(signal1, signal2, options){
options = options || {};
options = _.defaults(options, defaultOptions);
// ensure signal2 is not longer than signal2
if(signal1.length < signal2.length){
var tmp = signal1;
signal1 = signal2;
signal2 = tmp;
}
if(options.method == "... | javascript | {
"resource": ""
} | |
q33842 | train | function(signal1, signal2, options){
options = options || {};
options.epsilon = options.epsilon || 1E-08;
var sig1 = Signal(signal1);
var sig2 = Signal(signal2);
if(signal1.length != signal2.length) return false;
var diffSQ = _.reduce(_.range(signal1.length), function(d,idx){
var diff = (s... | javascript | {
"resource": ""
} | |
q33843 | train | function(callback) {
log('Connecting...');
MongoClient.connect(dbUrl, dbOptions, function(err, dbConn) {
if(err) {
log('Cannot connect: ' + err);
callback(err);
return;
}
log('Connected!');
isConnected = true;
db = dbConn;
// http://stackoverflow.com/a/18715857... | javascript | {
"resource": ""
} | |
q33844 | train | function(node, msg) {
if (node.complete === "complete") {
return msg;
}
try {
return (node.prop||"payload").split(".").reduce(function (obj, i) {
return obj[i];
}, msg);
} catch (err) {
return; // undefined
}
} | javascript | {
"resource": ""
} | |
q33845 | hook | train | function hook(p, key) {
var h = function h(e) {
// update only when the argument is an Event object
if (e && e instanceof Event) {
// suppress updating on the inherit tag
e.preventUpdate = true;
// call original method
p[key](e);
// update automatically
p.... | javascript | {
"resource": ""
} |
q33846 | init | train | function init() {
var _this = this;
/** Store the keys originally belonging to the tag */
this.one('update', function () {
_this._ownPropKeys = getAllPropertyNames(_this);
_this._ownOptsKeys = getAllPropertyNames(_this.opts);
});
/** Inherit the properties from parents on ... | javascript | {
"resource": ""
} |
q33847 | querySelector | train | function querySelector(sel, flag) {
var node = this.root.querySelector(normalize(sel));
return !flag ? node : node._tag || undefined;
} | javascript | {
"resource": ""
} |
q33848 | querySelectorAll | train | function querySelectorAll(sel, flag) {
var nodes = this.root.querySelectorAll(normalize(sel));
return !flag ? nodes : Array.prototype.map.call(nodes, function (node) {
return node._tag || undefined;
});
} | javascript | {
"resource": ""
} |
q33849 | fragmentClick | train | function fragmentClick(e) {
var el = e.target;
var href;
while (el && el.nodeName !== 'HTML' && !el.getAttribute('data-render-html')) { el = el.parentNode };
if (el && (href = el.getAttribute('data-render-html'))) {
bindEditor(generator.fragment$[href]);
e.preventDefault(); // will also stop... | javascript | {
"resource": ""
} |
q33850 | bindEditor | train | function bindEditor(fragment) {
saveBreakHold();
if (fragment) {
editor.$name.text(fragment._href);
if (fragment._holdUpdates) {
editText(fragment._holdText);
}
else {
editText(fragment._hdr + fragment._txt);
}
editor.binding = fragment._href;
}
else {... | javascript | {
"resource": ""
} |
q33851 | editorUpdate | train | function editorUpdate() {
if (editor.binding) {
if ('hold' === generator.clientUpdateFragmentText(editor.binding, editor.$edit.val())) {
editor.holding = true;
}
}
} | javascript | {
"resource": ""
} |
q33852 | saveBreakHold | train | function saveBreakHold() {
if (editor.binding && editor.holding) {
generator.clientUpdateFragmentText(editor.binding, editor.$edit.val(), true);
editor.holding = false;
}
} | javascript | {
"resource": ""
} |
q33853 | train | function(type) {
//define if put type is present in config
if (config.moduleTypes.indexOf(type) > -1) {
config.moduleType = type;
fs.writeFile(path.resolve(__dirname, 'config.json'), JSON.stringify(config, null, 4), 'utf8', function (err) {
if (err) {
retu... | javascript | {
"resource": ""
} | |
q33854 | train | function(folder) {
var type = config.moduleType;
var appPath;
if (folder) {
if (path.isAbsolute(folder)) {
appPath = path.join(folder);
} else {
appPath = path.join(process.cwd(), folder);
}
} else {
appPath = path.join(process.cwd());
}
var appSrc = config.apps[type];
helpers.gitClone... | javascript | {
"resource": ""
} | |
q33855 | train | function (){
var offset = parseInt(self._utcoffset());
var minus = false;
if (offset < 0)
{
minus = true;
offset = -offset;
}
var minutes = offset % 60;
var hours = (offset - minutes) / 60;
o... | javascript | {
"resource": ""
} | |
q33856 | isFileOfType | train | async function isFileOfType(filename, condition){
try{
// get stats
const stats = await _fs.stat(filename);
// is directory ?
return condition(stats);
}catch(e){
// file not found error ?
if (e.code === 'ENOENT'){
return false;
}else{
... | javascript | {
"resource": ""
} |
q33857 | bulkCopy | train | async function bulkCopy(srcset, createDestinationDirs=true, defaultFilemode=0o750, defaultDirmode=0o777){
// create destination directories in advance ?
if (createDestinationDirs === true){
// get unique paths from filelist
const dstDirs = Array.from(new Set(srcset.map((set) => _path.dirname(set... | javascript | {
"resource": ""
} |
q33858 | isPrivateBrowsingMode | train | function isPrivateBrowsingMode () {
try {
localStorage.setItem(TEST_KEY, '1')
localStorage.removeItem(TEST_KEY)
return false
} catch (error) {
return true
}
} | javascript | {
"resource": ""
} |
q33859 | extractDomProperties | train | function extractDomProperties(domNode, regex, removeDomAttributes = false) {
if(regex && classof(regex) !== 'RegExp'){
throw Error('Second argument is passed but it must be a Regular-Expression');
}
let domViewAttributes = {};
let toBeRemovedAttributes = [];
for(let key in domNode.attributes) {
if(!domNode... | javascript | {
"resource": ""
} |
q33860 | Nello | train | function Nello(token)
{
if (!(this instanceof Nello))
return new Nello(token);
_events.call(this);
this.token = token;
if (!this.token)
throw new Error('Please check the arguments!');
} | javascript | {
"resource": ""
} |
q33861 | RotaryEncoder | train | function RotaryEncoder(pinA, pinB) {
this.gpioA = new Gpio(pinA, 'in', 'both');
this.gpioB = new Gpio(pinB, 'in', 'both');
this.a = 2;
this.b = 2;
this.gpioA.watch((err, value) => {
if (err) {
this.emit('error', err);
return;
}
this.a = value;
});
this.gpioB.watch((err, value) => {
if (err) {
... | javascript | {
"resource": ""
} |
q33862 | serve | train | function serve(res, file, maxAge) {
log.debug(`Serving: ${ file }`)
res.status(200)
.set('Cache-Control', `max-age=${ maxAge }`)
.sendFile(file, err => {
if (err) {
log.error(err)
res.status(err.status).end()
return
}
})
} | javascript | {
"resource": ""
} |
q33863 | find | train | function find(pathname, patterns) {
for (const entry of patterns)
if (minimatch(pathname, entry.pattern))
return entry.handler
return null
} | javascript | {
"resource": ""
} |
q33864 | FileInputStream | train | function FileInputStream(src){
// wrap into Promise
return new Promise(function(resolve, reject){
// open read stream
const istream = _fs.createReadStream(src);
istream.on('error', reject);
istream.on('open', function(){
resolve(istream);
});
});
} | javascript | {
"resource": ""
} |
q33865 | Auth | train | function Auth(clientId, clientSecret)
{
if (!(this instanceof Auth))
return new Auth(clientId, clientSecret);
this.clientId = clientId;
this.clientSecret = clientSecret;
if (!this.clientId || !this.clientSecret)
throw new Error('No Client ID / Client Secret provided!');
} | javascript | {
"resource": ""
} |
q33866 | isSymlink | train | async function isSymlink(filename){
try{
// get stats
const stats = await _fs.lstat(filename);
// is symlink ?
return stats.isSymbolicLink();
}catch(e){
// file not found error ?
if (e.code === 'ENOENT'){
return false;
}else{
throw... | javascript | {
"resource": ""
} |
q33867 | train | function(file, targetPath) {
rigger(
file,
{ output: targetPath},
function(error, content) {
if (error) {
console.log(error);
return;
}
fs.writeFile(targetPath, content, 'utf8');
}
);
} | javascript | {
"resource": ""
} | |
q33868 | renderJSON | train | function renderJSON( request, reply, err, result ){
if(err){
if(err.code === 404){
reply(new hapi.error.notFound(err.message));
}else{
reply(new hapi.error.badRequest(err.message));
}
}else{
reply(result).type('application/json; charset=utf-8');
}
} | javascript | {
"resource": ""
} |
q33869 | _initDefaultConnection | train | function _initDefaultConnection() {
if ('CLOUD_STORAGE_ACCOUNT' in process.env) {
var accountSettings = utils.parseAccountString(process.env.CLOUD_STORAGE_ACCOUNT);
if (accountSettings !== null) {
_defaultClientSetting = _.defaults(_defaultClientSetting, accountSettings);
}
}
} | javascript | {
"resource": ""
} |
q33870 | train | function (a, b) {
var Kernel = [0.05, 0.25, 0.4, 0.25, 0.05];
var width = this.getWidth();
var weight = this.getWeight();
//#pragma omp parallel for
for (var y = 0; y < weight; y++) {
for (var x = 0; x < width; x++) {
var index = y * width + x;
a[index] = 0;
for (var i = -2; i <= 2; i++) {
... | javascript | {
"resource": ""
} | |
q33871 | canonical | train | function canonical() {
var tags = document.getElementsByTagName('link');
// eslint-disable-next-line no-cond-assign
for (var i = 0, tag; tag = tags[i]; i++) {
if (tag.getAttribute('rel') === 'canonical') {
return tag.getAttribute('href');
}
}
} | javascript | {
"resource": ""
} |
q33872 | hasChanged | train | function hasChanged(depValues, current, dependencies) {
var len = dependencies.length;
var i = 0;
var result = false;
while (len--) {
var dep = dependencies[i++];
var value = get(current, dep);
if (get(depValues, dep) !== value) {
result = true;
set(depValues, dep, value);
}
}
re... | javascript | {
"resource": ""
} |
q33873 | initWatch | train | function initWatch(obj, depValues, dependencies) {
var len = dependencies.length;
if (len === 0) {
return false;
}
var i = 0;
while (len--) {
var dep = dependencies[i++];
var value = clone(get(obj, dep));
set(depValues, dep, value);
}
return true;
} | javascript | {
"resource": ""
} |
q33874 | timestamp | train | function timestamp(schema, options) {
options = options || {};
// Set defaults
options = Object.assign({
createdName: 'createdAt',
updatedName: 'updatedAt',
disableCreated: false,
disableUpdated: false
}, options);
// Add fields if not disabled
if (!options.disableCreated) {
addSchemaField(schema, opti... | javascript | {
"resource": ""
} |
q33875 | preSave | train | function preSave(next) {
const _ref = this.get(options.createdName);
if (!options.disableUpdated) {
this[options.updatedName] = new Date();
}
if (!options.disableCreated && (_ref === undefined || _ref === null)) {
this[options.createdName] = new Date();
}
next();
} | javascript | {
"resource": ""
} |
q33876 | train | function(key, path, next) {
this.fileSystem.get(key, function(err, data) {
fs.writeFile(path, data, function(err) {
if (err) {
console.log(err);
}
next(err, data);
});
});
} | javascript | {
"resource": ""
} | |
q33877 | train | function(next) {
var self = this;
var obj = {};
obj.path = path.join(os.tmpdir, randomstring.generate());
obj.original_name = self.document[self.has_attached_file].original_url.split('/').pop();
this.downloadUrl(self.document[self.has_attached_file].origi... | javascript | {
"resource": ""
} | |
q33878 | train | function (data, trans, key) {
if (typeof data[key] !== "object") {
throw new SyntaxError('Cannot extend a scalar value. Transform: ' + util.getTransDescription(trans) + ' Data: ' + JSON.stringify(data));
}
for (var prop in trans) {
if (typeof data[prop] === "object") {
return extend(data[key], ... | javascript | {
"resource": ""
} | |
q33879 | train | function (data, transform) {
if (typeof transform.jsontl !== "undefined") {
if (typeof transform.jsontl.transform !== "undefined") {
return locators.in(data, transform.jsontl.transform);
}
}
throw new Error("Tranform definition invalid");
} | javascript | {
"resource": ""
} | |
q33880 | gunzip | train | async function gunzip(input, dst){
// is input a filename or stream ?
if (typeof input === 'string'){
input = await _fileInputStream(input);
}
// decompress
const gzipStream = input.pipe(_zlib.createGunzip());
// write content to file
return _fileOutputStream(gzipStream, dst);
} | javascript | {
"resource": ""
} |
q33881 | targetComplete | train | function targetComplete(target) {
let complete = true;
Object.values(target).forEach((value) => {
if (value > 0)
complete = false;
});
return complete;
} | javascript | {
"resource": ""
} |
q33882 | guid | train | function guid() {
function _s4() {
return Math.floor(
(1 + Math.random()) * 0x10000
).toString(16).substring(1);
}
return _s4() + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + _s4() + _s4();
} | javascript | {
"resource": ""
} |
q33883 | getDecoratorTypeFromArguments | train | function getDecoratorTypeFromArguments(args) {
'use strict';
if (args.length === 0 || args.length > 3) {
return DecoratorType.None;
}
var kind = typeof (args.length === 1 ? args[0] : args[2]);
switch (kind) {
case 'function':
return DecoratorType.Class;
case 'numb... | javascript | {
"resource": ""
} |
q33884 | train | function( tagName, inputString ) {
let ret = inputString;
if ( ret.indexOf( '<' + tagName ) === -1 ) {
ret = `<${tagName}>${ret}`;
}
if ( ret.indexOf( '</' + tagName + '>' ) === -1 ) {
ret = `${ret}</${tagName}>`;
}
return ret;
} | javascript | {
"resource": ""
} | |
q33885 | variance | train | function variance(values) {
let avg = mean(values);
return mean(values.map((e) => Math.pow(e - avg, 2)));
} | javascript | {
"resource": ""
} |
q33886 | train | function (path, image) {
if (image instanceof Buffer) {
return Promise.denodeify(PNGImage.loadImage)(image);
} else if ((typeof path === 'string') && !image) {
return Promise.denodeify(PNGImage.readImage)(path);
} else {
return image;
}
} | javascript | {
"resource": ""
} | |
q33887 | fadeOutScreen | train | function fadeOutScreen(screen) {
var screenElement = document.querySelector(screen);
return Velocity(screenElement, {
opacity: 0,
}, {
display: "none",
duration: 500
});
} | javascript | {
"resource": ""
} |
q33888 | eat | train | function eat(expected) {
if (s[i] !== expected) {
throw new Error("bad JSURL syntax: expected " + expected + ", got " + (s && s[i]));
}
i++;
} | javascript | {
"resource": ""
} |
q33889 | decode | train | function decode() {
var beg = i;
var ch;
var r = "";
// iterate until we reach the end of the string or "~" or ")"
while (i < len && (ch = s[i]) !== "~" && ch !== ")") {
switch (ch) {
case "*":
if (b... | javascript | {
"resource": ""
} |
q33890 | train | function (_a) {
var _b = _a === void 0 ? {} : _a, baseDir = _b.baseDir, _c = _b.fontsPathToSave, fontsPathToSave = _c === void 0 ? process.cwd() + "/build/static/fonts/" : _c, _d = _b.iconUrl, iconUrl = _d === void 0 ? "https://at.alicdn.com/t/" : _d, _e = _b.fontReg, fontReg = _e === void 0 ? /@font-face{font-fami... | javascript | {
"resource": ""
} | |
q33891 | untar | train | async function untar(istream, dst){
// is destination a directory ?
if (!await _isDirectory(dst)){
throw Error('Destination is not a valid directory: ' + dst);
}
// get instance
const extract = _tar.extract();
// list of extracted files
const items = [];
// wrap into Promi... | javascript | {
"resource": ""
} |
q33892 | zipDirectory | train | function zipDirectory(directories, dest, callback) {
var archive = archiver.create('zip', {gzip: false});
// Where to write the file
var destStream = fs.createWriteStream(dest);
archive.on('error', function(err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Archi... | javascript | {
"resource": ""
} |
q33893 | encode | train | function encode(s) {
if (!/[^\w-.]/.test(s)) {
// if the string is only made up of alpha-numeric, underscore,
// dash or period, we can use it directly.
return s;
}
// we need to escape other characters
s = s.replac... | javascript | {
"resource": ""
} |
q33894 | setupTypedArray | train | function setupTypedArray(name, fallback) {
// check if TypedArray exists
// typeof on Minefield and Chrome return function, typeof on Webkit returns object.
if (typeof this[name] !== "function" && typeof this[name] !== "object") {
// nope.. check if WebGLArray exists
if (typeof this[fallback] === "functio... | javascript | {
"resource": ""
} |
q33895 | DFT | train | function DFT(bufferSize, sampleRate) {
FourierTransform.call(this, bufferSize, sampleRate);
var N = bufferSize/2 * bufferSize;
var TWO_PI = 2 * Math.PI;
this.sinTable = new Float32Array(N);
this.cosTable = new Float32Array(N);
for (var i = 0; i < N; i++) {
this.sinTable[i] = Math.sin(i * TWO_PI / buf... | javascript | {
"resource": ""
} |
q33896 | Oscillator | train | function Oscillator(type, frequency, amplitude, bufferSize, sampleRate) {
this.frequency = frequency;
this.amplitude = amplitude;
this.bufferSize = bufferSize;
this.sampleRate = sampleRate;
//this.pulseWidth = pulseWidth;
this.frameCount = 0;
this.waveTableLength = 2048;
this.cyclesPerSample = freq... | javascript | {
"resource": ""
} |
q33897 | checkLater | train | function checkLater() {
setTimeout(function () {
ctrl.options(ctrl.searchTerms, function (options) {
ctrl._options = options;
if (options.length === 0) checkLater();
$scope.$apply();
});
}, 1000);
} | javascript | {
"resource": ""
} |
q33898 | checksum | train | function checksum(src, algorithm='sha256', outputFormat='hex'){
return new Promise(async function(resolve, reject){
// hash engine
const hash = _crypto.createHash(algorithm);
// events
hash.on('readable', function(){
// get hashsum
const sum = hash.read();
... | javascript | {
"resource": ""
} |
q33899 | mkdirp | train | async function mkdirp(dir, mode=0o777, recursive=false){
// stats command executable ? dir/file exists
const stats = await _statx(dir);
// dir already exists ?
if (stats){
// check if its a directory
if (!stats.isDirectory()){
throw new Error('Requested directory <' + d... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.