code: function RingBuffer(maxSize){
      var data = [];
      var cursor = 0;
      var isFull = false;
      this.append = function(x){
          if (isFull){
              data[cursor] = x;
              cursor = (cursor + 1) % maxSize;
          }
          else{
              data.push(x);
              cursor++;
              if (data.length === maxSize){
                  cursor = 0;
                  isFull = true;
              }
          }
      };
      this.avg = function(){
          var sum = data.reduce(function(a, b){ return a + b });
          return sum / (isFull ? maxSize : cursor);
      };
      this.size = function(){
          return isFull ? maxSize : cursor;
      };
      this.clear = function(){
          data = [];
          cursor = 0;
          isFull = false;
      };
  }
docs: /*
  
  Vardiff ported from stratum-mining share-limiter
  https://github.com/ahmedbodi/stratum-mining/blob/master/mining/basic_share_limiter.py