This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** crop vertical portions **/ | |
.outer-wrap{ | |
position:relative; | |
width:100px; | |
height:100px; /* @OH */ | |
background:#ccc; | |
overflow:hidden; | |
} | |
.inner-wrap{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solution 1 (best) */ | |
.wrap{ | |
position:relative; | |
} | |
img{ | |
position:abosulute; | |
top:0; | |
right:0; | |
bottom:0; | |
left:0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a{ | |
line-height:0; | |
/*font-size:0; will not work only line-height*/ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
instead of declaring global variables. | |
var counter = 0; | |
$(document).on("click", function(){ | |
console.log(counter); | |
counter++; | |
}); | |
*/ | |
$(document).on("click", function handler(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Instead of | |
interval(); | |
setInterval(interval, 1000); | |
*/ | |
// -1. Invocation function already defined. | |
// Never use this even if it looks awesome implicit eval is slow because of an additional parse step. | |
function interval(){ | |
console.log("Invoked"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function literallyEqual(value1, value2) { | |
var _fn = literallyEqual, | |
result = 1; | |
_fn.propLength = {}; | |
// getLength method is used to get simplify equality condition from (a subsetOf b && b subsetOf a) to (a subsetOf b && a.length = b.length). | |
_fn.getLength = function (object) { | |
if(Object.hasOwnProperty("keys")) return Object.keys(object).length; | |
// fallback for Object.keys. | |
var _len = 0, _key; | |
for (_key in object) { _len++; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generally for in loops are used to save a non-referenced copy/snapshot of an array. this is a far simpler method to acheive the same | |
var arr = [1, 2, 3]; | |
// referenced copy of an array. | |
var arr_ref_copy = arr; | |
// non-referenced copy or snapshot of an array. | |
var arr_snapshot = arr.slice(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* memoize(fn[, options]) -> returns a new function which memoizes return values for given args. | |
* Arguments: | |
* 1. fn: -> function to be memoized. (pass function's promise if it is async). | |
* 2. options: { | |
* isAsync -> (boolean), if function to be memoized is async. | |
* cacheLimit -> (integer), max no. of results that can be stored in cache. | |
* } | |
*/ | |