Skip to content

Instantly share code, notes, and snippets.

View shettayyy's full-sized avatar

Rahul Shetty shettayyy

View GitHub Profile
@shettayyy
shettayyy / index.html
Last active April 30, 2020 21:46
Log atleast o(n) and atmost O(1) five https://jsbin.com/pavecaf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@shettayyy
shettayyy / index.html
Created April 30, 2020 21:44
Check the performance of the function that sums 'n' numbers using loop and math// source https://jsbin.com/tajiyoq
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Check the performance of the function that sums 'n' numbers using loop and math">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@shettayyy
shettayyy / index.html
Last active April 30, 2020 21:43
Double the values in the array
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@shettayyy
shettayyy / retry-api-call.js
Created April 25, 2019 13:00
If the API fails then this code will help in retrying the call
(function() {
sleep = ms => {
return new Promise(resolve => setTimeout(resolve, ms));
};
async function getTokenFromApi() {
let retries = 2;
async function poll(apiCallback) {
let response = {};
@shettayyy
shettayyy / pre-commit-eslint
Last active December 10, 2021 05:27
Pre-commit hook for Linting JS with ESLint before commit.
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
/**
* Flatten an array
* E.g [[1,2,[3]],4] -> [1,2,3,4]
*
* @Contributor Rahul Shetty <rahulshetty@helpshift.com>
* @created Wed Feb 15 12:40:37 2017
*/
function flattenNestedArray(arr) {
var result = [];
@shettayyy
shettayyy / .gitignore
Last active July 12, 2018 16:34
An extensive list of file and folder names to be ignored while working on a node, angular, react and similar types of project. I have referred various gists and sites to prepare this list. Feel free to provide feedbacks.
# Logs
logs
*.log
npm-debug.log*
yarn-error.log
libpeerconnection.log
# Runtime data
pids
*.pid
@shettayyy
shettayyy / head-room.js
Created June 12, 2016 11:39
Auto show hide sliding header using pure javascript
import classie from 'desandro-classie';
export function SlidingHeader(options) {
this.init(options);
}
SlidingHeader.prototype.init = function(options) {
// Define the settings as an object
let settings = {
'element': options.element,
@shettayyy
shettayyy / head-room-with-interval.js
Last active June 12, 2016 11:37
Auto show hide sliding header with setInterval using pure javascript
import classie from 'desandro-classie';
export function SlidingHeader(options) {
this.init(options);
}
SlidingHeader.prototype.init = function(options) {
// Define the settings as an object
let settings = {
'element': options.element,