Instantly share code, notes, and snippets.

Alexander Moon mr-moon

  • Tallinn, Estonia, Europe
View GitHub Profile
@mr-moon
mr-moon / await.js
Created Nov 4, 2017
clean javascript API for waiting for some condition to be met
View await.js
/**
* A helper that simplifies waiting for something to happen. It acts like an observer without any
* particular observable. So your 'evaluator' function may do anything, untill it's returns non-undefined value
*
* For example, you may want to "observe" a sessionStorage value regardless of browser support of the
* "storage" events.
*
* @example
* ```js
* var awaiter = await(
@mr-moon
mr-moon / gist:77c90944804f7da71ecd
Last active Aug 29, 2015
Doing supported browsers check with WhichBrowser.net library.
View gist:77c90944804f7da71ecd
var
INTERNET_EXPLORER = 'Internet Explorer',
FIREFOX = 'Firefox',
CHROME = 'Chrome',
OPERA = 'Opera',
OPERA_MINI = 'Opera Mini',
SAFARI = 'Safari',
MAXTHON = 'Maxthon',
WEBKIT = 'WebKit',
TRIDENT = 'Trident',
View gist:1486161
/**
* Evaluates the given number against array of numbers, and returns
* the one that is the "closest"
* @param value Value to be tested
* @param array Array of numbers
* @param method uint a comparison method. 0 - round, 1 - ceil, 2 - floor
* @return The closest value from <code>array</code> parameter
*/
public static function closestAgainstArray(value:Number, array:Array, method:uint = 0):Number
{