tinyjs / moduleUnused.js2

/*FILE_BEG {"actions": ["jslint"], "name": "/FS_MODULE/libUnused.js"}*/
/*jslint bitwise: true, indent: 2, nomen: true*/
'use strict';
(function moduleUnused() {
  var EXPORTS = global.EXPORTS = global.EXPORTS || {}, local = {

    arrayRandom: function (length) {
      //// create an array with random numbers
      var arr = [], ii = length;
      while (ii > 0) {
        arr.push(Math.random());
        ii -= 1;
      }
      return arr;
    },

    arrayRange: function (length) {
      var arr = [], ii;
      for (ii = 0; ii < length; ii += 1) {
        arr.push(ii);
      }
      return arr;
    },

    arrayShuffle: function (arr) {
      //// randomly shuffle elements in array
      var ii, rnd, swap;
      for (ii = 1; ii <= arr.length; ii += 1) {
        //// OPTIMIZATION - Fisher-Yates algorithm
        rnd = Math.floor(Math.random() * ii);
        swap = arr[ii];
        arr[ii] = arr[rnd];
        arr[rnd] = swap;
      }
    },

    echo: function (obj) {
      return obj;
    },

    echoArguments: function () {
      return arguments;
    },

    nop: function () {},

  };

  function Cache(size) {
    this.size = size;
    this.clear();
  }

  Cache.prototype = {

    clear: function () {
      //// clear cache
      this.arr1 = {};
      this.arr2 = {};
      this.ii = this.size;
    },

    gc: function (force) {
      //// garbage collect arbitray number of lru items
      this.ii -= 1;
      if (force || this.ii <= 0) {
        this.arr1 = this.arr2;
        this.arr2 = {};
        this.ii = this.size;
      }
    },

    getItem: function (key) {
      this.gc();
      return (this.arr2[key] = this.arr1[key]);
    },

    setItem: function (key, val) {
      this.gc();
      this.arr2[key] = this.arr1[key] = val;
    },

    _objectCullEmpty: function (obj, key) {
      var empty, key2, val = obj[key];
      if (typeof val !== 'object') {
        return val === undefined;
      }
      empty = true;
      for (key2 in val) {
        if (val.hasOwnProperty(key2)) {
          empty &= local._objectCullEmpty(val, key2);
        }
      }
      if (empty) {
        obj[key] = undefined;
        return true;
      }
    },

    objectCullEmpty: function (obj) {
      //// recursively set empty objects and nulls to undefined
      local._objectCullEmpty(obj = [obj], 0);
      return obj[0];
    },

    objectUpdateIfUndefined: function (aa, bb) {
      var key, val;
      for (key in bb) { if (bb.hasOwnProperty(key) && !aa.hasOwnProperty(key)) { aa[key] = bb[key]; } }
    },

    printe: function (err) {
      if (err) {
        console.error(err.stack);
      }
    },

  };
}());



(function moduleCron() {
  var EXPORTS = global.EXPORTS = global.EXPORTS || {}, local = {

    _init: function () {
      //// EXPORTS
      EXPORTS.moduleCron = moduleCron;
      EXPORTS.CRON_DATE = EXPORTS.CRON_DATE || new Date();
      EXPORTS.CRON_DAY = EXPORTS.CRON_DAY || {};
      EXPORTS.CRON_HOUR = EXPORTS.CRON_HOUR || {};
      EXPORTS.CRON_INTERVAL_ID = EXPORTS.CRON_INTERVAL_ID || setInterval(local._setInterval, 1000);
      EXPORTS.CRON_MINUTE = EXPORTS.CRON_MINUTE || {};
      EXPORTS.CRON_SECOND = EXPORTS.CRON_SECOND || {};
    },

    _objectEachCall: function (obj) {
      var key;
      for (key in obj) { if (obj.hasOwnProperty(key)) { obj[key](); } }
    },

    _setInterval: function () {
      var arr, date, kk;
      date = new Date();
      if (date.getHours() < EXPORTS.CRON_DATE.getHours()) {
        local._objectEachCall(EXPORTS.CRON_DAY);
      }
      if (date.getHours() !== EXPORTS.CRON_DATE.getHours()) {
        local._objectEachCall(EXPORTS.CRON_HOUR);
      }
      if (date.getMinutes() !== EXPORTS.CRON_DATE.getMinutes()) {
        local._objectEachCall(EXPORTS.CRON_MINUTE);
      }
      if (date.getSeconds() !== EXPORTS.CRON_DATE.getSeconds()) {
        local._objectEachCall(EXPORTS.CRON_SECOND);
      }
      EXPORTS.CRON_DATE = date;
    }

  };
  local._init();
}());
/*FILE_END*/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.