_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q41700 | getCssSelectorClasses | train | function getCssSelectorClasses(selector) {
var list = []
var ast = cssSelector.parse(selector)
visitRules(ast, function(ruleSet) {
if (ruleSet.classNames) {
list = list.concat(ruleSet.classNames)
}
})
return uniq(list)
} | javascript | {
"resource": ""
} |
q41701 | loadScript | train | function loadScript(url) {
s = document.createElement('script');
s.src =url;
document.body.appendChild(s);
} | javascript | {
"resource": ""
} |
q41702 | Texture | train | function Texture(context, options) {
if (!(this instanceof Texture))
return new Texture(context, options);
//sets up base Kami object..
BaseObject.call(this, context);
/**
* When a texture is created, we keep track of the arguments provided to
* its constructor. On context loss and restore, these ... | javascript | {
"resource": ""
} |
q41703 | train | function(options) {
var gl = this.gl;
//If no options is provided... this method does nothing.
if (!options)
return;
// width, height, format, dataType, data, genMipmaps
//If 'src' is provided, try to load the image from a path...
if (options.src && typeof options.src==="string") {
var img = new Im... | javascript | {
"resource": ""
} | |
q41704 | train | function() {
if (this.id && this.gl)
this.gl.deleteTexture(this.id);
if (this.context)
this.context.removeManagedObject(this);
this.width = this.height = 0;
this.id = null;
this.managedArgs = null;
this.context = null;
this.gl = null;
} | javascript | {
"resource": ""
} | |
q41705 | train | function(s, t, ignoreBind) { //TODO: support R wrap mode
if (s && t) {
this.wrapS = s;
this.wrapT = t;
} else
this.wrapS = this.wrapT = s;
//enforce POT rules..
this._checkPOT();
if (!ignoreBind)
this.bind();
var gl = this.gl;
gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, this.wrapS)... | javascript | {
"resource": ""
} | |
q41706 | train | function(min, mag, ignoreBind) {
if (min && mag) {
this.minFilter = min;
this.magFilter = mag;
} else
this.minFilter = this.magFilter = min;
//enforce POT rules..
this._checkPOT();
if (!ignoreBind)
this.bind();
var gl = this.gl;
gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, this.... | javascript | {
"resource": ""
} | |
q41707 | train | function(width, height, format, type, data, genMipmaps) {
var gl = this.gl;
format = format || gl.RGBA;
type = type || gl.UNSIGNED_BYTE;
data = data || null; //make sure falsey value is null for texImage2D
this.width = (width || width==0) ? width : this.width;
this.height = (height || height==0) ? height ... | javascript | {
"resource": ""
} | |
q41708 | train | function(domObject, format, type, genMipmaps) {
var gl = this.gl;
format = format || gl.RGBA;
type = type || gl.UNSIGNED_BYTE;
this.width = domObject.width;
this.height = domObject.height;
this._checkPOT();
this.bind();
gl.texImage2D(this.target, 0, format, format,
type, domObject);
if ... | javascript | {
"resource": ""
} | |
q41709 | train | function() {
if (!Texture.FORCE_POT) {
//If minFilter is anything but LINEAR or NEAREST
//or if wrapS or wrapT are not CLAMP_TO_EDGE...
var wrongFilter = (this.minFilter !== Texture.Filter.LINEAR && this.minFilter !== Texture.Filter.NEAREST);
var wrongWrap = (this.wrapS !== Texture.Wrap.CLAMP_TO_EDGE || t... | javascript | {
"resource": ""
} | |
q41710 | ReportParameter | train | function ReportParameter(name, type, value) {
this.parameterTypes = [
"string",
"number",
"boolean",
"datetime",
"date",
"time"
];
this.name = name;
this.type = type;
this.value = value;
this.dependsOn = null; //use when you need cascading values
this.label = null; // display label
this.displa... | javascript | {
"resource": ""
} |
q41711 | sha2 | train | function sha2(str) {
var md = forge.md.sha256.create();
md.update(str);
return md.digest().toHex()
} | javascript | {
"resource": ""
} |
q41712 | hashToInts | train | function hashToInts(hash) {
var arr = []
var num = 4
for (var i = 0; i < 4; i++) {
var part = hash.substr(i*8,8)
var n = parseInt(part, 16) & 0x7fffffff
arr.push(n)
}
return arr
} | javascript | {
"resource": ""
} |
q41713 | mnemonicToPubKey | train | function mnemonicToPubKey(str) {
var m = new Mnemonic(str);
var xpriv1 = m.toHDPrivateKey(); // no passphrase
var xpub1 = xpriv1.hdPublicKey;
return xpub1
} | javascript | {
"resource": ""
} |
q41714 | webidAndPubKeyToAddress | train | function webidAndPubKeyToAddress(webid, pubKey, testnet) {
if (typeof(pubKey) === 'string') {
pubKey = new bitcore.HDPublicKey(pubKey)
}
var hash = sha2(webid)
var ints = hashToInts(hash)
var dep2 = pubKey.derive(ints[0]).derive(ints[1]).derive(ints[2]).derive(ints[3])
//console.log(dep2);
if (tes... | javascript | {
"resource": ""
} |
q41715 | webidAndPrivKeyToAddress | train | function webidAndPrivKeyToAddress(webid, privKey, testnet) {
if (typeof(privKey) === 'string') {
privKey = new bitcore.HDPrivateKey(privKey)
}
var hash = sha2(webid)
var ints = hashToInts(hash)
var dep2 = privKey.derive(ints[0]).derive(ints[1]).derive(ints[2]).derive(ints[3])
//console.log(dep2);
... | javascript | {
"resource": ""
} |
q41716 | train | function(server, opts) {
EventEmitter.call(this);
this.server = server;
this.wsprocessor = new WSProcessor();
this.tcpprocessor = new TCPProcessor(opts.closeMethod);
this.id = 1;
this.timeout = (opts.timeout || DEFAULT_TIMEOUT) * 1000;
this.setNoDelay = opts.setNoDelay;
if (!opts.ssl) {
this.server... | javascript | {
"resource": ""
} | |
q41717 | Namespace | train | function Namespace(path, hex) {
this.hex = !!hex
this.keyEncoding = hex ? 'utf8' : 'binary'
this.path = path
this.buffer = bytewise.encode(path)
this.prehooks = []
this.posthooks = []
} | javascript | {
"resource": ""
} |
q41718 | csv | train | function csv(input, delimiter) {
if (!input) return []
delimiter = delimiter || ','
var lines = toArray(input, /\r?\n/)
var first = lines.shift()
var header = toArray(first, delimiter)
var data = lines.map(function(line) {
var row = toArray(line, delimiter)
return toObject(row, header)
})
r... | javascript | {
"resource": ""
} |
q41719 | toArray | train | function toArray(line, delimiter) {
var arr = line
.split(delimiter)
.filter(Boolean)
return arr
} | javascript | {
"resource": ""
} |
q41720 | toObject | train | function toObject(row, header) {
var obj = {}
row.forEach(function(value, key) {
obj[header[key]] = value
})
return obj
} | javascript | {
"resource": ""
} |
q41721 | writeContractsFile | train | function writeContractsFile(contractsFilePath, contractsObject, callback) { // eslint-disable-line
if (typeof contractsFilePath !== 'string') {
return callback();
}
if (utils.filenameExtension(contractsFilePath) !== 'json') {
throw new Error('Your contracts output file must be a JSON file (i.e. --output ... | javascript | {
"resource": ""
} |
q41722 | writeStatsFile | train | function writeStatsFile(statsFilePath, statsObject, callback) { // eslint-disable-line
if (typeof statsFilePath !== 'string') {
return callback();
}
if (utils.filenameExtension(statsFilePath) !== 'json') {
throw new Error('Your stats output file must be a JSON file (i.e. --stats ./stats.json)');
}
f... | javascript | {
"resource": ""
} |
q41723 | makeCycleReactDriver | train | function makeCycleReactDriver(element, querySelector) {
if (typeof element === 'undefined') {
throw Error('Missing or invalid react element');
}
if (typeof querySelector !== 'string') {
throw new Error('Missing or invalid querySelector');
}
const source$ = new Rx.ReplaySubject();
const callback = ... | javascript | {
"resource": ""
} |
q41724 | train | function (callback, source, dest)
{
compressor.compress(
// Source can either be a file path or source code
source,
// Options
{
charset: 'utf8',
type: 'js',
nomunge: true,
'preserve-semi': true
... | javascript | {
"resource": ""
} | |
q41725 | train | function(task, pid) {
this.task = task;
this.pid = pid;
this.failedCount = 0;
this.buffer = '';
this.exitCode = -1;
this.insertTag = true;
} | javascript | {
"resource": ""
} | |
q41726 | get_db | train | function get_db (ent, done) {
var folder = internals.makefolderpath(opts.folder, ent)
var db = dbmap[folder]
if (db) {
return done(null, db)
}
internals.ensurefolder(folder, internals.error(done, function () {
db = dbmap[folder]
if (db) {
return done(null, db)
}
... | javascript | {
"resource": ""
} |
q41727 | crosshair | train | function crosshair(g) {
var group = g.selectAll('g.data.top').data([change], function(d) { return d; }),
groupEnter = group.enter(),
dataEnter = groupEnter.append('g').attr('class', 'data top').style('display', 'none');
group.exit().remove();
dataEnter.append('path').attr('class'... | javascript | {
"resource": ""
} |
q41728 | Component | train | function Component (props) {
this._parent = null
this._collector = { refs: [], components: [] }
/**
* > Contains all component properties and children. <br>
* > Do not modify it directly, but recreate a new component using `cloneElement` instead
* @type {object}
* @category Properties
*/
this.pr... | javascript | {
"resource": ""
} |
q41729 | Jusibe | train | function Jusibe(publicKey, accessToken) {
if (!(publicKey || accessToken)) {
throw new Error('Provide both Jusibe PUBLIC_KEY and ACCESS_TOKEN');
}
if (!(this instanceof Jusibe)) {
return new Jusibe(publicKey, accessToken);
}
this.options = {
auth: {
user: publicKey,
pass: accessToken... | javascript | {
"resource": ""
} |
q41730 | train | function(opts){
//setup options
this.opts = new ObjectManage({
username: '',
password: '',
domain: 'cdn.oose.io',
prism: {
host: null,
port: 5971
}
})
this.opts.$load(opts)
//set properties
this.api = {}
this.authenticated = false
this.connected = false
this.session = {... | javascript | {
"resource": ""
} | |
q41731 | ensureTimestamps | train | function ensureTimestamps(columns, allowSyncedAt) {
var now = Date.now();
if (!allowSyncedAt || !columns.syncedAt) {
columns.syncedAt = now;
}
if (!columns.createdAt) {
// Take the value from the client, if present:
columns.createdAt = columns.updatedAt;
}
} | javascript | {
"resource": ""
} |
q41732 | _queryForTargetSessions | train | function _queryForTargetSessions(url, minDbSeq) {
var where = { isConnected: true };
if (minDbSeq) {
where.connectedAtDbSeq = { gt: minDbSeq };
}
return Session.findAll({
where: where,
attributes: [
'sessionId',
'connectedAtDbSeq',
],
include... | javascript | {
"resource": ""
} |
q41733 | _filter | train | function _filter(data, schema) {
if (typeof data !== 'object' ||
data === null ||
schema === null) {
return data;
}
if (schema instanceof Array) {
return _filterByArraySchema(data, schema);
}
if (typeof schema === 'object') {
return _filterByObjectSchema(data,... | javascript | {
"resource": ""
} |
q41734 | _filterByArraySchema | train | function _filterByArraySchema(data, schema) {
return Object
.keys(data)
.filter(function (key) {
return !!~schema.indexOf(key);
})
.reduce(function (memo, key) {
memo[key] = data[key];
return memo;
}, {});
} | javascript | {
"resource": ""
} |
q41735 | _filterByObjectSchema | train | function _filterByObjectSchema(data, schema) {
return Object
.keys(data)
.filter(function (key) {
return schema.hasOwnProperty(key);
})
.reduce(function (memo, key) {
var value = data[key];
var schemaPart = schema[key];
if (typeof schem... | javascript | {
"resource": ""
} |
q41736 | Fixed2DArray | train | function Fixed2DArray(rows, cols, defaultValue) {
if(rows <= 0 || cols <= 0){
throw new Error('fixed-2d-array: Must have more then 0 rows and 0 columns.');
}
this._width = cols;
this._height = rows;
this._grid = [];
for (var i = 0; i < rows; i++) {
this._grid[i] = [];
for (var j = 0; j < cols;... | javascript | {
"resource": ""
} |
q41737 | exec | train | function exec() {
var actions = {
commands: {
init: { action: _init },
run : { action: _run }
}
};
cli.command(__dirname, actions);
} | javascript | {
"resource": ""
} |
q41738 | parse | train | function parse(content, options) {
options = options || {};
options = defaults(options, {
addEsprimaInfo: false,
parseJsDocTags: true,
hideJsDocTags: true,
trim: true
});
var comments = [];
var ast = esprima.parse(content, {
tolerant: true,
comment: true,
tokens: true,
... | javascript | {
"resource": ""
} |
q41739 | formatLines | train | function formatLines(lines, jsDoc, trim) {
jsDoc = undefined === jsDoc || true;
trim = undefined === trim || true;
lines = lines.slice();
for (var i = 0; i < lines.length; i++) {
var line = lines[i] + '';
if (jsDoc) {
line = line.replace(/^\s*\*/, '');
}
if ('right' === trim) {
... | javascript | {
"resource": ""
} |
q41740 | applyJsDocTags | train | function applyJsDocTags(comment, removeTagLine) {
removeTagLine = (undefined !== removeTagLine) ? removeTagLine : true;
var lines = [];
comment.tags = [];
for (var i = 0; i < comment.lines.length; i++) {
var line = comment.lines[i];
if ('@' === line.charAt(0)) {
var spacePos = line.indexOf(' ');... | javascript | {
"resource": ""
} |
q41741 | defaults | train | function defaults(object, options) {
object = object || {};
for (var i in options) {
if (undefined === object[i] && options.hasOwnProperty(i)) {
object[i] = options[i];
}
}
return object;
} | javascript | {
"resource": ""
} |
q41742 | matter | train | function matter(str, opts) {
str = formatString(str);
opts = formatOptions(opts);
var result = {src: str, data: null, body: str};
if (!str) {
return result;
}
var strict = !opts.loose;
var header = opts.delims[0];
var footer = opts.delims[1];
var dataStart, dataEnd;
// Front matter must start ... | javascript | {
"resource": ""
} |
q41743 | train | function (classesSource)
{
this.e.log&&this.e.log('Importing core classes...','system');
var classesSource = classesSource||global.wns.coreClasses;
var classBuilder = new process.wns.wnBuild(classesSource,this);
this.setComponent('classBuilder',classBuilder);
classBuilder.build();
return this;
} | javascript | {
"resource": ""
} | |
q41744 | train | function ()
{
var nmPath = this.modulePath + 'node_modules/';
var pkgJson;
var pkgName;
var pkgInfo;
var packageList = {};
var validScript = /[\w|\W]+\.[js|coffee]+$/;
if (fs.existsSync(nmPath))
{
this.e.log&&this.e.log('Importing packages...','system');
var packages = fs.readdirSync(n... | javascript | {
"resource": ""
} | |
q41745 | train | function (packageList)
{
if (!_.isObject(packageList))
return false;
var pkgList = _.keys(packageList);
var pkgRequire;
var pkgName;
var pkgInfo;
var depName;
var depVersion;
var i=0;
var valid;
var error;
while (pkgList.length > 0)
{
valid=true;
error=[];
pkgName=... | javascript | {
"resource": ""
} | |
q41746 | train | function (packageList)
{
var classes;
var className;
var classSource;
var classBuilder = this.getComponent('classBuilder');
for (p in packageList)
{
classes = packageList[p].classes;
for (c in classes)
{
className = c;
classBuilder.addSource(className,classes[c],true);
}
... | javascript | {
"resource": ""
} | |
q41747 | train | function ()
{
this.e.log&&this.e.log('Importing from config...','system');
var importConfig = this.getConfig('import');
var cb = this.getComponent('classBuilder');
var validScript = /[\w|\W]+\.[js|coffee]+$/;
for (i in importConfig)
{
var path = this.modulePath+importConfig[i];
if (fs.exist... | javascript | {
"resource": ""
} | |
q41748 | train | function ()
{
for (c in this.c)
{
if (this.c[c].build && this.c[c].build.extend && this.c[c].build.extend.indexOf('wnActiveRecord')!=-1)
{
this.prepareModel(c);
}
}
} | javascript | {
"resource": ""
} | |
q41749 | train | function (model) {
var c = this.c,
s = this;
this.m[model]=function () {
var modelClass = c[model];
return new modelClass({ autoInit: true }, s.c, s, s.db);
};
} | javascript | {
"resource": ""
} | |
q41750 | train | function (file)
{
if (!_.isString(file))
return false;
var file = file+'';
this.e.log&&this.e.log('Loading module configuration from file: '+file,'system');
if (fs.statSync(file).isFile() && path.extname(file) == '.json')
{
var _data = (fs.readFileSync(file,'utf8').toString())
.replace(... | javascript | {
"resource": ""
} | |
q41751 | train | function (components)
{
for (c in components)
{
_componentsConfig[c]=_.merge({}, components[c]);
if (this.hasComponent(c))
_.merge(_componentsConfig[c],this.getComponentsConfig[c]);
}
return this;
} | javascript | {
"resource": ""
} | |
q41752 | train | function (className,config)
{
var component = this.createClass(className,config);
if (component)
component.setParent(this);
return component;
} | javascript | {
"resource": ""
} | |
q41753 | train | function ()
{
this.setConfig({components: this.preload});
var preload = this.getConfig().components;
if (preload != undefined)
{
this.setComponents(preload);
}
return this;
} | javascript | {
"resource": ""
} | |
q41754 | train | function ()
{
var cps=this.getComponentsConfig();
for (c in cps)
{
var cpnt=this.getComponent(c);
if (cpnt)
this.e.log&&this.e.log('- Started component: '+cps[c].class+(cpnt.getConfig('alias')?' (as '+cpnt.getConfig('alias')+')':''),'system');
}
return this;
} | javascript | {
"resource": ""
} | |
q41755 | train | function (modules)
{
for (m in modules)
{
_modulesConfig[m]=_.merge({}, modules[m]);
if (this.hasModule(m))
_.merge(_modulesConfig[m],this.getModulesConfig[m]);
}
return this;
} | javascript | {
"resource": ""
} | |
q41756 | train | function (id,onLoad)
{
if (_modules[id] != undefined)
return _modules[id];
else if (this.hasComponent('classBuilder'))
{
try {
var config = _modulesConfig[id] || {},
modulePath = config.modulePath || id,
className = config.class;
if (fs.existsSync(this.modulePath+modulePath) &&... | javascript | {
"resource": ""
} | |
q41757 | train | function (className,config,modulePath,npmPath)
{
var module = this.createClass(className,config,modulePath,npmPath);
return module;
} | javascript | {
"resource": ""
} | |
q41758 | train | function (id) {
if (!_.isString(id))
return false;
var module = this.getModule(id),
events;
this.e.log&&this.e.log("Attaching module's events...",'system');
if (module != undefined && (events=module.getEvents()) && !_.isEmpty(events)) {
for (e in events)
{
var evtConfig = {},
eve... | javascript | {
"resource": ""
} | |
q41759 | train | function (scripts)
{
var script = {};
for (s in scripts)
{
var ref=scripts[s],
scriptName = s.substr(0,1).toUpperCase()+s.substr(1).toLowerCase(),
s = 'script-'+s.replace('-','.');
script[s]=ref;
script[s].class='wnScript'+scriptName || 'wnScript';
_componentsConfig[s]=_.merge({}, s... | javascript | {
"resource": ""
} | |
q41760 | train | function (value)
{
if (value != undefined && fs.statSync(value).isDirectory())
{
this.modulePath = value;
this.setConfig('modulePath',value);
}
return this;
} | javascript | {
"resource": ""
} | |
q41761 | MicroserviceClient | train | function MicroserviceClient(settings) {
var self = this;
self.settings = settings;
self.get = bind(self.get, self);
self.post = bind(self.post, self);
self.put = bind(self.put, self);
self.delete = bind(self.delete, self);
self.search = bind(self.search, self);
self._request = bind(self._request, self);... | javascript | {
"resource": ""
} |
q41762 | buildHandler | train | function buildHandler(overrides) {
const parseError = buildHandler.parseError;
const buildError = buildHandler.buildError;
/**
* .
*/
return function handler(error) {
const found = parseError.apply(this, arguments);
if (!found) {
if (error instanceof Error) {
Error.captureStackTrace... | javascript | {
"resource": ""
} |
q41763 | train | function (string) {
color = chalk.cyan;
if (args.verbose) {
if (typeof string === "string") {
console.log(color(string));
}
if (isArray(string)) {
console.log(color(arrayToString(string)));
}
}
return this;
} | javascript | {
"resource": ""
} | |
q41764 | addListener | train | function addListener(name) {
if (name !== 'collect') {
return;
}
if (this._collecting) {
// Don't add more than once
return;
}
debug('adding collect method', this._readableState.objectMode, this._readableState.encoding);
let collected;
if (this._readableState.objectMode) {
collected = [... | javascript | {
"resource": ""
} |
q41765 | addToStream | train | function addToStream(stream) {
// Don't add more than once
if (stream.listeners('addListener').includes(addListener)) {
return stream;
}
stream.on('newListener', addListener);
return stream;
} | javascript | {
"resource": ""
} |
q41766 | collect | train | function collect(stream, encoding, cb = () => {}) {
if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
return stream
.pipe(new Collect({ encoding, objectMode: stream._readableState.objectMode }))
.collect()
.then((data) => {
cb(null, data);
return data;
})... | javascript | {
"resource": ""
} |
q41767 | ObiCallerID | train | function ObiCallerID() {
this.fromRegex = /^INVITE[\S\s]*From:\s*"?([\w\s\.\+\?\$]*?)"?<sip:((.*)@)?(.*)>;.*/;
this.cidRegex = /<7> \[SLIC\] CID to deliver: '([\w\s\.\+\?\$]*?)' (\d*).*/;
this.cnams = {};
this.lastSentTime = new Date();
this.outlookImported = false;
this.addressbookImported = fa... | javascript | {
"resource": ""
} |
q41768 | SallyWriter | train | function SallyWriter(opts)
{
this.sally = require('./sally');
opts = opts || {};
this.path = opts.path || 'sally.log';
this.prefix = opts.prefix || '';
this.digest = undefined;
this.onLog = this.onLog.bind(this);
this.onEpochStart = this.onEpochStart.bind(this);
this.onEpochEnd = this.onEpochEnd.bin... | javascript | {
"resource": ""
} |
q41769 | train | function(client, app, sinfos) {
let item;
for (let i = 0, l = sinfos.length; i < l; i++) {
item = sinfos[i];
if (hasProxy(client, item)) {
continue;
}
client.addProxies(getProxyRecords(app, item));
}
} | javascript | {
"resource": ""
} | |
q41770 | train | function(client, sinfo) {
let proxy = client.proxies;
return !!proxy.sys && !! proxy.sys[sinfo.serverType];
} | javascript | {
"resource": ""
} | |
q41771 | train | function(app, sinfo) {
let records = [],
appBase = app.getBase(),
record;
// sys remote service path record
if (app.isFrontend(sinfo)) {
record = pathUtil.getSysRemotePath('frontend');
} else {
record = pathUtil.getSysRemotePath('backend');
}
if (record) {
records.push(pathUtil.remotePat... | javascript | {
"resource": ""
} | |
q41772 | snapToWord | train | function snapToWord() {
if (isHighlighted()) {
throw new Error("Can't modify range after highlighting");
}
var start = selection.range.startOffset;
var startNode = selection.range.startContainer;
while (startNode.textContent.charAt(start) != ' ' && start > 0) {
... | javascript | {
"resource": ""
} |
q41773 | removeHighlight | train | function removeHighlight() {
for (var h in selection._highlighter) {
var highlighter = selection._highlighter[h];
var parent = highlighter.parentNode;
while (highlighter.firstChild) {
parent.insertBefore(highlighter.firstChild, highlighter);
}
paren... | javascript | {
"resource": ""
} |
q41774 | shard | train | function shard() {
var treeNode = new RangeTreeNode();
treeNode.setStart(range.startContainer, range.startOffset);
var current = range.startContainer;
var distance = 0;
while (current != range.endContainer && distance < 50) {
var last = current;
if (current... | javascript | {
"resource": ""
} |
q41775 | getFingerprintsForAnimal | train | function getFingerprintsForAnimal(animalDir) {
if (!fs.existsSync(animalDir) || !fs.statSync(animalDir).isDirectory()) {
return false;
}
var fgpFiles = fs.readdirSync(animalDir).filter(function (entry) {
return entry.split('.').pop().toLowerCase() == 'fgp';
});
var fgps = [];
fgpFiles.forEach(function (fgpF... | javascript | {
"resource": ""
} |
q41776 | getAllFingerprints | train | function getAllFingerprints(dir) {
var ids = getAnimals();
var fgps = ids.map(function (id) {
return getFingerprintsForAnimal(path.join(dir, id));
}).filter(function (fgp) { return fgp; });
return fgps;
} | javascript | {
"resource": ""
} |
q41777 | getAnimals | train | function getAnimals(dir) {
var ids = fs.readdirSync(dir).filter(function (id) {
return fs.statSync(path.join(dir, id)).isDirectory();
});
return ids;
} | javascript | {
"resource": ""
} |
q41778 | moveCursorRelative | train | function moveCursorRelative(stream, dx, dy) {
if (dx < 0) {
stream.write('\x1b[' + (-dx) + 'D');
} else if (dx > 0) {
stream.write('\x1b[' + dx + 'C');
}
if (dy < 0) {
stream.write('\x1b[' + (-dy) + 'A');
} else if (dy > 0) {
stream.write('\x1b[' + dy + 'B');
}
} | javascript | {
"resource": ""
} |
q41779 | createValidationErrorMessages | train | function createValidationErrorMessages(base, subjDef) {
if (!subjDef.validationErrorMessages &&
(base !== standard.VALIDATION_ERROR_MESSAGES))
return base;
const validationErrorMessages = Object.create(base);
for (let messageId in subjDef.validationErrorMessages) {
const messageDef = subjDef.validationErrorM... | javascript | {
"resource": ""
} |
q41780 | createValidatorFuncs | train | function createValidatorFuncs(base, subjDef, subjDescription) {
if (!subjDef.validatorDefs && (base !== standard.VALIDATOR_DEFS))
return base;
const validatorFuncs = Object.create(base);
for (let validatorId in subjDef.validatorDefs) {
const validatorFunc = subjDef.validatorDefs[validatorId];
if ((typeof val... | javascript | {
"resource": ""
} |
q41781 | train | function (num, uppercase) {
var digits = String(+num).split(""),
key = ["","c","cc","ccc","cd","d","dc","dcc","dccc","cm",
"","x","xx","xxx","xl","l","lx","lxx","lxxx","xc",
"","i","ii","iii","iv","v","vi","vii","viii","ix"],
roman = "",
i = 3;
while (i--)
... | javascript | {
"resource": ""
} | |
q41782 | getMimeType | train | function getMimeType (media) {
return new Promise((resolve, reject) => {
if (isFile(media)) {
typechecker.detectFile(media, (err, result) => {
err && reject(err)
resolve(result)
})
} else if (isBuffer(media)) {
typechecker.detect(media, (err, result) => {
err && rejec... | javascript | {
"resource": ""
} |
q41783 | isImage | train | function isImage (path) {
return new Promise((resolve, reject) => {
getMimeType(path)
.then((type) => {
;(type.indexOf('image') > -1) ? resolve(true) : resolve(false)
})
.catch(err => reject(err))
})
} | javascript | {
"resource": ""
} |
q41784 | urlToBase64 | train | function urlToBase64 (url) {
return new Promise((resolve, reject) => {
request.get(url, (err, response, body) => {
err && reject(err)
resolve(body.toString('base64'))
})
})
} | javascript | {
"resource": ""
} |
q41785 | toBase64 | train | function toBase64 (media) {
return new Promise((resolve, reject) => {
if (isBase64(media)) {
resolve(media)
} else if (isURL(media)) {
urlToBase64(media)
.then(data => resolve(data))
.catch(error => reject(error))
} else if (isFile(media)) {
fileToBase64(media)
.then(da... | javascript | {
"resource": ""
} |
q41786 | toBuffer | train | function toBuffer (media) {
return new Promise((resolve, reject) => {
if (isURL(media)) {
toBase64(media)
.then(data => {
toBuffer(data)
.then(data => resolve(data))
.catch(error => reject(error))
})
.catch(error => reject(error))
} else if (isBase64(media)) {
... | javascript | {
"resource": ""
} |
q41787 | translateDateTimestamp | train | function translateDateTimestamp(timestamp) {
if (!timestamp) {
LOG.warn("Received an invalid timestamp: {}", timestamp);
return Date.now();
}
return new Date(timestamp);
} | javascript | {
"resource": ""
} |
q41788 | translateRole | train | function translateRole(role) {
switch (role) {
case "5615fa9ae596154a5c000000":
return Types.UserRole.COOWNER;
case "5615fd84e596150061000003":
return Types.UserRole.MANAGER;
case "52d1ce33c38a06510c000001":
return Types.UserRole.MOD;
case "5615fe1... | javascript | {
"resource": ""
} |
q41789 | Basic | train | function Basic(client, channel, done){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
this.publishCallbackMethod = DEFAULT_PUBLISH_ANSWER_WAIT_MECHANISM;
this.timeout = DEFAULT_WAIT_TIMEOUT;
this.lastConfirmSendId = 1;
this.lastMessageId = 1;
this.done = done... | javascript | {
"resource": ""
} |
q41790 | getJSFiles | train | function getJSFiles(folder = srcFolder){
let all = [];
let f = fs.readdirSync(folder);
for(file of f){
all.push(path.join(folder,file))
if(fs.lstatSync(path.join(folder,file)).isDirectory()){
all = all.concat(getJSFiles(path.join(folder,file)));
}
}
return all.filter(x => x.endsWith('.js'));... | javascript | {
"resource": ""
} |
q41791 | Sweep | train | function Sweep(actor, context) {
this.actor = actor;
this.context = context;
this.prev = context.actors[actor] || {};
this.resources = context.actors[actor] = {};
} | javascript | {
"resource": ""
} |
q41792 | session | train | function session(options) {
options = options || {};
DEBUG && debug('configure http session middleware', options);
if (options.store) {
try {
var storeModule = options.store.module;
var SessionStore = require(storeModule)(express);
// replace store options with st... | javascript | {
"resource": ""
} |
q41793 | forEachDesc | train | function forEachDesc(obj, fn) {
var names = Object.getOwnPropertyNames(obj);
for (var i$0 = 0; i$0 < names.length; ++i$0)
fn(names[i$0], Object.getOwnPropertyDescriptor(obj, names[i$0]));
names = Object.getOwnPropertySymbols(obj);
for (var i$1 = 0; i$1 < names.length; ++i$1)
fn(names... | javascript | {
"resource": ""
} |
q41794 | mergeProperty | train | function mergeProperty(target, name, desc, enumerable) {
if (desc.get || desc.set) {
var d$0 = { configurable: true };
if (desc.get) d$0.get = desc.get;
if (desc.set) d$0.set = desc.set;
desc = d$0;
}
desc.enumerable = enumerable;
Object.defineProperty(target, name, de... | javascript | {
"resource": ""
} |
q41795 | mergeProperties | train | function mergeProperties(target, source, enumerable) {
forEachDesc(source, function(name, desc) { return mergeProperty(target, name, desc, enumerable); });
} | javascript | {
"resource": ""
} |
q41796 | buildClass | train | function buildClass(base, def) {
var parent;
if (def === void 0) {
// If no base class is specified, then Object.prototype
// is the parent prototype
def = base;
base = null;
parent = Object.prototype;
} else if (base === null) {
// If the base is null, t... | javascript | {
"resource": ""
} |
q41797 | train | function(target) {
for (var i$2 = 1; i$2 < arguments.length; i$2 += 3) {
var desc$0 = Object.getOwnPropertyDescriptor(arguments[i$2 + 1], "_");
mergeProperty(target, arguments[i$2], desc$0, true);
if (i$2 + 2 < arguments.length)
mergeProperties(target, argu... | javascript | {
"resource": ""
} | |
q41798 | train | function(iter) {
var front = null, back = null;
return _esdown.computed({
next: function(val) { return send("next", val) },
throw: function(val) { return send("throw", val) },
return: function(val) { return send("return", val) },
}, Symbol.asyncIterator... | javascript | {
"resource": ""
} | |
q41799 | train | function(initial) {
return {
a: initial || [],
// Add items
s: function() {
for (var i$3 = 0; i$3 < arguments.length; ++i$3)
this.a.push(arguments[i$3]);
return this;
},
// Add the contents of i... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.