Skip to content

Instantly share code, notes, and snippets.

View lusan's full-sized avatar
🎯
Focusing

Lusan Das lusan

🎯
Focusing
View GitHub Profile
@lusan
lusan / 1_primitive_comparison.js
Created July 1, 2019 06:20 — forked from nicbell/1_primitive_comparison.js
JavaScript object deep comparison. Comparing x === y, where x and y are values, return true or false. Comparing x === y, where x and y are objects, returns true if x and y refer to the same object. Otherwise, returns false even if the objects appear identical. Here is a solution to check if two objects are the same.
//Primitive Type Comparison
var a = 1;
var b = 1;
var c = a;
console.log(a == b); //true
console.log(a === b); //true
console.log(a == c); //true
console.log(a === c); //true
// write code for this function: sum(a)(b)(c)....( n)(). This should return the sum of a+b+c....+n.
let sum = function(a) {
return function(b) {
if (b) {
return sum(a + b)
}
return a;
}
}
function throttle(callback, wait) {
let flag = true;
return function() {
let context = this, args = arguments;
if (flag) {
callback.apply(context, args);
flag = false;
}
setTimeout(() => {
flag = true;
@lusan
lusan / bind-polyfill.js
Last active June 30, 2019 19:41
Throttle polyfill
Function.prototype.myBind = function(...args) {
let context = this;
let params = args.slice(1);
return function(...args2) {
context.apply(args[0], [...params, ...args2])
}
}
@lusan
lusan / simple-vanilla-debounce.js
Created June 26, 2019 13:10
Simple vanilla debounce function
function debounce(func, wait = 100) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}
@lusan
lusan / composing-software.md
Created February 4, 2019 05:29 — forked from rosario/composing-software.md
Eric Elliott's Composing Software Series
@lusan
lusan / scrollToY.js
Created October 11, 2018 08:26
requestanimationframe-for-smart-animating
/* eslint-disable */
// http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
if (window) {
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
@lusan
lusan / index.html
Created September 28, 2018 13:08 — forked from jeffposnick/index.html
beforeinstallprompt demo
<html>
<head>
<title>Test</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<p>
If the <code>beforeinstallprompt</code> event fires, there will be a button displayed allowing
you to use <code>prompt()</code> on the deferred event.
</p>
@lusan
lusan / stickyfilterlogic.js
Created September 24, 2018 09:01
sticky filter logic
if user scrolling down
if user scrolled at bottom most isfilterAtBottom: (pageYOffset > positionFilterTopWhenFilterAtBottomMost)
then set position top gridProductsContainerHeight - gridFixedFilterContainerHeight
else
if user has reached bottom of filter container (pageYOffset > gridFixedFilterContainerBottom)
then set position fixed and style accordingly
set wasScrollingDownwards true
ser wasScrollingUpwards false
else user has not yet reached bottom AND wasScrollingUpwards earlier
then set position relative and calculate top.
showMoreFilterPositionTop = (
searchFilterPositionTop,
gridFiltersContainerRect,
) => {
const defaultHeaderHeight = 120;
const filterTitleHeight = 60;
const showMoreFilterPositionTop =
Math.abs(
searchFilterPositionTop - gridFiltersContainerRect.top