Beispiel #1
0
  getComputedDimensions: function (obj) {
    var compstyle;
    if (typeof window.getComputedStyle === 'undefined') {
      compstyle = obj.currentStyle;
    } else {
      compstyle = window.getComputedStyle(obj);
    }

    var computeInnerBound = function (acc, key) {
      var val = parseInt(compstyle[key], 10);
      if (_.isNaN(val)) {
        return acc;
      } else {
        return acc - val;
      }
    };

    var width = _.foldl(
      ['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'],
      computeInnerBound,
      obj.offsetWidth
    );

    var height = _.foldl(
      ['paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth'],
      computeInnerBound,
      obj.offsetHeight
    );

    return {
      width: width,
      height: height
    };
  },
Beispiel #2
0
 /*
  * find json documents matching either a qs query or kv query
  *
  * https://github.com/marklogic/Corona/wiki/Key-Value-Query-Service
  *
  * e.g. var login = "******";
  *      db.json.find( { github: login
  *                    , twitter: login 
  *                    }
  *                  , { start: 1
  *                    , end: 10
  *                    }
  *                  , function (e,b,h) {
  *                      if(e) { return console.log(err); }
  *                      var user_from_db = response.results[0];
  *                      console.log(user_from_db);
  *                    });
  *
  * @error {nuvem:INVALID-QUERY} query was neither a string or a kv object
  *
  * @param {query:string|object} the query
  * @param {opts:object:optional} either index or start & end
  * @param {callback:function:optional} function to call back
  *
  * @return a json response containing outputs in the "results" property
  */
  function find_json(query,opts,callback) {
    var get = {};
    if (typeof opts === 'function') {
     callback = opts;
     opts = {};
    }
    if(typeof query === "string") {
      get.resource = 'json/query';
      get.params   = _.extend({q: query}, opts);
    }
    else if(typeof query === "object") {
      get.resource = 'json/kvquery';
      get.params = _.extend(
        _.foldl(
          _.keys(query), 
          function (memo,e) { 
            memo.key.push(e); 
            memo.value.push(query[e]); 
            return memo; },
          {key: [], value: []}),
      opts);
    }
    else {
      return callback(err.nuvem("Please provide either a string or a kv object", "INVALID-QUERY"));
    }
    request.json(get, function (e,b,h){
      if(e) { return callback(e,b,h); }
      if(opts.start === opts.end && b.results[0]) {
        b = b.results[0];
      }
      return callback(null,b,h);
    });
  }
Beispiel #3
0
  getHostResourcesByFramework: function (state, filter) {
    return _.foldl(state.frameworks, function (memo, framework) {
      _.each(framework.tasks, function (task) {
        if (memo[task.slave_id] == null) {
          memo[task.slave_id] = {};
        }

        var frameworkKey = task.framework_id;
        if (_.contains(filter, framework.id)) {
          frameworkKey = 'other';
        }

        var resources = _.pick(task.resources, 'cpus', 'disk', 'mem');
        if (memo[task.slave_id][frameworkKey] == null) {
          memo[task.slave_id][frameworkKey] = resources;
        } else {
          // Aggregates used resources from each executor
          _.each(resources, function (value, key) {
            memo[task.slave_id][frameworkKey][key] += value;
          });
        }
      });

      return memo;
    }, {});
  }
Beispiel #4
0
// Helper function to extract the bounds on a dataset, by base
function datasetBounds(dataset, state0) {
  return _.foldl(dataset, function (acc, entry) {
    var base = idr.toString(idr.base(entry.idr));
    var accItem = acc[base] || { newest: 0, oldest: Date.now(), total: 0 };
    accItem.oldest = Math.min(accItem.oldest, entry.at);
    accItem.newest = Math.max(accItem.newest, entry.at);
    accItem.total++;
    acc[base] = accItem;
    return acc;
  }, state0 || {});
}
Beispiel #5
0
function getCountByHealth(frameworks) {
  return _.foldl(frameworks, function (acc, framework) {
    let appHealth = MarathonStore.getServiceHealth(framework.name);
    if (acc[appHealth.value] === undefined) {
      acc[appHealth.value] = 1;
    } else {
      acc[appHealth.value]++;
    }
    return acc;
  }, {});
}
Beispiel #6
0
    return client.iterator(batchSize, opts).then(function(it) {
      var p = _.foldl(_.range(expected.length),
          function(p) {
            return p.then(function(array) {
              return it.next().then(function(entry) {
                array.push(entry);
                return array;
              })
            });
          }, Promise.resolve([]));

      return p
          .then(function(array) { exports.toContainAllEntries(expected)(sortByF, array); })
          .then(function() { return it.close(); }) // Close iterator
          .then(function() { return client; });
    })
Beispiel #7
0
 var define_with_constructors = function(local_definition, root_name) {
     if (_.has(local_definition, 'operations')) {
         var interface_definition = complete_operation_set(local_definition);
         return function() { 
             var servant = new Servant(interface_definition);
             servant.obj_name = root_name;
             return servant;
         };
     } else {
         var apply_inner_definitions = function(module, inner_definitions, this_name) {
             fully_qualified_name = root_name + "::" + this_name;
             module[this_name] = define_with_constructors(inner_definitions, fully_qualified_name);
             return module;
         };
         return _.foldl(local_definition, apply_inner_definitions, {});
     }
 };
