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 treeHeight(tree) { | |
if (tree === null) return 0; | |
let subHeights = Array.from(tree.children).map(treeHeight) | |
return Math.max(...subHeights, 0) + 1 | |
} | |
// Another option is to traverse DOM layer by layer | |
function treeHeight2(tree) { | |
if (tree === null) return 0; | |
const queue = [tree] |
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
{ | |
"openapi": "3.0.1", | |
"info": { | |
"title": "Swagger Petstore", | |
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", | |
"termsOfService": "http://swagger.io/terms/", | |
"contact": { | |
"email": "[email protected]" | |
}, | |
"license": { |
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
declare const window: any | |
const chainIds: { | |
[chainId: string]: string | |
} = { | |
ethereum: '0x1', | |
bsc: '0x38', | |
} | |
const rpcUrls: { |
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
declare const window: any | |
// account is the ethereum address | |
export const signMessage = async (account: string, message: string) => { | |
const { ethereum } = window | |
if (!ethereum) return | |
try { | |
const signature = await window.ethereum.request({ | |
method: 'personal_sign', | |
params: [account, message], |
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
[ | |
{ | |
"name": "Ethereum Mainnet", | |
"chain": "ETH", | |
"network": "mainnet", | |
"icon": "ethereum", | |
"rpc": [ | |
"https://mainnet.infura.io/v3/${INFURA_API_KEY}", | |
"wss://mainnet.infura.io/ws/v3/${INFURA_API_KEY}", | |
"https://api.mycryptoapi.com/eth", |
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
import * as React from 'react' | |
function lazyImport< | |
T extends React.ComponentType<any>, | |
I extends { [K2 in K]: T }, | |
K extends keyof I | |
>(factory: () => Promise<I>, name: K): I { | |
return Object.create({ | |
[name]: React.lazy(() => | |
factory().then(module => ({ default: module[name] })) |

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
import * as React from 'react'; | |
import { providers } from 'ethers'; | |
const logout = async () => | |
axios | |
.get('/api/auth/logout') | |
.then(_ => _) | |
.catch(_ => console.log(_)); | |
export const useDetectAccountChange = () => { |
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
// don't use this. I'm not sure if this is a good solution | |
// keeping it as notes till I find a better solution | |
// assume you got this from a JSON file: | |
const statesWeather = { | |
"wisconsin": "cloudy", | |
"california": "rainy", | |
"newyork": "sunny", | |
"florida": "cloudy", | |
"texas": "rainy", |
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
// Usage | |
console.log("\x1b[32m", "color colorr colorrrrr") | |
const colors = { | |
reset: "\x1b[0m", | |
bright: "\x1b[1m", | |
dim: "\x1b[2m", | |
underscore: "\x1b[4m", | |
blink: "\x1b[5m", | |
reverse: "\x1b[7m", |