_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 27 233k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q42400 | train | function(size) {
size = size || 1;
var numChunks = Math.ceil(this.length / size);
var result = new Array(numChunks);
for (var i = 0, index = 0; i < numChunks; i++) | javascript | {
"resource": ""
} | |
q42401 | train | function() {
var result = [];
for (var i = 0; i < this.length; i++) {
var value = this[i];
if (Array.isArray(value)) {
for (var j = 0; j < value.length; j++) | javascript | {
"resource": ""
} | |
q42402 | train | function() {
var remStartIndex = 0;
var numToRemove = 0;
for (var i = 0; i < this.length; i++) {
var removeCurrentIndex = false;
for (var j = 0; j < arguments.length; j++) {
if (this[i] === arguments[j]) {
removeCurrentIndex = true;
break;
}
}
i... | javascript | {
"resource": ""
} | |
q42403 | train | function(isSorted) {
var result = [];
var length = this.length;
if (!length) {
return result;
}
result[0] = this[0];
var i = 1;
if (isSorted) {
for (; i < length; | javascript | {
"resource": ""
} | |
q42404 | train | function() {
var result = [];
next: for (var i = 0; i < this.length; i++) {
for (var j = 0; j < arguments.length; j++) {
if (this[i] === arguments[j]) {
| javascript | {
"resource": ""
} | |
q42405 | flattenArray | train | function flattenArray(arrayToFlatten, arrayFlatten) {
// check if the arg is a array, if not a error is thrown
if(!Array.isArray(arrayToFlatten)) throw new Error('Only can flat arrays and you pass a ' + typeof arrayToFlatten)
// set the default value of arrayFlatten, this validation is used only in the firs... | javascript | {
"resource": ""
} |
q42406 | nextQuestion | train | function nextQuestion() {
if ( !hooks.length ) {
if ( !!options.onDone ) {
grunt.log.writeln( '' );
grunt.log.writeln( options.onDone.blue );
}
done();
| javascript | {
"resource": ""
} |
q42407 | actuallyInstallHook | train | function actuallyInstallHook(
hookToCopy,
whereToPutIt,
sourceCanonicalName
) {
mkpath.sync( path.join( './', path.dirname( whereToPutIt ) ) );
exec( 'cp ' + hookToCopy + ' ' + whereToPutIt ); | javascript | {
"resource": ""
} |
q42408 | train | function(e) {
var touch = e.touches[0]
// Make sure click doesn't | javascript | {
"resource": ""
} | |
q42409 | login | train | function login(){
console.log('Login called');
var username = document.getElementById('login-username').value;
var password = document.getElementById('login-password').value;
// | javascript | {
"resource": ""
} |
q42410 | logout | train | function logout(){
console.log('Logout called');
grout.logout().then(function(){
console.log('successful logout');
setStatus();
| javascript | {
"resource": ""
} |
q42411 | signup | train | function signup(){
console.log('signup called');
var name = document.getElementById('signup-name').value;
var username = document.getElementById('signup-username').value;
var email = document.getElementById('signup-email').value;
var password = document.getElementById('signup-password').value;
| javascript | {
"resource": ""
} |
q42412 | getProjects | train | function getProjects(){
console.log('getProjects called');
grout.Projects.get().then(function(appsList){
console.log('apps list loaded:', appsList);
var outHtml = '<h2>No app data</h2>';
if (appsList) {
outHtml = '<ul>';
appsList.forEach(function(app){
| javascript | {
"resource": ""
} |
q42413 | getFile | train | function getFile() {
var file = grout.Project('test', 'scott').File({key: 'index.html', path: 'index.html'});
console.log('fbUrl', file.fbUrl);
| javascript | {
"resource": ""
} |
q42414 | getUsers | train | function getUsers(){
console.log('getUsers called');
grout.Users.get().then(function(app){
console.log('apps list loaded:', app);
| javascript | {
"resource": ""
} |
q42415 | searchUsers | train | function searchUsers(searchStr){
console.log('getUsers called');
if(!searchStr){
searchStr = document.getElementById('search').value;
}
grout.Users.search(searchStr).then(function(users){
console.log('search users | javascript | {
"resource": ""
} |
q42416 | write | train | function write(msg, color, prefix) {
if (!prefix)
prefix = clc.cyan('[conquer]');
// Print each line of the message on its own line.
var messages = msg.split('\n');
for (var i = 0; i < messages.length; i++) {
var message = | javascript | {
"resource": ""
} |
q42417 | log | train | function log() {
var msg = util.format.apply(null, | javascript | {
"resource": ""
} |
q42418 | warn | train | function warn() {
var msg = util.format.apply(null, | javascript | {
"resource": ""
} |
q42419 | error | train | function error() {
var msg = util.format.apply(null, | javascript | {
"resource": ""
} |
q42420 | scriptLog | train | function scriptLog(script, msg, isError) {
write(msg,
isError ? clc.red : null, | javascript | {
"resource": ""
} |
q42421 | Plugin | train | function Plugin(element, options, jsonData) {
// same the DOM element.
this.element = element;
this.jsonData = jsonData;
// merge the options.
// the jQuery extend | javascript | {
"resource": ""
} |
q42422 | train | function(options, jsonData) {
//console.log(jsonData);
var self = this;
// remove the existing one.
$('#' + self.attrId).empty();
// need merge the options with default options.
self.options | javascript | {
"resource": ""
} | |
q42423 | train | function() {
var self = this;
var bsExplanation = '';
if(self.options.explanationBuilder) {
// call customized explanation builder.
| javascript | {
"resource": ""
} | |
q42424 | train | function() {
var self = this;
// calculate the location and offset.
// the largest rectangle that can be inscribed in a
// circle is a square.
// calculate the offset for the center of the chart.
var offset = $('#' + self.getGenericId('svg')).... | javascript | {
"resource": ""
} | |
q42425 | train | function(p) {
var self = this;
if (p.depth > 1) p = p.parent;
// no children
if (!p.children) return;
| javascript | {
"resource": ""
} | |
q42426 | train | function(pageviews, name) {
var self = this;
$("#" + self.getGenericId('pageviews'))
.text(self.formatNumber(pageviews));
| javascript | {
"resource": ""
} | |
q42427 | train | function(p) {
var self = this;
if (!p) return;
if (!p.parent) return;
//console.log("zoom out p.value = " + p.parent.value); | javascript | {
"resource": ""
} | |
q42428 | onFile | train | function onFile(filePath, stat) {
if (filePath.match(ignore) || filePath.match(globalIgnore)) { return; }
var newTimestamp = updateTimestamp(stat.mtime);
| javascript | {
"resource": ""
} |
q42429 | filterPrompts | train | function filterPrompts( PromptAnswers, generator_prompts ) {
return filter(
generator_prompts,
| javascript | {
"resource": ""
} |
q42430 | Through | train | function Through (options, transform, flush) {
var self = this
if (!(this instanceof Through)) {
return new Through(options, transform, flush)
}
if (typeof options === 'function') {
flush = transform
transform = options
options = {}
}
options = options || {}
Transform.call(this, options... | javascript | {
"resource": ""
} |
q42431 | finishSpec | train | function finishSpec(spec, opts, field) {
if (opts.unique) {
var keylength = parseInt(opts.unique, 10) ? opts.unique : undefined;
if (opts.unique === true && spec.sql.match(/^(text|blob)/i)) {
var msg = 'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g... | javascript | {
"resource": ""
} |
q42432 | pprintSEXP | train | function pprintSEXP(formJson, opts, indentLevel, priorNodeStr) {
opts = opts || {};
opts.lbracket = | javascript | {
"resource": ""
} |
q42433 | isQuotedString | train | function isQuotedString(str) {
var is = false;
if(typeof str === 'string') { | javascript | {
"resource": ""
} |
q42434 | stripQuotes | train | function stripQuotes(text) {
var sansquotes = text;
if(isQuotedString(text)) {
if(text.length === 2) {
sanquotes = ""; // empty string
}
else {
| javascript | {
"resource": ""
} |
q42435 | addQuotes | train | function addQuotes(text, quoteChar) {
var withquotes = text;
if(!isQuotedString(text)) {
| javascript | {
"resource": ""
} |
q42436 | getPixels | train | function getPixels(texture, opts) {
var gl = texture.gl
if (!gl)
throw new Error("must provide gl-texture2d object with a valid 'gl' context")
if (!fbo) {
var handle = gl.createFramebuffer()
fbo = {
handle: handle,
dispose: dispose,
gl: gl
... | javascript | {
"resource": ""
} |
q42437 | train | function(listsEnabled, lineAttributesEnabled) {
if ((!hasList() && !hasLineAttributes) || (!listsEnabled && !lineAttributesEnabled)) {
return {
lineAttributes: [],
inlineAttributeString: rawAttributeString,
inlinePlaintext: rawText
... | javascript | {
"resource": ""
} | |
q42438 | train | function( userID ) {
var id = curId;
curId++;
if( curId == Number.MAX_VALUE )
curId = Number.MIN_VALUE;
roomUsers[ id ] = [];
return this.setRoomData( id, {} )
| javascript | {
"resource": ""
} | |
q42439 | train | function( userID, roomID ) {
var userCount;
if( roomUsers[ roomID ] === undefined ) {
return promise.reject( 'No room with the id: ' + roomID );
} else {
var userIDX = roomUsers[ roomID ].indexOf( userID );
if( userIDX != -1 ) {
roomUsers[ roomID ].splice( userIDX, 1 );
userCount = roomUse... | javascript | {
"resource": ""
} | |
q42440 | train | function( roomID ) {
if( keys.length > 0 ) {
var randIdx = Math.round( Math.random() * ( keys.length - 1 ) ),
key = keys.splice( randIdx, 1 )[ 0 ];
keyToId[ key ] = roomID;
| javascript | {
"resource": ""
} | |
q42441 | train | function( roomID, key ) {
return this.getRoomIdForKey( key )
.then( function( savedRoomId ) {
if( savedRoomId == roomID ) {
delete idToKey[ roomID ];
delete keyToId[ key ];
| javascript | {
"resource": ""
} | |
q42442 | train | function( key ) {
var savedRoomId = keyToId[ key ];
if( savedRoomId | javascript | {
"resource": ""
} | |
q42443 | train | function( roomID, key, value ) {
if( roomData[ roomID ] === undefined ) | javascript | {
"resource": ""
} | |
q42444 | train | function( roomID, key ) {
if( roomData[ roomID ] === undefined ) {
return promise.reject( 'There | javascript | {
"resource": ""
} | |
q42445 | train | function( roomID, key ) {
var oldVal;
if( roomData[ roomID ] === undefined ) {
return promise.reject( 'There is no room by that id' );
} else {
oldVal | javascript | {
"resource": ""
} | |
q42446 | Tag | train | function Tag(tagDict){
if(!(this instanceof Tag))
return new Tag(tagDict)
// Check tagDict has the required fields
checkType('String', 'tagDict.key', tagDict.key, {required: true});
checkType('String', 'tagDict.value', tagDict.value, {required: true});
// Init parent class
Tag.super_.call(this, tagDic... | javascript | {
"resource": ""
} |
q42447 | readJSON | train | function readJSON(filepath){
var buffer = {};
try{
buffer = JSON.parse(fs.readFileSync(filepath, { | javascript | {
"resource": ""
} |
q42448 | readYAML | train | function readYAML(filepath){
var buffer = {};
try{
buffer = YAML.safeLoad(fs.readFileSync(filepath, | javascript | {
"resource": ""
} |
q42449 | createMultitasks | train | function createMultitasks(gulp, aliases){
for(var task in aliases){
if(aliases.hasOwnProperty(task)){
| javascript | {
"resource": ""
} |
q42450 | filterFiles | train | function filterFiles(gulp, options, taskFile){
var ext = path.extname(taskFile);
if(/\.(js|coffee)$/i.test(ext)){
createTask(gulp, | javascript | {
"resource": ""
} |
q42451 | loadGulpConfig | train | function loadGulpConfig(gulp, options){
options = Object.assign({ data:{} }, options);
options.dirs = isObject(options.dirs) ? options.dirs : {};
options.configPath = isString(options.configPath) ? options.configPath : 'tasks';
glob.sync(options.configPath, { | javascript | {
"resource": ""
} |
q42452 | setAfter | train | function setAfter (pipes, ai, bi) {
// console.log(' move %s => %s', ai, bi);
var ap = | javascript | {
"resource": ""
} |
q42453 | setBefore | train | function setBefore (pipes, ai, bi) {
// console.log(' move %s => %s', ai, bi);
var ap = | javascript | {
"resource": ""
} |
q42454 | arity | train | function arity(cmd, args, info, sub) {
var subcommand = sub !== undefined;
// command validation decorated the info
var def = sub || info.command.def
, expected = def.arity
, first = def.first
, last = def.last
, step = def.step
, min = Math.abs(expected)
, max
// account for command,... | javascript | {
"resource": ""
} |
q42455 | createGenerateDocs | train | function createGenerateDocs(inPath, outPath) {
if (!inPath) {
throw new Error('Input path(s) argument is required');
}
if (!outPath) {
throw new Error('Output path argument is required');
}
const jsDocConfig = {
opts: {
| javascript | {
"resource": ""
} |
q42456 | Feedsme | train | function Feedsme(opts) {
if (!this) new Feedsme(opts); // eslint-disable-line no-new
if (typeof opts === 'string') {
this.base = opts;
} else if (opts.protocol && opts.href) {
this.base = url.format(opts);
} else if (opts.url || opts.uri) {
this.base = opts.url || opts.uri;
} else {
throw new... | javascript | {
"resource": ""
} |
q42457 | validateBody | train | function validateBody(err, body) {
body = tryParse(body);
if (err || !body) {
return next(err || new Error('Unparsable response with | javascript | {
"resource": ""
} |
q42458 | AsLate | train | function AsLate(arg, u, ments) {
this.args = arg + u | javascript | {
"resource": ""
} |
q42459 | getObjectClassname | train | function getObjectClassname (listener) {
if (!listener) return DEFAULT_LISTENER;
if (typeof listener === 'string') return listener;
| javascript | {
"resource": ""
} |
q42460 | SansServer | train | function SansServer(configuration) {
if (!(this instanceof SansServer)) return new SansServer(configuration);
const config = configuration && typeof configuration === 'object' ? Object.assign(configuration) : {};
config.logs = config.hasOwnProperty('logs') ? config.logs : true;
config.rejectable = conf... | javascript | {
"resource": ""
} |
q42461 | addHook | train | function addHook(hooks, type, weight, hook) {
const length = arguments.length;
let start = 2;
if (typeof type !== 'string') {
const err = Error('Expected first parameter to be a string. Received: ' + type);
err.code = 'ESHOOK';
throw err;
}
// handle variable input paramete... | javascript | {
"resource": ""
} |
q42462 | defineHookRunner | train | function defineHookRunner(runners, type) {
if (runners.types.hasOwnProperty(type)) {
const err = Error('There is already a hook runner defined for this type: ' + type);
err.code = 'ESHOOK';
throw err;
}
| javascript | {
"resource": ""
} |
q42463 | request | train | function request(server, config, hooks, keys, request, callback) {
const start = Date.now();
if (typeof request === 'function' && typeof callback !== 'function') {
callback = request;
request = {};
}
// handle argument variations and get Request instance
const args = Array.from(arg... | javascript | {
"resource": ""
} |
q42464 | timeout | train | function timeout(seconds) {
return function timeoutSet(req, res, next) {
const timeoutId = setTimeout(() => {
if (!res.sent) res.sendStatus(504)
}, 1000 * seconds);
| javascript | {
"resource": ""
} |
q42465 | transform | train | function transform(req, res, next) {
const state = res.state;
const body = state.body;
const type = typeof body;
const isBuffer = body instanceof Buffer;
let contentType;
// error conversion
if (body instanceof Error) {
res.log('transform', 'Converting Error to response');
r... | javascript | {
"resource": ""
} |
q42466 | validMethod | train | function validMethod(req, res, next) {
if (httpMethods.indexOf(req.method) === -1) {
| javascript | {
"resource": ""
} |
q42467 | train | function (name) {
if (!this.instances[name]) {
this.instances[name] = DevFixturesModel.create({name: | javascript | {
"resource": ""
} | |
q42468 | sliceOf | train | function sliceOf(ars, i, parts) {
return ars.slice( | javascript | {
"resource": ""
} |
q42469 | train | function(className, viewArgs) {
var self = this,
view = this.views[className],
dfd = $.Deferred();
if (view) {
view.undelegateEvents();
}
this.loader.load(className)
.then(function(Constructor) {
... | javascript | {
"resource": ""
} | |
q42470 | Directive | train | function Directive(filename, directiveArguments) {
this.filename = filename;
this.name = directiveArguments[0].value;
var directiveConfiguration = directiveArguments[1];
// Extract the last attribute of the array
if (directiveConfiguration.type === 'ArrayExpression' && directiveConfiguration.elements.length) ... | javascript | {
"resource": ""
} |
q42471 | parseAst | train | function parseAst(filename, ast) {
var directives = [];
esprimaHelper.traverse(ast, function (node) {
var calleeExpressionName = esprimaHelper.getCallExpressionName(node);
if (calleeExpressionName === 'directive') {
var directiveArguments = node['arguments'] || [];
| javascript | {
"resource": ""
} |
q42472 | parseFile | train | function parseFile(filename, code) {
if (/directive/.test(code)) | javascript | {
"resource": ""
} |
q42473 | connStr | train | function connStr(conn) {
var conf = mergeDefaults(conn);
var connString = conf.driver + '://' + conf.username + | javascript | {
"resource": ""
} |
q42474 | createPool | train | function createPool(conn) {
var conf = connectionConfig[conn.app][conn.env];
conf.connStr = connStr(conn);
console.log('Creating pool to : ' + conf.connStr);
// Create the pool on the conf object for easy future access
conf.pool = anydb.createPool(conf.connStr, {
min: conf.min,
max: conf.max,
onCo... | javascript | {
"resource": ""
} |
q42475 | parseML | train | function parseML(memberLog, required) {
return memberLog.map(member => {
const cloned = clone(member);
const key = Reflect.ownKeys(cloned)[0];
const value = cloned[key];
| javascript | {
"resource": ""
} |
q42476 | addSourceInfoToML | train | function addSourceInfoToML(memberLog, source) {
let cloned = memberLog.slice();
for (const [key, value] of getIterableObjectEntries(source)) {
if (Talent.typeCheck(value)) {
cloned = addSourceInfoToML(cloned, value);
}
const foundAndCloned = clone(findWhereKey(cloned, key));
| javascript | {
"resource": ""
} |
q42477 | translate | train | function translate(content, langFile) {
return content.replace(templateRegEx, function (match, capture) {
return | javascript | {
"resource": ""
} |
q42478 | train | function (promise) {
var targets = this._targets;
targets.push(promise);
promise['catch'](
function() {
return true;
}
).then(
function() {
| javascript | {
"resource": ""
} | |
q42479 | train | function (type) {
var targets = this._targets.slice(),
known = {},
args = arguments.length > 1 && toArray(arguments, 1, true),
target, subs,
i, j, jlen, guid, callback;
// Add index 0 and 1 entries for use in Y.bind.apply(Y, a... | javascript | {
"resource": ""
} | |
q42480 | train | function(anchornode) {
var valid = (anchornode.get('tagName')==='A') && anchornode.getAttribute('data-pjax-mojit'),
attributes, i, parheader;
if (valid) {
attributes = {
'data-pjax-mojit': anchornode.getAttribute('data-pjax... | javascript | {
"resource": ""
} | |
q42481 | _getRef | train | function _getRef (refOrQuery) {
if (typeof refOrQuery.ref === 'function') {
refOrQuery = refOrQuery.ref()
} else if (typeof refOrQuery.ref | javascript | {
"resource": ""
} |
q42482 | createRecord | train | function createRecord (snapshot) {
var value = snapshot.val()
var res = | javascript | {
"resource": ""
} |
q42483 | indexForKey | train | function indexForKey (array, key) {
for (var i = 0; i < array.length; i++) { | javascript | {
"resource": ""
} |
q42484 | bind | train | function bind (vm, key, source) {
var asObject = false
var cancelCallback = null
var readyCallback = null
// check { source, asArray, cancelCallback } syntax
if (isObject(source) && source.hasOwnProperty('source')) {
asObject = source.asObject
cancelCallback = source.cancelCallback
readyCallback =... | javascript | {
"resource": ""
} |
q42485 | defineReactive | train | function defineReactive (vm, key, val) {
if (key in vm) { | javascript | {
"resource": ""
} |
q42486 | bindAsArray | train | function bindAsArray (vm, key, source, cancelCallback) {
var array = []
defineReactive(vm, key, array)
var onAdd = source.on('child_added', function (snapshot, prevKey) {
var index = prevKey ? indexForKey(array, prevKey) + 1 : 0
array.splice(index, 0, createRecord(snapshot))
}, cancelCallback)
var o... | javascript | {
"resource": ""
} |
q42487 | bindAsObject | train | function bindAsObject (vm, key, source, cancelCallback) {
defineReactive(vm, key, {})
var cb = source.on('value', function (snapshot) {
vm[key] | javascript | {
"resource": ""
} |
q42488 | unbind | train | function unbind (vm, key) {
var source = vm._wilddogSources && vm._wilddogSources[key]
if (!source) {
throw new Error(
'VueWild: unbind failed: "' + key + '" is not bound to ' +
'a Wilddog reference.'
)
}
var listeners = vm._wilddogListeners[key]
for (var event in listeners) {
| javascript | {
"resource": ""
} |
q42489 | ensureRefs | train | function ensureRefs (vm) {
if (!vm.$wilddogRefs) {
vm.$wilddogRefs = Object.create(null)
| javascript | {
"resource": ""
} |
q42490 | getRequireNameForPackage | train | function getRequireNameForPackage(pkgName) {
if (this.options.rename[pkgName]) {
return this.options.rename[pkgName];
}
| javascript | {
"resource": ""
} |
q42491 | ReadArray | train | function ReadArray (options, array) {
if (!(this instanceof ReadArray)) {
return new ReadArray(options, array)
}
if (Array.isArray(options)) {
array = options
options = {}
} | javascript | {
"resource": ""
} |
q42492 | select | train | function select(rule, prefix) {
return rule.selectors | javascript | {
"resource": ""
} |
q42493 | assertKeys | train | function assertKeys (routes) {
Object.keys(routes).forEach(function (route) {
| javascript | {
"resource": ""
} |
q42494 | getQueryResponse | train | function getQueryResponse(url) {
var response;
if (options.stopQueryParam) {
var parsedUrl = parseUrl(url, true);
if (parsedUrl.query && parsedUrl.query[options.stopQueryParam]) {
| javascript | {
"resource": ""
} |
q42495 | engine | train | function engine(url) {
var ret;
var parts = /^(\w+):/.exec(url);
if (!parts) {
d.fatal("Invalid engine URI", url);
}
try {
var Engine = angular.injector(['ng', 'coa.store']).get('Engine' + parts[1].ucfirst());
r... | javascript | {
"resource": ""
} |
q42496 | getEngine | train | function getEngine(name) {
if (!dbconfig.has(name)) {
d.fatal("Trying to access data storage that is not configured:", name);
}
var conf = dbconfig.get(name);
| javascript | {
"resource": ""
} |
q42497 | runDriver | train | function runDriver(location, driver, options) {
options.testComplete = options.testComplete || 'return window.TESTS_COMPLETE';
options.testPassed = options.testPassed || 'return window.TESTS_PASSED && !window.TESTS_FAILED';
var startTime = Date.now();
var jobInfo = {
name: options.name,
build: process.e... | javascript | {
"resource": ""
} |
q42498 | mergeAttributes | train | function mergeAttributes( target, source ) {
const propNames = Object.keys( source );
for ( let i = 0, numNames = propNames.length; i < numNames; i++ ) {
const name = propNames[i];
const attribute = source[name];
switch ( typeof attribute ) {
case "object" :
if ( attribute ) {
break;
| javascript | {
"resource": ""
} |
q42499 | mergeComputeds | train | function mergeComputeds( target, source ) {
const propNames = Object.keys( source );
for ( let i = 0, numNames = propNames.length; i < numNames; i++ ) {
const name = propNames[i];
const computer = source[name];
switch ( typeof computer ) {
case "function" :
break;
default :
| javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.