Skip to content

Instantly share code, notes, and snippets.

View sagiavinash's full-sized avatar

Sagi Avinash Varma sagiavinash

View GitHub Profile
@sagiavinash
sagiavinash / FunctionProperties.js
Created April 27, 2015 16:42
Function Properties (instead of global variables to store invokation values).
/*
instead of declaring global variables.
var counter = 0;
$(document).on("click", function(){
console.log(counter);
counter++;
});
*/
$(document).on("click", function handler(){
@sagiavinash
sagiavinash / getObjectClass.js
Created April 28, 2015 17:07
Get object class
function getClass(obj) {
if (typeof obj === "undefined")
return "undefined";
if (obj === null)
return "null";
return Object.prototype.toString.call(obj)
.match(/^\[object\s(.*)\]$/)[1];
}
getClass("") === "String";
@sagiavinash
sagiavinash / deepVal.js
Created April 28, 2015 17:08
Method to get value of nth level enumerable property of an object.
Object.defineProperty(Object.prototype, 'deepVal', {
enumerable: false,
configurable: false,
writable: false,
value: function (string){
var props = string.split("."),
val = {};
for(var key in this){
val[key] = this[key];
}
@sagiavinash
sagiavinash / jquery-importProp.js
Created April 28, 2015 17:10
Import object by values not references
;(function($){
$.importProp = function($this, $src, subset) {
if(subset){
$.each(subset, function(i, key){
$this[key] = $src[key];
});
} else {
$.each($src, function(key, e){
$this[key] = $src[key];
});
@sagiavinash
sagiavinash / JS_CallStackExecution_Demo.js
Created April 28, 2015 17:10
JS_CallStackExecution_Demo
console.log("1");
(function level1(){
console.log("2");
setTimeout(function async1(){
console.log("3");
},0);
(function level2(){
console.log("4");
setTimeout(function async2(){
console.log("5");
@sagiavinash
sagiavinash / dataTypeCheck.js
Last active August 29, 2015 14:20
Check variable's primitive datatype
// just typepof myVar == 'string' fails when my var is declared => var myVar = new String("value");
if (typeof myVar == 'string' || myVar instanceof String){
// it's a string
}
// just typepof myVar == 'string' fails when my var is declared => var myVar = new String("value");
if (typeof myVar == 'number' || myVar instanceof Number){
// it's a string
}
@sagiavinash
sagiavinash / jquery-throttle.js
Created April 28, 2015 17:14
Throttle Snippet - Jquery
(function($) {
$.extend({
throttle : function(fn, timeout, ctx) {
var timer, args, needInvoke;
return function() {
args = arguments;
needInvoke = true;
ctx = ctx || this;
if(!timer) {
(function() {
@sagiavinash
sagiavinash / image-center-fill.css
Created April 28, 2015 17:16
image centering - fill configuration
/** crop vertical portions **/
.outer-wrap{
position:relative;
width:100px;
height:100px; /* @OH */
background:#ccc;
overflow:hidden;
}
.inner-wrap{
@sagiavinash
sagiavinash / image-center-fit.css
Created April 28, 2015 17:17
image centering with "fit" configuration
/* Solution 1 (best) */
.wrap{
position:relative;
}
img{
position:abosulute;
top:0;
right:0;
bottom:0;
left:0;
@sagiavinash
sagiavinash / anchorContainer-remove-space.css
Created April 28, 2015 17:18
remove space after image which is inside anchor tag
a{
line-height:0;
/*font-size:0; will not work only line-height*/
}