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 28, 2015 17:21
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 / inline-block-fix.css
Created April 28, 2015 17:18
fix to remove space between inline-block elements due to line-breaks in code
/* Solution 0:
* Avoiding line breaks in code or using multi-line comments as placeholders for line-breaks.
* Its best to adopt this solution if its part of the html build process to remove whitespaces.
*/
/* Solution 1:
* use width=device-width (needed for iphone).
*/
.list-wrapper {
letter-spacing: -0.31em; /* -4px doesnt work in zoomed states */
@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*/
}
@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 / 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 / debounce-snippet.js
Created April 28, 2015 17:16
Debounce Function Snippet : Plain JS
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@sagiavinash
sagiavinash / jquery-debounce.js
Created April 28, 2015 17:15
Debounce Snippet - Jquery
(function($) {
$.extend({
debounce : function(fn, timeout, invokeAsap, ctx) {
if(arguments.length == 3 && typeof invokeAsap != 'boolean') {
ctx = invokeAsap;
invokeAsap = false;
}
var timer;
return function() {
var args = arguments;
@sagiavinash
sagiavinash / throttle.js
Created April 28, 2015 17:15
Throttle Snippet - Plain JS
function throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last,
deferTimer;
return function () {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshhold) {
@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 / 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
}