Skip to content

Instantly share code, notes, and snippets.

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]
{
"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": {
declare const window: any
const chainIds: {
[chainId: string]: string
} = {
ethereum: '0x1',
bsc: '0x38',
}
const rpcUrls: {
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],
@o-az
o-az / ethereum_chains.json
Created December 22, 2021 21:57
All Ethereum chains info & metadata
[
{
"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",
@o-az
o-az / use-named-lazy-import.tsx
Created December 24, 2021 05:09
Lets you React.lazy import named exports
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] }))
@o-az
o-az / avatar.png
Last active January 13, 2022 17:18
avatar.png
@o-az
o-az / useDetectAccountChange.ts
Created February 19, 2022 06:44
a react custom hook to detect account change and do things
import * as React from 'react';
import { providers } from 'ethers';
const logout = async () =>
axios
.get('/api/auth/logout')
.then(_ => _)
.catch(_ => console.log(_));
export const useDetectAccountChange = () => {
@o-az
o-az / object.keys_literal_types.ts
Created March 30, 2022 07:16
Object.keys(obj) array to string literal types
// 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",
// 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",