Beispiel #8
0
    }, function (err, results) {
	if (err) {
	    next(err);
	} else {
	    var xmlObj = _.foldl(results, function (obj, type) {
		obj[type.type] = {kategori: _.map(type.categories, function (category) {
		    return {
			"@id"   : category._id,
			"#text" : category.name
		    };
		},{})};
		return obj;
	    }, {});

	    xmlObj = {data: xmlObj};
	    res.header('Content-Type', 'text/xml');
	    res.send(json2xml.xml(xmlObj));
	}
    });
Beispiel #9
0
  getUsedSliceConfig: function (node) {
    var props = this.props;
    var resourceConfig = ResourceTypes[props.selectedResource];
    var serviceSlices = this.getServiceSlicesConfig(node);
    var percentage;

    if (serviceSlices.length > 0) {
      percentage = _.foldl(serviceSlices, function (memo, slice) {
        return memo + slice.percentage;
      }, 0);
    } else {
      percentage = node.getUsageStats(props.selectedResource).percentage;
    }

    return [{
      colorIndex: resourceConfig.colorIndex,
      name: resourceConfig.label,
      percentage: percentage
    }];
  },
Beispiel #10
0
                return compileModule.compileAllFiles(filesToCompile, target, options, currenttask.target).then(function (result) {
                    // End the timer
                    endtime = new Date().getTime();

                    grunt.log.writeln('');

                    // Analyze the results of our tsc execution,
                    //   then tell the user our analysis results
                    //   and mark the build as fail or success
                    if (!result) {
                        grunt.log.error('Error: No result from tsc.'.red);
                        return false;
                    }

                    var isError = (result.code !== 0);

                    // If the compilation errors contain only type errors, JS files are still
                    //   generated. If tsc finds type errors, it will return an error code, even
                    //   if JS files are generated. We should check this for this,
                    //   only type errors, and call this a successful compilation.
                    // Assumptions:
                    //   Level 1 errors = syntax errors - prevent JS emit.
                    //   Level 2 errors = semantic errors - *not* prevents JS emit.
                    //   Level 5 errors = compiler flag misuse - prevents JS emit.
                    var level1ErrorCount = 0, level5ErrorCount = 0, nonEmitPreventingWarningCount = 0;
                    var hasPreventEmitErrors = _.foldl(result.output.split('\n'), function (memo, errorMsg) {
                        var isPreventEmitError = false;
                        if (errorMsg.search(/error TS1\d+:/g) >= 0) {
                            level1ErrorCount += 1;
                            isPreventEmitError = true;
                        } else if (errorMsg.search(/error TS5\d+:/) >= 0) {
                            level5ErrorCount += 1;
                            isPreventEmitError = true;
                        } else if (errorMsg.search(/error TS\d+:/) >= 0) {
                            nonEmitPreventingWarningCount += 1;
                        }
                        return memo || isPreventEmitError;
                    }, false) || false;

                    // Because we can't think of a better way to determine it,
                    //   assume that emitted JS in spite of error codes implies type-only errors.
                    var isOnlyTypeErrors = !hasPreventEmitErrors;

                    // Log error summary
                    if (level1ErrorCount + level5ErrorCount + nonEmitPreventingWarningCount > 0) {
                        if (level1ErrorCount + level5ErrorCount > 0) {
                            grunt.log.write(('>> ').red);
                        } else {
                            grunt.log.write(('>> ').green);
                        }

                        if (level5ErrorCount > 0) {
                            grunt.log.write(level5ErrorCount.toString() + ' compiler flag error' + (level5ErrorCount === 1 ? '' : 's') + '  ');
                        }
                        if (level1ErrorCount > 0) {
                            grunt.log.write(level1ErrorCount.toString() + ' syntax error' + (level1ErrorCount === 1 ? '' : 's') + '  ');
                        }
                        if (nonEmitPreventingWarningCount > 0) {
                            grunt.log.write(nonEmitPreventingWarningCount.toString() + ' non-emit-preventing type warning' + (nonEmitPreventingWarningCount === 1 ? '' : 's') + '  ');
                        }

                        grunt.log.writeln('');

                        if (isOnlyTypeErrors) {
                            grunt.log.write(('>> ').green);
                            grunt.log.writeln('Type errors only.');
                        }
                    }

                    // !!! To do: To really be confident that the build was actually successful,
                    //   we have to check timestamps of the generated files in the destination.
                    var isSuccessfulBuild = (!isError || (isError && isOnlyTypeErrors && !options.failOnTypeErrors));

                    if (isSuccessfulBuild) {
                        // Report successful build.
                        var time = (endtime - starttime) / 1000;
                        grunt.log.writeln('');
                        grunt.log.writeln(('TypeScript compilation complete: ' + time.toFixed(2) + 's for ' + result.fileCount + ' typescript files').green);
                    } else {
                        // Report unsuccessful build.
                        grunt.log.error(('Error: tsc return code: ' + result.code).yellow);
                    }

                    return isSuccessfulBuild;
                });
Beispiel #11
0
 function getDiff(chunk) {
     return _.foldl(tokenizers, function(diff, tokenizer) {
         return diff ? diff : tokenizer.apply(tokenizer, [chunk]);
     }, 0);
 }
Beispiel #12
0
 it("should reduce boils down a list of values from left into a single value", function() {
   var result = _.foldl([1, 2, 3], function(memo, value) {
     return memo + value;
   }, 0);
   assert.strictEqual(result, 6);
 });