Skip to content

Instantly share code, notes, and snippets.

View mistadikay's full-sized avatar

Denis Koltsov mistadikay

View GitHub Profile
/**
* @param {object} NS namespace (window by default)
*/
(function(NS){
NS = NS || window;
/**
* Returns option from cases with the correct ending according to passed number
*
* @param {Number} num number
/**
* @param {object} NS namespace (window by default)
*/
(function(NS){
NS = NS || window;
NS.getRandom = function(){
return Math.random();
};
@mistadikay
mistadikay / index.js
Created March 25, 2015 08:16
shuffle
/* Fisher–Yates shuffle */
function shuffle(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
@mistadikay
mistadikay / bind.js
Created March 25, 2015 08:14
bind polyfill
/**
* bind polyfill by Mozilla
* from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
*/
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
function checkControlSumPhysical(value){
var code = value.split(''),
x;
x = code[0] * (-1) + code[1] * 5 + code[2] * 7 + code[3] * 9 + code[4] * 4 + code[5] * 6 + code[6] * 10 + code[7] * 5 + code[8] * 7;
if (x % 11 === 10){
x = (x % 11) % 10;
} else{
x = x - (11 * Math.floor(x / 11));
}
return +code[9] === x;
function checkControlSumJuridical(value){
var code = value.split(''),
numericValue = +value,
x;
if ((numericValue < 30000000) || (numericValue > 60000000)){
x = code[0] + code[1] * 2 + code[2] * 3 + code[3] * 4 + code[4] * 5 + code[5] * 6 + code[6] * 7;
} else{
x = code[0] * 7 + code[1] + code[2] * 2 + code[3] * 3 + code[4] * 4 + code[5] * 5 + code[6] * 6;
}
@mistadikay
mistadikay / index
Last active August 29, 2015 14:05
focusin/focusout polyfill
/**
* usage: NAMESPACE.addFocusInEvent($node, listener);
* replace comments containing [code] with your code
*/
(function(NAMESPACE, global){
var document = global.document,
$body = document.body,
focusInEvent = 'focusin',
focusOutEvent = 'focusout',
$testInputContainer,