Skip to content

Instantly share code, notes, and snippets.

View gengkev's full-sized avatar

Kevin Geng gengkev

  • Carnegie Mellon University
View GitHub Profile
@gengkev
gengkev / birsdaytimer.js
Created January 7, 2012 03:37
A very oddly worded setTimeout replacement that uses a convoluted algorithm to try to run as close as possible to the specified interval.
function BirsdayTimer (interval,checkUpdateTime,nTimeWeight,func) {
this.func = func;
this.nTimeWeight = nTimeWeight;
this.interval = interval;
this.checkUpdateTime = checkUpdateTime;
}
BirsdayTimer.prototype.haisur = function(){
this.execTime = this.execTime || +new Date(),
this.updateTime = this.updateTime || this.execTime,
curTime = +new Date(),
@gengkev
gengkev / interval.js
Created December 28, 2011 15:26 — forked from manast/interval.js
Accurate Javascript setInterval replacement
function Interval(func,duration){
if(typeof func !== "function") throw new TypeError("Expected function");
else if(typeof duration !== "number") throw new TypeError("Expected number");
this.func = func;
this.duration = duration;
this.baseline = +new Date();
(function(_this){
_this.timer = setTimeout(function(){