Skip to content

Instantly share code, notes, and snippets.

View zhyd1997's full-sized avatar
🏠
Working from home

Yadong Zhang zhyd1997

🏠
Working from home
View GitHub Profile
@zhyd1997
zhyd1997 / bash.sh
Last active April 16, 2024 10:24
custom transform function for json schema from supabase.
# Step 1: Download schema types from supabase via download button in supabase dashboard `API Docs` or the script below
# https://supabase.com/docs/guides/api/rest/generating-types
npx supabase gen types typescript --project-id "$PROJECT_REF" --schema public > types/supabase.ts
# Step 2: Transform TS schema types to json
npx ts-json-schema-generator --path './supabase.ts' --type 'Database' -o "./supabase.js"
# Step 3: Copy `schema.definitions.Database.properties['public'].properties.Tables` value into https://jsoneditoronline.org/
# Step 4: Applied custom transform function below:
@zhyd1997
zhyd1997 / firstUniqChar.js
Created August 16, 2022 02:07
`indexOf` vs `Map`
function firstUniqCharWithHashMap(str) {
const map = new Map();
for (let i = 0; i < str.length; i++) {
const char = str.charAt(i);
if (!map.has(char)) {
map.set(char, [i, 1]);
} else {
map.set(char, [i, map.get(char) + 1]);
}
@zhyd1997
zhyd1997 / README.md
Created September 15, 2021 05:37
The following code tries to implement the React Suspense API

3 core issues

  1. mixin useEffect: the order should be
  • Start fetching
  • Start rendering
  • Finish fetching
  1. missing Suspense fallback
  2. not try to read user info before it loaded

I also add lazy reload component here.