Skip to content

Instantly share code, notes, and snippets.

View Tushkiz's full-sized avatar

Tushar Sonawane Tushkiz

View GitHub Profile
@Tushkiz
Tushkiz / randomNumber.js
Created May 7, 2013 18:53
Random Number Function
function randomNumber(from, to) {
return Math.floor((Math.random()*(to - from + 1)) + from);
}
@Tushkiz
Tushkiz / RegEx.js
Last active December 17, 2015 02:19
Common Regular Expressions
// Common Regular Expression
// Email Address
/* Humans */ var emailHuman = /[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}/i;
/* Bots */ var emailBots = /^[\w!#$%&\’*+\/=?^`{|}~.-]+@(?:[a-z\d][a-z\d-]*(?:\.[a-z\d][a-z\d-]*)?)+\.(?:[a-z][a-z\d-]+)$/i;
// Date
var datePattern = /([01]?\d)[-\/ .]([0123]?\d)[-\/ .](\d{4})/;
// Web Address
var debug = true,
_log = function() {
debug && window.console && console.log.apply(console, arguments);
};
@Tushkiz
Tushkiz / memoizer.js
Last active December 15, 2015 14:09
Faster Recursions The memoizer function will take an initial 'cache' array and the 'operation' function. It returns a 'self' function that manages the cache store, this 'self' function calls the 'operation' function only when there is a 'cache' miss, ultimately improves performance.
var memoizer = function (cache, operation) {
var self = function (n) {
var result = cache[n];
if (typeof result !== 'number') {
result = operation(self, n);
cache[n] = result;
}
return result;
};
return self;