Skip to content

Instantly share code, notes, and snippets.

View mr-moon's full-sized avatar

Alexander Moon mr-moon

  • Tallinn, Estonia, Europe
View GitHub Profile
@mr-moon
mr-moon / psqlerrors.json
Created July 4, 2024 13:20
PostgreSQL error codes with semantic identifier
{
"20000": "case_not_found",
"21000": "cardinality_violation",
"22000": "data_exception",
"22001": "string_data_right_truncation",
"22002": "null_value_no_indicator_parameter",
"22003": "numeric_value_out_of_range",
"22004": "null_value_not_allowed",
"22005": "error_in_assignment",
"22007": "invalid_datetime_format",
@mr-moon
mr-moon / coords.js
Created November 18, 2019 11:41
DOM element coordinate helpers
/**
* MIT License
* @author Alexander Moon [email protected]
*/
/**
* An offset type definition
* @typedef {Object} Offset
* @property {number} top
* @property {number} left
@mr-moon
mr-moon / await.js
Created November 4, 2017 14:14
clean javascript API for waiting for some condition to be met
/**
* 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 August 29, 2015 14:05
Doing supported browsers check with WhichBrowser.net library.
var
INTERNET_EXPLORER = 'Internet Explorer',
FIREFOX = 'Firefox',
CHROME = 'Chrome',
OPERA = 'Opera',
OPERA_MINI = 'Opera Mini',
SAFARI = 'Safari',
MAXTHON = 'Maxthon',
WEBKIT = 'WebKit',
TRIDENT = 'Trident',
/**
* 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
{