Skip to content

Instantly share code, notes, and snippets.

View ntnbst's full-sized avatar

Nitin bisht ntnbst

View GitHub Profile
function myForEach<T>(arr: T[], forEachFunc: (v: T) => void) {
arr.reduce((acc, val) => {
forEachFunc(val)
return undefined;
}, undefined)
}
function myFilter<T> (arr: T[], filterFunc: (v: T) => boolean): T[] {
return arr.reduce((acc: T[], val) => {
if (filterFunc(val)) {
@ntnbst
ntnbst / error-boundary.jsx
Last active May 10, 2020 15:33
This gist has a simple implementation of error boundary (errors that occurs in react callstack unlike - promises or async calls)
// Using react-error-boundary library to handle custom error component in case of dom failure
// Error boundary will render the fallback component to its decendents in case of failure
// So we can add multiple error boundaries according to project
import { useState } from 'react'
import ReactErrorBoundary from 'react-error-boundary'
const ErrorBoundary = ReactErrorBoundary.ErrorBoundary
function ErrorFallback ({ error }) {
@ntnbst
ntnbst / safariOnly.css
Created April 26, 2020 08:04
Target only safari browser - CSS
@media not all and (min-resolution:.001dpcm)
{ @supports (-webkit-appearance:none) {
.safari_only {
color:#0000FF;
background-color:#CCCCCC;
}
}}
.full-width {
left: 50%;
margin-left: -50vw;
margin-right: -50vw;
max-width: 100vw;
position: relative;
right: 50%;
width: 100vw;
}
const D = document
const $ = D.querySelector.bind(D)
const $$ = (selector, startNode = D) => [...startNode.querySelectorAll(selector)]
@ntnbst
ntnbst / gist:291dac8d585436c98d1c824dcbc33d96
Last active July 16, 2018 17:43 — forked from bradtraversy/webdev_online_resources.md
Online Resources For Web Developers (No Downloading)
We couldn’t find that file to show.
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
@ntnbst
ntnbst / git-prompt.sh
Created January 5, 2018 15:58
Change Git Prompt
PS1='\[\033]0;Terminal: ${PWD//[^[:ascii:]]/?}\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[33m\]' # change to green
PS1="$PS1"'❯' # ->
PS1="$PS1"'\W ❯'
PS1="$PS1"'\[\033[0m\]' # change color
MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc
# 🎵 💎⭐🔥➤
@ntnbst
ntnbst / .hyper.js
Created January 5, 2018 15:56
hyper config for gitbash
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// POKEMON THEME CONFIG
// pokemon: 'gengar',
// STAR WARS THEME CONFIG
// StarWarsTheme: {