ToCode
Open in Telegram
ืืืคืื ืงืฆืจืื ืืืชืื ืชืื ืืืช ืื ืื ืคืจืง
Show more1 417
Subscribers
-224 hours
-37 days
-630 days
Posts Archive
1 417
ืคืจืืืงื ืืืฉื ืืืชืืืืง ืืื ืื ืจืง ืขืื ืืจื ืืืชืืงืฆืข, ืืื ืืืกืืก ืขืืื ืชืืืื ืื ืกืืช ืืจืืงืื ืืืฉืื ืืื ืืืืื ืืืื ืืืงืฉ ืจืฉืืช.
ืืื ืืืื ืงืืื ืืขืืืื?
ืื ืื ื ื ืืฆืืื ืืชืงืืคื ืืฉืืืขืช ืืื ื ืืืื ืฉืงืฉื ืืืขืช ืื ืืื ืืื. ืืฉ ืกืืืื ืฉืืฉืืืขืืช ืื ืืืืฉืื ืืงืจืืืื ืืืกืคืช ืืฃ ืคืจืืคืื ืขื "ืคืจืืืงืืื" ืืืคืื ืืกืื ืืจื ืืื ืงืืจืืช ืืืื ืืื ืืื ืคืฉืื ืืืกืืฃ ืคืจืืืงื ืงืื ืฉืืื ืืชื ื base44 ืืงืืจืืช ืืืื, ืืืจืื ืฉื ืืคืจืืืงืืื ืืืืืืืืืื ืืืื ืชืืื ืื ืื ืืืืื ืฉืื ืืคืฉืจ ืืืื ืืืืืื ืืื ื ืืืื ืคืจืืืงื ืืืืชื.
ืื ื ืื ืืืืข.
ืืจืืข ืื ืื ื ืขืื ืื ืฉื. ื ืืื ืืืืื ืืฉืื ื ืืกืชืื ืขื ืงืื ืฉื ืืชื ืขื ืืื Vibe Coding ืืฉ ืื ืืขืืืช ืืื ืืืืชื ืฆืจืื ืืืืื ืงืื ืืื ืืงืืจืืช ืืืื ืืืจ ืืืื ืื ืืื ื ืจืื ืื ืืฉืื. ืืฉืืื ืืืคืขืื ืืืื AI ืืืงืื ืชืืฆืื ืฉื ืงืื ืืจืื ืืืืื ืฆืจืื ืืืืืจ ืืช ืืืืืจ ืืืงืฆืืขื ืืจืื ืืืื, ืืืื ืืืขืชื ืื ืื ืืืื ืืฉื ื. ืื ืืื ืคืืชืื ืฉืืงืจืื ืืช ืืงืื ืฉื ืืคืจืืืงื ืืืื ื ืื ืืจืื ืืืงืฆืืขืืช ืฉื ืืืคืชื, ืื ืื ืืื ื ืขืืจ ื AI, ืืืืขืฉื ืื ื ืืืฉื ืฉืจืื ืืงืฆืืขืืช ื ืืืื ืื ืืฉืื ืฉืจืืืื ืืคืืื ืืืชืจ ืืืืจืืจ ืืฉืื ืฉืื ื ืขืืจืื ื AI.
ืืื ืืืขืจืืชื ืคืจืืืงื ืืืฉื ืืจืื ืืืืื ืขืืืื ืืืื ืืคืชืื ืืืชืืช. ืื ืืืื ืืืขืจืื ืฉืื ืขื ืืชืืงืฆืขืืช ืคื ืื ื ืฉื ืืืืืืช ืืืื ืื ืืืืืืืช ืกืืื ืืขืชืื.
ืืกืืื ืืืืื ืืคืืชืื ืคืจืืืงืืื
ืื ืื ืืืื ืื ื ืืืื ื-ืืืื? ืืื ืขืืงืจื ืืืืจืื:
1. ืฉืืืฉื ืฉืืืขืืช ืฉื ืืืคืืื ืคืจืืืงื, ืกืืืจื ืืื ืืืืืืช, ืืชืืืช POC ืืื ืืืืงืจ ืฉืืกืืื. ืืื ืืื ืืื ืืืื ืืขื ืคืืืืง ืืคืืจื ืขื ืืขืืืื ืฉืืื ืืื ืืืืืข ืืืืคืืื ืืื ืืื ืฉืืคืฉืจ ืืืืืืฉืฃ ืืืื ืืืืืืืช ืืืฉืืช ืฉืืืื ืื ืืชื ืกืืชื ืืื ืขืืืื.
2. ืืืืฉื ืฉืืืขืืช ืฉื ืคืืชืื ืืคื ืชืืื ืืช ืืคืืจืืช ืืืืฉืืช ืฉืื ื ืืขืืืจ ืืื ืืื ืืช. ืืชืืื ืืช ืื ืืื ืขื ืืขืืื ืฉืืืขืืื ืืืฉ ืืื ืืืืฉืืช ืืขืืื ืืืื ืฉื ืื ืืื.
3. ืืคืืฉ ืืื ืคืขื ืืฉืืืข ืื ื ืจืื ื ืงืืืืช ืืจืืืืืช ืืืคืจืืืงื ืฉืืื ืืืืคืจืืืงืืื ืฉื ืืืจืื ืืงืืืฆื, ื ืืืจ ืขื ืืชืืจืื ืืจืืืืื ืฉืขืื ืืืื ืคืชืจื ื ืืืชื (ืืื ืืืงืื).
4. ืฉืืขืืจ ืฉืืืขื ืขื ื ืืฉื ืืฉืืชืฃ ืืืืื ืืื ืืืฆืืขืื, ืืืืืช ืืืืข, ืืจืืืืงืืืจื, ืืื AI ืืขืื.
ืื ืืืจ ืืฉ ืืื ืจืขืืื ืืคืจืืืงื ืืืืืื ืืจืฉืื ืืืชื ืืืฃ ืืจืืฉืื ืืื:
https://www.tocode.co.il/mentoring
ืื ืืชื ืจืืฆืื ืืืฉืชืชืฃ ืืื ืืื ืจืขืืื ืื ืฉืื ืืกืคืืง ืกืืืจืื, ืื ืืคืืื ืจืืฆืื ืืฉืืืข ืขืื ืคืจืืื ืขื ืืืกืืื - ืชืฉืืืจื ืื ืืืืขื ืื ืชืื ืฉืืืช ืืืขืืฅ ืืกืืืจืช.
1 417
ืืืจื ืคืกื ืืืืข - ืืืื ื ืืืจ ืขื ืคืจืืืงื ืชืืื ื
ืืื ืคืืชืื ืคืจืืืงื ืชืืื ื ืืืฉื ืืื ืขืืืื ืืจื ืืืืืฆืช ืืืชืงืื ืืชืืจ ืืคืชืืื?
ืชืืฃ ื ืจืืื ืขื ืืฉืืื ืืืืช ืืื ืืคื ื ืฉืืฉืื, ืื ืชืกืืืื ืืืชื ืฉืืชืฉืืื ืืืืืืช (ืืื ื ืืงืืื ืฉืชืกืืืื), ืืืื ื ืืงืจืื ืื ื ืคืืชื ืงืืืฆื ื ืืกืคืช ืืืกืืื ืคืืชืื ืืคืจืืืงืืื, ืื ืชืงืืื ืืช ืืืกืืจืช ืืืืืื ืืื ืืช ืคืจืืืงื ืชืืื ื ืืืฉื ืฉืืื ืืจืื ืืืืื ืืขื ืฉืืืื ืืื AI ืืื ืืชืืืืืืืืืช ืืคืืชืื ืืขืืื ืืืช. ืื ืืฉ ืืื ืจืขืืื ืืคืจืืืงื ืืืชื ืืืคืฉืื ืืืืื ืืช ืืืืฆืื ืืืชื ืืืืืืจื ืื ื ืฉืืื ืืืื ื ืืืืื ืืชืช ืืช ืืืืืคื ืืืขืืืจ ืืื ืื ืฉืืคืฉืจ. ืคืจืืื ืืื:
https://www.tocode.co.il/mentoring
ืืขืืฉืื ืืคืืกื.
ืืื ืคืืชืื ืคืจืืืงื ืืืฉื ืืื ืขืืืื ืืืจื ืืืชืงืื ืืชืืจ ืืคืชืืื?
ืืฉืืื ืืืืช ืชืืื ืืื ืืืขืื ืื ืืืืื ืืฉื ื ืืฆืืืื. ืืฆื ืืื ืืขืืืื ืขื ืคืจืืืงื ืื ืื ื ืืชืขืกืงืื ืืืืื ืืืจืื: ืฆืจืื ืื ืืืชืื ืืช ื Backend ืืื ืืช ื Frontend, ืื ืืืชืืื ืืืืืืื ืืื ืืืืื ืืืืฆืืขืื, ืื ืืืชืื ืืืืงืืช ืืื ืืืงืื ืชืฉืชืืช CI/CD, ืื ืืืืื ืืื ืืืชืื ืืื ืฉืืคืจืฆื ืืื ืืืขืจืืช ืืื ืืืชืื ืงืื ื ืืื ืฉืืคืฉืจ ืืืื ืืฉื ืืช ืืืชืืืง. ืืื ืืคืฉืจ ืืืฆืื ืืื ืืืขืช ืืช ืื ืื ืืื ืืืชืืงืฆืข ืืชืืื ืืกืืื? ืืื ืื ื ืื ืืชืืงืฆืข ืืืฃ ืชืืื ืืื ืืืื ืืขืืืจ ืจืืืื ืขืืืื?
ืืฆื ืฉื ื ืื ืื ื ืืืืขืื ืฉืคืืชืื ืชืืื ื ืืื ืชืืืื ืืืืืกืื. ื Backend ืืฉืคืืข ืขื ื Frontend, ืืืืืงืืช ืืฉืคืืขืืช ืขื ืืชืืืืงื, ืืืืืช ืืืืืข ืืืฉืคืขืช ืืกืื ืื ืืืชืืื. ืืคืชืืื ืฉืื ืืืืจืื ืืช ืื ืืชืืื ื ืื ืฉืื ืืฆืืืืื ืืจืืืช ืืืชื ืืคืกืคืกื ืื ืงืืืืช ืงืจืืืืืช ืื ืฉืื ืืืื ื ืขื ืืกืืฃ ืืช ืืงืื ืฉืื ืืืชืืื. ืืืชืจ ืืื, ืขื ืืื ืืกื ืฉื AI ืืชืืื ื ืื ืื ื ืืืืจืื ืืจืืืช ืฆืืืชื ืคืืชืื ืฉื ืืื, ืืคืชื ืื ืืคืชืืช ืืืืืืื ืฉื ืขืืจืื ื AI ืืื ืืขืฉืืช ืขืืืื ืฉื 5 ืื ืฉืื. ืืืชืืงืฆืขืืช ืงืืืืช ืืงืืืื ืืืคื ืืืจ.
ืื ืืกืช ืืื AI ืืชืืื ื ืืืกืืคื ืขืื ื ืงืืืช ืืื, ืืืืืื ืืฉืื ืื ื ืืืฉืืื ืขื Vibe Coding. ืื ื ืืืื ืืืื ืืขืืจืช Prompt ืืืืฆืจ ืงืื ืฉื ืืขืจืืช ืืืื. ืืืื ืืื Base44 ื Lovable ืืื bolt ื v0 ืืจืืื ื ืืกืคืื ืืขืืืืื ืื ืฉืื ืืื ืืืข ืืคืืชืื ืืื ืืช ืืขืจืืืช, ืืคืชืืื ืืฉืื ื ืืืกืืฃ ืืงืืจืืช ืืืื ืคืจืืืงื ืฉืื ืืชื ืื ืื ืืจืฉืื ืืฃ ืืื. ืื ืืืืข ืื ืืืืช ืืชืืชื ืืช ืื ืืื ืื ืฉื ืชืชื ื AI ืืขืฉืืช ืืช ืจืื ืืขืืืื ืืืคืจืืืงื ืืื ืืืืื ืื ืืืืืฉืื ืืืงืืื.
ืืื ืืฉืื ืฉืืืื ืืื ืคืจืืืงื ืืืฉื
ืืจืขืืื ืืจืืฉืื ืฉืืืื ืืงืืช ืืื ืืื ืฉืืชืืงืฆืขืืช ืืื ืื ืืื ืืจืืช ืืืื ืื ืืื ืืื. ืื ื ืืื ืืืืืืืช ืืืืืื ืืืืช ืฉืื ืืช ืฉืืคืชืืื ืืืืืื ืืืฉืชืคืจ ืืื:
1. ืืืืืืช ืืงืืช ืืฉืืืช ืคืืชืื ืืืืฆืข ืืืชื, ืืืืืจ ืืืืืจ ืขื ืงืื ืฉืขืืื.
2. ืืืืืืช ืืจืืืช ืืื ื ืฉื ืืขืจืืช ืืืขืืื ืืชืื ืืืืืื, ืืืืืจ ืืขืืื ืืช ืืงืื ืืื ืืฉืืืจ ืื ืืืช ืืกืื ืฉื ืืืขืจืืช.
3. ืืืืืืช ืืืืืช ืืืกืืจืงืฆืืืช ืืืืฆืืจ ืืืชื ืืื ืืฉืคืจ ืืช ืืฉืคื ืฉื ืืืขืจืืช.
4. ืืืืืืช ืืืืื ืืื ืืืืืื ืืืฉื.
5. ืืืืืืช ืืจืืืช ืืกืคืจ ืคืืชืจืื ืืช ืฉื ืืขืื ืืืฉืงืื ืืชืจืื ืืช ืืืกืจืื ืืช ืฉื ืื ืืืฉื.
6. ืืืืืืช ืืจืืืช ืงืืืื ืืืืืืช ืืื ืฉืื ืื ืืกืืื ืืฉืคืืข ืขื ืืืขืจืืช ืืขืชืื ืื ืขื ืืืงืื ืืืจืื ืืืขืจืืช.
7. ืืืืืืช ืืืขืจืื ื ืืื ืืื ืืืืงืฃ ืขืืืื ืขื ืคืืฆ'ืจ ืืกืืื.
8. ืืืืืืช ืืขืืื ืืืื ืื ืื ืขื ืืฉืืื ืืืฆืืข ืคืฉืจืืช, ืืืืื ื ืืืื ืคืฉืจืืช ืืคืฉืจ ืืืฆืข ืืขื ืื ืื ืืคืฉืจ ืืืชืคืฉืจ.
ืืืืืจ ืืืชืืงืฆืขืืช ืืคืืชืื ืชืืื ื ืืืจืืืช ืืืืื ืืงืืืจืื ืฉืื ืื, ืืฉ ืื ืืืื ืืืจืื ืฉืืคืฉืจ ืืขืฉืืช ืืื ืืืชืืงืฆืข ืืืคืชืื ืชืืื ื. ืื ืืคืขืืืืืืช ืืืื ืืฉืืืืช ืืืขืืจื ืืื ืืืืืช ืืคืชืืื ืืืืื ืืืชืจ:
1. ืงืจืืืช ืกืคืจื ืชืืืืจืื ืืืืขื ืืืืฉื.
2. ืคืืชืจืื ืชืจืืืืื ืงืื ืื ืืืื ืืืืืื ืฉืืชื ืืืืืื.
3. ืคืืชืจืื ืชืจืืืื ืืืืืจืืชืืืงื ืื ืกืืืืืืืช.
4. ืชืจืืืช ืงืื ืืคืจืืืงื ืงืื ืคืชืื (ืืืื ืืฉืืืชืืืงืื ืืชืืื ื ืื ืฉืืงืื ืฉืืื ืื ืืชืืื ืื ืืืื ืื ืืืืืืื ืขื ืฉื PR ืืชืงืื).
5. ืฉืืคืืจ ืืืฆืืขืื ืฉื ืืขืจืืช ืงืืืืช.
6. ืืืืื ืืขืืืช ืืืืื ืืงืื ืฉืืชื ืืชืืชื ืื ืฉืืืฉืื ืืืจ ืืชื.
7. ืงืจืืืช ืชืืขืื ืฉื ืกืคืจืื, ืื ืงืืจืก ืืงืฆืืขื ืขืืื.
8. ืืืกืคืช ืคืืฆ'ืจ ืืคืจืืืงื ืืืื, ืื ืชืืงืื ืืื ืืคืจืืืงื ืืื.
ืืื ืื ืคืืชืื ืคืจืืืงื ืขืฆืืื ืฉืืื. ืคืจืืืงื ืืืฉื ืฉืืืืฆืข ืืื ืืืื ืืืืืช ืืกืืก ืืื ืืื ืกืื ืืชืืงืฆืขืืช ืฉืชืืืจื - ืืื ืืืคืฉืจ ืืื ืืืืื ืขื ืืืืืช ืืืืข, ืขื ืืืฆืืขืื, ืขื ืืชืืืช ืงืื ืฉื ืืชื ืืืจืืื, ืืื ืืืคืฉืจ ืืื ืืืขืื ืืงืื ืืืจืืืช ืื ื ืฉืืจ ืืืื ืืืชืื ืงืื ืฉืืืฉืืจ ืคืืืช. ืืื ืืืชื ืืื ืืงืื ืืืชื ืกืืช ืขื ืืืืืืจืืชืืื ืืืืฉืื ืฉืืืืชื ืื ืขื ืกืคืจืืืช ืืืฉืืช ืฉืืืืืชื. ืื ืืืจ ืืื ืืืืื ืืื ืืืงืื ืคืื ืงืฆืืืช Lambda, ืืื ืืืจ ืืจืื ืืืชืจ ืืืื ืืฉืคืื ืงืฆืืืช ื Lambda ืฆืจืืื ืืืชืืืจ ืขื ืืขืจืืช ืืืืื ืฉืืฉ ืื ืืืืืื ืคื ืืื ืฉืืชื ืืื ืื. ืืืชื ืืืจ ืืืื ืืืืกืื ืงืืฆืื ืขื S3, ืืืืืจ ืืฉืชืืฉืื, ืืืืขืช ืฉืืจืืช ืฆื-ืฉืืืฉื ืื ืื ืื ืื ืื ืืืจ.
1 417
ืื ืืืืื ืืืชืจ
ืืืช ืืืืืืืืช ืฉืื ื ืื ืืืื ื next ืืื ืืืืฉืื build ืืฉืืฉ ืฉืืืืืช TypeScript ืื ESLint. ืืืืืจ ืื ืื ื ืืืื ืืช ืืืฉืืืืช, ืืืจืืจ ืื ืืื ืฆืจืื ืฉืืืื ืกืื ืืจืืื ืืคืจืืืงื ืืื ืืฆื ืฉื ื ืืฉ ืชืืงืื ืื ืฉืื ื ืืขืื ืื ืขืืฉืื ืฆืจืื ืชืืงืื ืืื ื ืืืืข ืฉืขืื ืืื-ืืืืืื ืื ื ืืืืืฃ ืืื ืื ืื ืืืชืจ ืืื ืื ืฉืื ืืืฉ ืื ืืฉืืืื ืืื ื ืืืื ืืืืืช ืขื ืืืื ืืฉืชื ื ืฉืื ืืฉืชืืฉืชื ืื. ืืืืื ืื ืฉืื ืื ืืฉืื ืื ืฉ ESLint ืืืื ืืืจืื ืืืื ืชืืื ืืืคืขืื ืืช ืื ืขืฆืืืืช ืืงืื ืคืืืืจืฆืื ืื ืืจื Hooks ื git.
ืืื ืืืคื ืขื ืืืืจืื ื ืืฉืืชื ืฉืื ืคืฉืื ืืขื ืื ืคืืคืืืจืืช ืฉืื, ืืื ื ืืืื ืืืฆืืื ืขื IDE ืืืฉ ืืฉืืื AI ืืฉื Firebase Studio, ืฉืขืืฉื ืงืกืืื ืขื ื ืงืกื 15 ืืืืืช ื ืจืื ืืืื ืืืื ืชืืื ืื ืื ืืืงืฉื ืขืืื ืืกืฃ, ืืืกืืืจืืจ ืฉื ืคืจืืืงื ืืืฉ ืืชืืื ืขื ืงืืืฅ ืืงืื ืคืืืืจืฆืื ืฉืื:
import type {NextConfig} from 'next';
const nextConfig: NextConfig = {
/* config options here */
typescript: {
ignoreBuildErrors: true,
},
eslint: {
ignoreDuringBuilds: true,
},
};
export default nextConfig;
ืฉื ื ืฉืืืจืืืื ืฉืื ืืืืชื ืขืืฉื ืืกืืืจืืจ ืืื ืื ืืฉืืจื ืืช ืจืืืงื ืืืืจืกื 19 ืืืช ืืืืืืืื ื ืืืืจืกื 4, ืื IDE ืขืฆืื ืืชืืื ื ืืืืืื ืฉืื ืืื ืฉืฉืืื ืขื ื'ืืื ื ืื ืืชืืืกืช ืืืืืืืืช ืืงืืืฅ ืฉืขืืฉืื ืคืชืื ืืขืืจื.
ืืื ืืืคื ืขื ืืื ื ืื ืืคืฉืจ ืืืชืืื ื. ืืคืฉืจ ืืืชืืื ืืงืืื ืืืชื ืืื:
https://firebase.studio/1 417
ืืืื ืืืืชื: ืืืืื ืืืืืืื ืืคืืืชืื
ืื ื ืื ืืืื ืฉืืฉืชืืฉ ืืงืื ืืื ืืื ืืื ืืื ืืืื ืื ืืฉืชืฃ ืืืชื ืืื - ื ื ืื ืฉืืฉ ืืื ื ืงืืืช ืงืฆื ืืคืืืกืง ืฉืืืืืจื JSON, ืืฉืื ืืื:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def hello():
message = "Hello, world!"
return jsonify(message=message)
if __name__ == '__main__':
app.run(debug=True)
ืืืชื ืืงื ืืื ืืืืืื ืืืงืืืืื ื JavaScript ืฉืืืืืื ืคืฉืื ืืืชืื:
return {message}
ืืื ืฆืจืืืื ืืืืืจ ืขื ืืฉื ืคืขืืืื, ืคืขื ืืืช ืืฉืืื ืืืคืชื ืืคืขื ืฉื ืืื ืืฉืืื ืืขืจื, ืื ืืชื ืืืืืื ืืืชืื:
@app.route('/hello', methods=['GET'])
def hello():
message = "Hello, world!"
return jsonify(**locals())
ืืื ืืงืื ืืืืืง ืืช ืืืชื ืชืืฆืื, ืืืื ืืืงืืื ืืช ืฉื ืืืฉืชื ื ืืคืืื ืคืขื ืืืช. ืื, ืื ืืชื ืืืฉืฉืื (ืืฆืืง) ืฉืืืื ืืฉืชื ื ืฉืื ืืชืืืื ืชื ืืืื ืก ืืื ื JSON ืชืืืื ืืืชืื:
@app.route('/hello', methods=['GET'])
def hello():
message = "Hello, world!"
return jsonify(**{k: v for k, v in locals().items() if k in ['message']})
ืืื ืื ืงืฆืช ืืจืื ืืื ืืคืฉืจ ืืงืฆืจ ืขื ืคืื ืงืฆืืืช ืขืืจ ืืื ื ืงืื:
def only(d, *keys):
return {k: d[k] for k in keys}
@app.route('/hello', methods=['GET'])
def hello():
message = "Hello, world!"
foo = 10
bar = 20
return jsonify(**only(locals(), 'message', 'bar'))
ืืืื? ืืื. ืืื ืื ืืืืชื ืจืืฆื ืืจืืืช ืืช ืื ืืงืื ืืืืชื. ืืืืกืืื ืื ืืกืคืืง ืืฉืื ืืฉืืื ืืจืืืช ืงืื ืื ืกืื ืืจืื.1 417
next unless map.contains(node)
# Calculate Manhattan distances from the node to each antenna
dist1 = (node.x - p1.x).abs + (node.y - p1.y).abs
dist2 = (node.x - p2.x).abs + (node.y - p2.y).abs
# An antinode occurs when one antenna is exactly twice as far away as the other
if dist1 == 2 * dist2 || dist2 == 2 * dist1
# Store this antinode location (using a string key to ensure uniqueness)
key = "#{node.x},#{node.y}"
antinode_locations[key] = node
end
end
end
end
* The answer is the number of unique antinode locations *
puts "The number of unique locations containing an antinode is: #{antinode_locations.size}"
ืืืขืืช ืฉื ืงืืื ืืคืืชืจืื ืืฉืืืฉื ืืขื ืืื ืช - ืชืืืื ืืื ืืคืขืื ืืช ืืคืื ืงืฆืื ืฉืื ืืื ืืืฆืื ืืช ื Antinodes:
antinode1, antinode2 = p1.find_antinodes(p2)
ืืื ืื ืืื ืืืืื ืฉืืชืืฆืืืช ืฉื ืืคืื ืงืฆืื ืืืืช ืืงืืืืืช ืืช ืชื ืื ืืืจืืง ืืฉืืื:
dist1 = (node.x - p1.x).abs + (node.y - p1.y).abs
dist2 = (node.x - p2.x).abs + (node.y - p2.y).abs
* An antinode occurs when one antenna is exactly twice as far away as the other *
if dist1 == 2 * dist2 || dist2 == 2 * dist1
# Store this antinode location (using a string key to ensure uniqueness)
key = "#{node.x},#{node.y}"
antinode_locations[key] = node
end
ืื ืืืืืง ืืื ืืืืื ืืืืชืจ ืื ืืจืืฉ ืืฆืจื ื ืืช ืื ืงืืืืช ืื ืฉืื ืืืื ืืืจืืง. ืื ืืกืจืืืืืืฆืื ืฉื ืืงืืืืจืืื ืืืช ืืืืจืืืช ืืืืชืจืช ืื ื Ruby ืืคืฉืจ ืืฉืืืจ Data Object ืืชืืจ ืืคืชื ื Hash.
ืืกืงื ืืช
ืื ืื ืืืื ื ืืื ืืกืื? ืืื ืชืืื ืื ืืจืื. ืื ื ืืื ืืกืงื ืืช ืฉืื ื ืืืงื:
1. ืืขืืืื ืขื AI ืืฉืื ืื ืกื ืืฆืืจื ืืืืืงืช ืืช ืืืขืื.
2. ืงืืื ืื ืชืืื ืืืืื ืืชืืขืื ืื ืืืืืืฉ ืฉืื ื. ืืื ืชืืื ืื ืืฆืืืชื ืืฉืื ืข ืืืชื ืืืชืื ืืช ืืงืื ืืื ืืืืกืืฃ ืืช ืืืืืงื ืืืคืืื.
3. ืืฆื ืฉื ื ืงืืื ืฉืื ืืืฉืชืืฉ ืืืืืืฉ ืฉืื ื Map ืืื ื ืืกื ืืืชืื ืืขืฆืื ืงืื ืฉืืคืจืกืก ืืช ืืงืื.
4. ืืืื ืืขื ืืื ืืืืื ืืื ืงืืื ืฉืื ืืืฉืชืืฉ ืืคืื ืงืฆืืืช ืฉืืชืืชื ื Map ืืื ืืื ืืืื ืกืงืคืื ืืืื ืืคืื ืงืฆืืืช ืฉืืชืืชื ื Point, ืืืื ืฆืจืื ืืืชืื ืืืกืืจืงืฆืืืช ืืื ืฉ AI ืืจืฆื ืืืฉืชืืฉ ืืื.
5. ืื ื ืืืฉื ืฉืืืขืจืืช ืืืืื ืืขืืืื ืขื Cursor ืืฉืื ืื ื ืจืืฆืื ืืืืื ืฉ AI ืืฉืชืืฉ ืืืืกืืจืงืฆืืืช ืฉืื ืื ื ืืืชืืื (ืืืฉื ืืืืื ืฉืืื ืืฉืชืืฉ ื Custom Hook ืฉืืชืื ื ืืืงืื ืืืชืื ืืืฉ) ืืืื ืืืืกืืฃ ืืงืื ืืงืกื ืฉื ื Prompt ืื ืืืืืช ืงืื ืฉืืฉืชืืฉืช ืืืืชื ืืืกืืจืงืฆืื. ืืืื ืื ืืคืืื ืืืชืจ ืืฉืื ืืืงืื ืืืงืืจื ืฉื ืืืืกืืจืงืฆืื.
6. ืื ืื ื ืขืืืื ืืืืืื. ืืขืืืื ืขื AI ืื ืฉืืฉืื ืื ืืขืฉืืช ืืื ืฉืืืชืจ ื ืืกืืืื ืืื ืืงืืช "ืืืื ืืฆืืข", ืื ืืฉื ื ืื ืืืชื ืืืชื. ืชืจืื ืื ืขืืื ืืื ืืชืืฉืืื ืืืืืง ืืฉืืืฆืืื ืืืืืื ืืืฉืื.1 417
ืืืฉืืชื ืืช ืืืืืงื ืขื ืคืจืืืคื ืืืชืจ ืืจืื. ืืคืขื ื ืชืชื ืื ืชืืขืื API Docs ืฉื ืฉืชื ืืืืืงืืช ืฉืืชืืชื (ืงืืื ืขืฆืื ืืฆืจ ืืช ืืชืืขืื ืืฉืืื ืืืจืช ืืืชื) ืืื ืืช ืืืขืื. ืื ื ืืืืืจ ืฉืืคืืชืจืื ืฉืื ืืืจื ืฉืืชืืชื ืืช ืืงืื ืืฉืชื ืืืืืงืืช ืืคืืชืจืื ืขืฆืื ืืงื ืืขืจื 5 ืฉืืจืืช. ืืื ืฉืืฉืืชื ืงืืื ืืกืชืื ืืขืืงืจ ืขื ืืื ืช ืืฉืืื ืืื ืชืืขืื ื API ืื ืขืืจ ืื ืืืฉืื ืืืคืขื ืืื ืืืคืืก ืงืื ืฉืืื ืืจืืฆื ืืื ื ืืืจื 4 ืคืขืืื ืืืื.
ืืืืกืจืื? ืืงืื ืื ืขืื ืืืืคืืก 0. ืื ืื ืฉืงืืื ืืืคืืก:
Point = Data.define(:x, :y) do
def manhattan_distance(other)
[
(self.x - other.x).abs,
(self.y - other.y).abs
]
end
def find_antinodes(other)
# Calculate the differences between the two points
dx = other.x - self.x
dy = other.y - self.y
# Create antinode points
antinode1 = Point.new(self.x - dx, self.y - dy)
antinode2 = Point.new(other.x + dx, other.y + dy)
[antinode1, antinode2]
end
end
class Map
attr_reader :index_by_letter, :max_x, :max_y
def initialize(input_file_name)
@index_by_letter = Hash.new { |h, k| h[k] = [] }
@max_x = 0
@max_y = 0
File.readlines(input_file_name).each_with_index do |line, y|
line = line.chomp
@max_x = [line.length - 1, @max_x].max
@max_y = [y, @max_y].max
line.chars.each_with_index do |char, x|
unless char == '.'
@index_by_letter[char] << Point.new(x, y)
end
end
end
end
def contains(p)
p.x >= 0 && p.x <= @max_x && p.y >= 0 && p.y <= @max_y
end
end
def find_antinodes(map)
antinodes = Set.new
# Process each frequency (letter)
map.index_by_letter.each do |letter, positions|
# We need at least 2 antennas with the same frequency
next if positions.length < 2
# Check all pairs of antennas with the same frequency
positions.combination(2).each do |p1, p2|
# Calculate Manhattan distance components
diff_x, diff_y = p1.manhattan_distance(p2)
# Skip if the points aren't aligned (Manhattan distance check)
next unless diff_x == 0 || diff_y == 0 || diff_x == diff_y
# Calculate total Manhattan distance
total_distance = diff_x + diff_y
# Calculate distance between p1 and midpoint
mid_x = (p1.x + p2.x) / 2.0
mid_y = (p1.y + p2.y) / 2.0
dist_to_mid = (p1.x - mid_x).abs + (p1.y - mid_y).abs
# Check if one antenna is twice as far from the midpoint as the other
# This is equivalent to checking if the ratio of distances is 1:2
next unless (total_distance % 3 == 0)
# Calculate antinodes
antinode1, antinode2 = p1.find_antinodes(p2)
# Add antinodes if they're within map bounds
antinodes.add(antinode1) if map.contains(antinode1)
antinodes.add(antinode2) if map.contains(antinode2)
end
end
antinodes.size
end
map = Map.new("input.txt")
puts find_antinodes(map)
ื ืืกืืื 3 - ืงืื ืืืืืงืืช ืขืฆืื
ืคื ืืื ืชื ืฉ API Docs ืื ืืืื ืื ืืืจื ืืื ืืืื ืืขืืื ืืช ืงืืื ืืขืืื ืืืืืชื ืื ืกืืช ืืืืื ืืืจ ืืืืืงืชื ืืงืืื ืืช ืืงืื ืืืื ืฉื ืฉืชื ืืืืืงืืช Map ื Point.
ืืคืขื ืงืืื ืืชื ืืืืง 8 ืคืืชืจืื ืืช ืืจืง ืืชืฉืืขื ืืื ืขืฆืจ ืืืืจืื ืฉืืคืืชืจืื ืขืืื ื ืืื. ืืื ืฆืืง. ืืืจืืช ืืืืจื ืืคืืชืจืื ืืฆืื ืืช ืืชืฉืืื ืื ืืื ื:
* Solution for the Easter Bunny antenna problem *
* Load the map *
map = Map.new('input.txt')
* Track unique antinode locations using a hash for O(1) lookup *
antinode_locations = {}
* For each frequency *
map.index_by_letter.each do |freq, antennas|
# Skip if there's only one antenna with this frequency
next if antennas.length < 2
# Process each pair of antennas with the same frequency
antennas.combination(2) do |p1, p2|
# The find_antinodes method calculates potential antinode points
# based on the relative positions of p1 and p2
antinode1, antinode2 = p1.find_antinodes(p2)
# Check both potential antinodes
[antinode1, antinode2].each do |node|
# Skip if the node is outside the map boundaries1 417
ื ืืกืื Advent Of Code ืืื 8 ืืงืืื
ืืืจื ืฉืคืชืจืชื ืืช ืืืืง ืืจืืฉืื ืฉื ืืื 8 ืฉื Advent Of Code ืืืคื ื ืืกืืืื ืฉื ืืืืง ืืฉื ื ืจืฆืืชื ืื ืฆื ืืช ืื ืืกืืืื ืืืืืืืื ืฉื ืืจืืง ืืืกืื ืืื ืืืขืื ืงืฆืช ืืงืืื ืื ืชืชื ืื ืืคืชืืจ ืืช ืืืชื ืชืจืืื ืืฉืืืฉ ืืืฉืืช ืฉืื ืืช.
ืืืชืืจ
ืืชืจืืื ืืืืื ืื ืืกืืื ืืื ืื ืื ืืกื ืืฆืืจื ืืืื ืืขืืืคืช. ืืฉ ืื ื ืืืจืืฆื ืขื ืื ืื ืืช:
............
........0...
.....0......
.......0....
....0.......
......A.....
............
............
........A...
.........A..
............
............
ื ืงืืื ืืกืื ืช ืืงืื ืจืืง ืืื ืชื ืืืจ ืืกืื ืื ืื ื. ืืื ืื ืื ื ืืฉ ืชืืืจืืช ืฉืื ืืชื ืฉืืืคืืข ืื, ืื ืฉืืฉ ืื ื ืืืืืื 3 ืื ืื ืืช ืืชืืืจืืช A ืืขืื 4 ืื ืื ืืช ืืชืืืจืืช 0.
ืื ืฉืชื ืื ืื ืืช ืขื ืืืชื ืชืืืจืืช ืืืฆืจืืช ืืชื ืืฉืืช ืฉื ืงืจืืช Antinode ืืฉื ื ืืฆืืืื ืฉื ืืงื. ืืื ืืืืืฉ ืืช ืืกืืคืืจ ืขื ืืืืืจ ืืงืื ืืื:
..........
...#......
..........
....a.....
..........
.....a....
..........
......#...
..........
..........
ืื ืื ืื ื ืจืืืื ืฉืฉื ื ื a-ืื ืืงืื ืื ืืชื ืืฉืื ืืืืฆืจืื ืงื, ืืื ืืืจืืืื ืืช ืืงื ืงืฆืช ืืื ืฆื ืืืงืืืื ืฉืชื ื ืงืืืืช ืืืฉืืช ืฉืื ื Antinodes, ืืกืืื ืืช ืืกืืืืืืช.
ืืืชืืจ ืืื ืืืฆืื ืืช ืื ืื ืงืืืืช ืืืคื ืืื ืืฉ Antinode, ืืฉืฆืจืื ืืฉืื ืื ืฉืื ืืฉ 3 ืื ืื ืืช ืืืชื ืชืืืจืืช ืื ืื 2 ืืื ืืืฆืจื Antinode.
ืืคืืชืจืื ืฉืื ืืชืจืืื ืืฉืคืช ืจืืื ืืื:
* frozen_string_literal: true *
Point = Data.define(:x, :y) do
def manhattan_distance(other)
[(x - other.x).abs, (y - other.y).abs]
end
def find_antinodes(other)
diff_x, diff_y = manhattan_distance(other)
if x < other.x
if y < other.y
# p1 is to the left and above p2
antinode1 = Point.new(x - diff_x, y - diff_y)
antinode2 = Point.new(other.x + diff_x, other.y + diff_y)
else
# p1 is to the left and below p2
antinode1 = Point.new(x - diff_x, y + diff_y)
antinode2 = Point.new(other.x + diff_x, other.y - diff_y)
end
else
if y < other.y
# p1 is to the right and above p2
antinode1 = Point.new(x + diff_x, y - diff_y)
antinode2 = Point.new(other.x - diff_x, other.y + diff_y)
else
# p1 is to the right and below p2
antinode1 = Point.new(x + diff_x, y + diff_y)
antinode2 = Point.new(other.x - diff_x, other.y - diff_y)
end
end
[antinode1, antinode2]
end
end
class Map
attr_accessor :matrix, :index_by_letter, :max_x, :may_y
def initialize(input_file_name)
@index_by_letter = Hash.new { |h, k| h[k] = [] }
@max_x = 0
@max_y = 0
File.read(input_file_name).lines.each_with_index.flat_map do |line, line_index|
line.chomp.split('').each_with_index.map do |char, column_index|
pos = Point.new(column_index, line_index)
@max_y = line_index if line_index > @max_y
@max_x = column_index if column_index > @max_x
@index_by_letter[char] << pos if char != '.'
end
end
end
def contains(p)
p.x <= @max_x && p.x >= 0 && p.y <= @max_y && p.y >= 0
end
end
m = Map.new('input.txt')
antinodes = m.index_by_letter.flat_map do |_char, positions|
positions.combination(2).flat_map { |p1, p2| p1.find_antinodes(p2) }
end
puts antinodes.filter { |p| m.contains(p) }.uniq.count
ืขืืฉืื ืื ืืกืื ืขื ืงืืื.
ื ืืกืืื ืจืืฉืื - ืจืง ืืืขืื
ืืชืืืชื ืืช ืื ืืกืื ืขื ืืคืจืืืคื ืืื:
Solve the following general problem in Ruby (input is saved in file input.txt)
ืืืจืื ืืืืงืชื ืคืฉืื ืืช ืื ืขืืื ืืชืืืืจ ืฉื ืืืขืื ื Advent Of Code:
https://adventofcode.com/2024/day/8
ืขืืฉืื ืงืืื ืืื ืืขื ืืื ืื ืืื ืืืคืืก ืงืื ืืื ืืืืง ืืช ืขืฆืื ืืืจืืืฉ ืฉืืื ืื ืขืฉื ืขืืืื ืืกืคืืง ืืืื ืืื ืืืคืืก ืขืื ืืืจืกื ืืืื ืืืืืื ืขื ืฉืืื ืืจืืฆื. ืืคืจืืืคื ืืื ืืงื ืื 6 ื ืืกืืื ืืช ืืืกืืฃ ืืื ืืืืข ืืคืืชืจืื ืขืืื.
ื ืืกืื ืฉื ื - ืืืืคื ืงืื ืขื API Docs1 417
ืืื ืืื, ืงืืืืช ืงืืืื!
ืื ืื ืฉื ืืื ืคืขืืืืช Outsource ืืืืจ ืืช ืืืชืืจ - ืืืืื ืื ืืชืช ืืืคืชืืื ืฉืืืืฅ, ืืื ืืืืื ืืช ืืืืืช ืืชืืฆืจ, ืื ืืืื ืืืฉืง ืืขืืืื ืืืื, ืืืื ืืฉืื, ืืืื ืืืืืืช ืื ืืืืืื ืืงืื ืืื ืืืืื ืืืืืืช ืืืื ืืงืื ืืืฉืื ืืืคื ืื.
ืืืจื ืืื ืขื GPT4.1 ื Cursor ืืจืืจ ืืืืจื ืฉืืืช ืืืฆืืืืช ืฉื ืืืื ื.
ื AI ืืืื ืืืชืื ืื ืงืื ืฉื ืืชื ืื ืืจืื ืกืืืจื, ืืื ืืืืจื ืืื ืื ืชืชื ื ืื ืืืชืื ืืกืคืืง ืงืื ืืื ืืืคืื ืืช ืืืขืจืืช ืืืืชื ื ืืชื ืช ืืชืืืืงื, ืื ืืื ืจืืื ืชืืื ืจืง ืืช ืืืืื ืืืื ืืื ืืช ืืชืืื ื ืืืืืื.
ืขืืฉืื ืืชื - ืืืื ืืืืืืช ืืชื ืืชืขืงืฉืื ืืงืื ืืื? ืขื ืื ืืชื ืื ืืืื ืื ืืืชืคืฉืจ? ืืื ืืืฉืืจ ืกืืื ืืืืืจ ืฉืืื ืืงืื ืฉื AI ืฉืืื ืืืชืื?
1 417
ืืื ืืืคืช ืฉ null ืืื ืืืืืงื?
ืืื'ื ืืกื, ืืืืืกื ืฉื ืจืคืืื, ืฆืืืฅ ืืืืจืื ื:
> I no longer think you should learn to code.
ืืืืฉื ืืชืืืืืช ืืื ืืคืจื ืืืจืืื ืืช ืืจืขืืื, ืืืกืืืจ ืฉืืื ืขืืืื ืืืฉื ืฉืืฉ ืืงืื ืืืื ืืกื ืชืืื ื, ืืื ืงืืืื ืืืื ืืืืชืจ. ืืฆืืืฅ ืืืฉื ืืื ืืกืืืจ ืฉืฆืจืื ืืืขืช ืืื ืืืจืื ืืืืืื ืืชืืืจืื ืืื ืืื ืืื ืฆืืจื ืืืขืช ืฉ null ืืื ืืืืืงื ื JavaScript.
ืืื ืืืฉืืืช ืขื ืื-
1. ืืกืคืจืื ืืจื ืืื ืืื ืืชื ืืช JavaScript ืืขืฉืจื ืืืื ื 1995. ืื ื ืืืืืื ืฉืืจืื ืืืจืขืืื ืืช ืืื ืื ืืจืืฉ ืืคื ื ืขืฉืจืช ืืืืื ืืืื, ืืื ืืืื ืืืืช ืคืืืช ืืฉื ื. ืื ืฉืื ืืฉื ื ืื ืฉืขืืืจ ืืจื ืืื ืืื ืฉื 1995 ืืฉืืื ืื null ืฆืจืื ืืืืืช ืืืืืงื ืื ืื ืืืชื ืฉืืื ืืืืชืืช. ืืื ืฉืืงืืืื ืืืืื ืืืื ืืืืื ืืืกืืคื ืฉื ืืืจ ืืืช ืืืชื ืืืืื ืฉืืชืงืืื, ืืื ืขื ืขืื ืืืืช ืืืืืืช ืงืื ืืช, ืื ืืืช ืขื ืืชืจืื ืืช ืืืกืจืื ืืช ืืฉืื, ืฉืื ื ืืื ืืช ืืืืคื ืฉื ืืฉืคื.
2. ืืื ืืกื ืืชืืื ื ืฉืืื'ื ืืฆืืจื ืื ืืืืืง ืื ืฉืื ืฉืืืืจืื ืืืขืช ืืงืื ืืืืืืช ืงืฉืืช. ืื ืื ืฉืื ืืฆืืจืชืืื, ืฉืืืืจืื ืืช ืืืขืจืืช, ืืช ืืืืืืฆืื ืฉืื, ืืช ืืืืืืื ืืืื ืืื ืืืืืืฉ ืื ืื ืื ืื ืืืช ืืืชืจืื ืืช ืืืืกืจืื ืืช ืฉื ืื ืืืืจื. ืื ืืื ืฉืื ืฉืฆืจืืืื ืืืืจ ืืื ืืืืจืช ืืืจืืฉืืช ืืืื ืงืืืื ืืืขืจืืช, ืืื ืื ืื ืื ืืืชืื ืืขืฆืื ืืช ืืงืื ืืื "ืจืง" ืืืืืจื ื AI ืืืื ืงืื ืืืชืื, ืื ืขืืืื ืืฆืืจืื ืืืืืช ืืืื ืืงืฆืืขืืื ืืื ืฉื AI ืืืชืื ืืช ืืงืื ืื ืืื ืขืืืจ ืืืขืจืืช ืืกืคืฆืืคืืช ืฉืืื.
3. ืืื'ื, ืืืืืจืื ืจืืื ื ืืกืคืื ืื ืืืฉืืื ืฉืื ืืกืช ืชืืื ื ืืื ืืืจ ืืฉืื. ืื ื ืขืื ืฆืืืฅ ืืคืขื ืฉื Pratik Kotkar ืฉืงืืื ืืกืืื ืืืื'ื ืืืืชื ืืืื:
> this doesnโt mean engineering is obsolete. The engineering approach to solving problems is now even more crucial to make best use of AI tools. the paradigm of what the focus of engineering just changes from syntax and semantics to problem solving
4. ืขืืฉืื ืืฉืืืืช - ืืื ืืืืืื Problem Solving ืืื ืืกืช ืชืืื ื? ืืื ืืชืืื ืื ืขื ืืืชื ืืืืืื ืืืืช ืฉืืืคืื ืืืชื ื ืืืื ืืกืื ืืืืืื ืฉื ืืขืชืื? ืืื ืื ืกืืืจ ืืืฉืื ืฉืืฉืืงืืืื ืฉื ืืจื ืืื ืืื ื 1995 ืืืืืื ืืืื ืืืชื ื ืขื ืคืืชืจืื ืืขืืืช ืืื ืืกืช ืชืืื ื? ืืืื ืืคืืื ืืืชืจ ืืื ืืืช ืขืื ืืขืจืืช SaaS ?
5. ืืืืื ืืืชื ืืื ืืกืื ืฉื ืืขืชืื, ืฉืืืืขืื ืืคืชืืจ ืืขืืืช ืืืืื ืื ืืช ืืืืืืืช ืืืืืืืฆืื ืืืื ืืื ืืื ืืช ืืืืืื ืืืืช ืฉื ืืืื ืืืืืื, ืื ืืขืฆื ืืืชื ืื ืฉืื ืฉืืืื ืืขืืืง ืืื ืงืื ืขืืื?
6. ืืฉืืืฉืื ืืฆืืข ืืืชืืงื ื"ืืื ื" ืื"ืคืืชืจืื ืืขืืืช" ืืืืื ืขื ืืงืืืื, ืื ื ืืจืืืฉ ืืืืื ืืื ืืฆืืข ืื ืืืืื ืืงืืืง ืฉื ืฉืคื ืืื ืืืืื ืืื ืืืืจ ืื. ืื ื ืื ืืืื ืฉืื ืืคืฉืจื.
ื .ื. ืงืจืืื ืืขื ืืื ืช ืืืื null ื JavaScript (ืชืืจืื ืืงืืจืืื ืืช ืขื ืืื AI)
https://witch.work/en/posts/javascript-why-typeof-null-is-object
1 417
ืืงืืืคืื ื ืื ืงืื ื ืืงืื ืืชืืืืงื ืงืืืืชื ืืคืืฆืช, ืืืื ืืจืืข ืืืจืืช ืฉืืืงืกื ืืื ืืืืจ ืขื field-sizing ืืื ืื ืืฉืชืืฉ ืื ืืคืืชืจืื ืื ืฉืืจ ืขื ืืืืืงืช ืืืคืงื. ืขืืฉืื ืื ื ืืืืจ ืืช ืืชืืืืจืื ืฉืื ืจืง ื ืืชื ื AI ืืืชืื ืืช ืืงืื ืื ืืจืื ืฉืืื ืจืืื ืืืชืื ืื ืืื ืืืื ืืชืืืง ืืช ืืงืื ืืงืฆื ืืงืฆื ืืื ืื ื ื ืฉื ืืฉืชืืช ืงืคื ืืืจืืื. ืขืืืื ืื ืจืืืชื ืืืืืืช ืืื, ืื ืืืจ ืื ืฉืื ืจืืืชื ืื ืฉืืฉืื ื ื ืืชื ื AI ืืขืืืจ ืื ืืงืื ืคืฉืื ืฉืื ืื ื ืืืื ืืืชืื ืืื ืืฆืืื ืืืืืช ืืขืืืช ืืืืฆืืข ืชืืงืื ืื ืืืืื, ืืื ืืื ืฉืืงืื ืืืชืจ ืืจืื ืืื ืื ื AI ืืืชืจ ืงืฉื ืืืืฉืืจ ืืจืืื. ืืืืืื ืืืจืืช ืงืืืืชื ืืืฆืืขืื ืืืืื ืืืชืจ ืืื ืืืืืจ ืฉื ืงืื ืืจืื ืืืชืจ ืงืฉื ืืชืืืืงื (ืื ืืื ืฉืื ืืื ืืืืืื).
ืืืืง 3 - ืฉื ื ืคืจืืืคืืื
ืื ืืกืืื ืฉืืืฉื ืื ื ืจืืฆื ืืืืื ืืช ื AI ืื ืืฉื ืืืืฆืืขืื ืืืชืช ืื ืืืืื ืฉืืฉ ืืื ืืจืืื ืืื ืืืืืฃ ืืืชื ืืืืืื ืคืืชืจืื ื CSS. ืื ื ืืชืืื ืขื:
Code review the following component. Focus on performance. Only explain the problematic points without suggesting fixes.
Consider the larger picture. If there is a simpler way to achieve the same goal please point me to it, but don't implement yet any fixed version.
const ResizingTextArea = ({
value,
}) => {
const ref = useRef(null);
React.useEffect(() => {
if (!ref.current) return;
ref.current.style.height = "inherit";
ref.current.style.height = \${ref.current.scrollHeight}px\;
}, [value]);
return (
<textarea ref={ref} value={value}></textarea>
)
}
ืืคืขื ืื ื ืืงืื ืืกืืจ ืฉื ืื ืงืืืืช ืืืขืืืชืืืช ืฉืืกืชืืื ืืคืืกืงื
> There is a modern, potentially simpler, and more performant approach to achieve self-sizing textareas that relies primarily on CSS, minimizing or eliminating the need for JavaScript-based height calculations on every input change.
ืื ื ืืืฉืื ืืช ืืฉืืื ืขื ืคืจืืืคื ื ืืกืฃ ืืืืชื:
Implement the most simple fix for the performance issue. Use inline style if you need to add CSS. Don't add new files
ืืชืืฆืื ืืคืขื:
const ResizingTextArea = ({
value,
// It's good practice to allow passing other props like onChange, placeholder etc.
...props
}) => {
// No more useRef or useEffect needed for resizing
return (
<textarea
value={value}
style={{
// This CSS property instructs the browser to size the field based on its content
fieldSizing: 'content',
// Optional: Prevents scrollbars from briefly appearing during resize in some browsers
// and ensures it doesn't overflow if a max-height is also applied elsewhere.
overflow: 'hidden',
// You might want to add a minHeight as well
// minHeight: '50px', // Example minimum height
}}
{...props} // Spread remaining props
/>
);
};
ืกืืฃ ืกืืฃ ืืื ืงืืข ืขื ื field-sizing. ืืื ืืืกืืฃ overflow ืฉืื ืืืงืฉืชื ืืื ืืช ื spread ืฉื ืื ืืคืจืืคืก ืืืืจืื ืฉืฉืื ืื ืืืงืฉืชื ืืืื ืืจืืข ืืื ืกืืฃ ืืขืจืืช ืฉืจืง ืืงืฉืืช ืขื ืืืื ื ืืืชืืืืงื, ืืื ืื ืืคืฉืจ ืืงืื ืืื ืืืืื.
ืื ืืืื ื
ืืืืืื ืืืฉืคืช ืืช ืืืชื ืฆื ืฉื AI ืฉืื ืื ื ืืืืืื ืืืกืชืืจ: ืืงืื ืืงืกื ืืื ืืืืจ ืืืฉืื. AI ืื ืืืื ืื ืืฉืื ืืื ืื ืืฉืื ืืืขืจืืช, ืืื ืืกื ืืื ืืืืจ. ืืืืืจื ืฉืื ื: ืืื ืืืฉืชืืฉ ืื ืืื ืืืืืช ืืืืื ืืืชืจ, ืืื ืืืจื ืคืจืื ืฉืืกืชืื ืขื ืืงืื ืืืืืข ืืืืื ืืืชื ื ืืฉืืืืช ืขืืืื ืืืืืช ืื ืคืฉืืืืช ืืืชืจ ืืื ืืืคืื ืืืชื ื ืืืคืชืืื ืืืชืจ ืืืืื ืื; ืื ืืื ืืืืืช ืืืืื ืคืืืช, ืืืชืื ืืืงืืื ื ืงืื ืฉืื ืืื ืืื ืื ืื ื ื ืืื ืืงืจืื ืื ืืชืืืง ืืืืจื ืืื.1 417
<textarea ref={ref} value={value}></textarea>
)
}
ืขืืฉืื ืืคืื ืืจืื ืืืชืจ ืืื. ืืื ืฉื ืื ืืฉืืืืฉ ื useEffect ืืืงืื ื useLayoutEffect, ืืื ืฉื ืื ืฉืืคืฉืจ ืืื ืืช ืืช ืืืชื ืื ืื ืื ืขื CSS, ืืื ืื ืืื ืืฆืืข ืชืืงืื ืืงืืงื ืืช ืื ืืฉืืื. ืื ืืงืื ืืืชืืงื ืฉ Gemini ืืฆืืข:
import React, { useState, useRef, useLayoutEffect, useCallback } from 'react';
// Simple debounce function (or use one from lodash/underscore)
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
const ResizingTextArea = ({ value, onChange, style, ...props }) => {
const ref = useRef(null);
// Memoize the resize function using useCallback
const resize = useCallback(() => {
if (ref.current) {
// Reset height - necessary to shrink correctly
ref.current.style.height = 'inherit';
// Set height based on scrollHeight
ref.current.style.height = \${ref.current.scrollHeight}px\;
}
}, []); // No dependencies needed if it only accesses ref.current
// Debounce the resize function
// Adjust the delay (e.g., 150ms) as needed
const debouncedResize = useCallback(debounce(resize, 150), [resize]);
// Resize on value change (debounced)
useLayoutEffect(() => {
// Call debounced resize. It might run immediately the first time
// or after a delay on subsequent changes.
debouncedResize();
// We only want this effect to run when \value\ changes or debouncedResize changes.
}, [value, debouncedResize]);
// Resize on window resize (debounced)
useLayoutEffect(() => {
// Initial resize on mount
resize();
window.addEventListener('resize', debouncedResize);
// Cleanup listener on unmount
return () => {
window.removeEventListener('resize', debouncedResize);
// Optional: Cancel any pending debounced calls on unmount
// If using lodash debounce, it often has a .cancel() method.
// For the simple debounce above, clearing the timeout isn't
// easily exposed without modifying the debounce function itself.
// However, the check \if (ref.current)\ inside resize handles this.
};
}, [resize, debouncedResize]); // Rerun if resize functions change (shouldn't often)
// --- Enhancements for usability ---
// Allow parent to control the textarea fully
const handleChange = (event) => {
// Trigger the resize immediately on change for responsiveness *before* state update
// Note: This might cause a slight flicker if the debounced one runs later.
// Alternatively, rely solely on the debounced effect driven by \value\ prop change.
// For simplicity and relying on the debounced effect: comment the next line out.
// resize(); // Optional: Immediate resize attempt
if (onChange) {
onChange(event);
}
};
return (
<textarea
ref={ref}
value={value}
onChange={handleChange}
style={{
overflow: 'hidden', // Hide scrollbar that might briefly appear
resize: 'none', // Prevent manual resize corner if not desired
...style, // Allow passing custom styles
}}
rows={1} // Start with minimum rows (optional but common)
{...props} // Pass down other props like placeholder, name, etc.
/>
);
};
export default ResizingTextArea;1 417
ืืืื ื ืฉืื ืข ืืช ื'ืืื ื ืืฉืื ืื ืืืขืื ืืงืื
ื'ืืื ื 2.5 ืคืจื ืืื ืืืืื ืืื ืืงืฆืืขื ืืืื (ืืื ืืืื ืืืฉืชื ืืช ืืืจ) ืืืืจืืช, ืืืืื ืขื ืื ืืืืืืืช ืฉืื, ืืื ืื ืืื ื ืืื ื ืืื ืขืืื ืืคืกืคืก ืืืจืื ืืฉืืืื. ืื ืืกืื ืืืื ืื ื ืืืงื ืงืืข ืงืื ืฉืืฆืืชื ืืชืืื ืืืืืจืื ืืื ืกื ืืฉืื ืข ืืช ื'ืืื ื ืืฉืื ืื ืืืขืืืช ืืืฆืืขืื ืืืืฆืืข ืชืืงืื ืืืืฅ ืืงืืคืกื.
ืืืืง 1 - Code Review
ืืงืื ืฉืืขื ืืื ืืืชื ืืื ืืงืืืคืื ื ืื CommentTextarea ืฉืืืืืจืช ืืงืืืฅ:
https://github.com/antiwork/gumroad/blob/main/app/javascript/components/Post/PostCommentsSection.tsx
ืืฉ ืฉื ืฉืืืืฉ ืื ืืืืืื ื useEffect ืฉืคืืืข ืืืืฆืืขืื ืืืฉื ื ืืช ืืืคืืื ืืืืื ืื ืคืขื ืฉืืชืืื ืืฉืชื ื ืืคื ืืืื ืืืื ืืชืืื. ืืืจื ืืื ืขืืืื ื ืืืื ืืืื ืฆืจืืืื ืืืืืช ื useLayoutEffect, ืืืืชืจ ืืื ืืฉืืืืืจ ื textarea ืืฉ ืืืคืืื CSS ืืฉื
field-sizing ืฉืืืจื ื textarea ืืืืื ืืืืืืืืช ืืคื ืืืื ืืชืืื. ืืืืชื ืจืืฆื ืฉ AI ืืืื ืืช ืืืขืื ืืืฆืืข ืืช ืืชืืงืื ืื ืืื ืืขืืจืช CSS, ืืื ืืฉืื ืืืชื ืืงืจืื ืขื ืืงืฉืจ ืืื useEffect ืืืืฆืืขืื ืืืื ืื ืืืื ืืืฉืชืืฉ ืืืื ื ืื ืืื ืฉืืืื ืืคืขื ืืืื.
ืื ืืกืืื ืืจืืฉืื ืฉืื ืืื ืืืืืืง ืืช ืื ืืงืื ืื'ืืื ื ืืืืงืฉ Code Review. ืื ืืื ืืคืจืืืคื:
const CommentTextarea = ({
children,
showAvatar = true,
...props
}: React.ComponentProps<"textarea"> & { showAvatar?: boolean }) => {
const appDomain = useAppDomain();
const { purchase_id } = useCommentsMetadata();
const loggedInUser = useLoggedInUser();
const ref = React.useRef<HTMLTextAreaElement | null>(null);
React.useEffect(() => {
if (!ref.current) return;
ref.current.style.height = "inherit";
ref.current.style.height = \${ref.current.scrollHeight}px\;
}, [props.value]);
return (
<div className={cx({ comment: showAvatar })} style={showAvatar ? {} : { display: "grid", gap: "var(--spacer-3)" }}>
{showAvatar ? (
<img className="user-avatar" alt="Current user avatar" src={loggedInUser?.avatarUrl ?? defaultUserAvatar} />
) : null}
{loggedInUser || purchase_id ? (
<textarea ref={ref} rows={1} placeholder="Write a comment" {...props} />
) : (
<div>
<a href={Routes.login_url({ host: appDomain })}>Log in</a> or{" "}
<a href={Routes.signup_url({ host: appDomain })}>Register</a> to join the conversation
</div>
)}
{loggedInUser != null || purchase_id != null ? (
<div style={{ display: "grid", justifyContent: "end", gap: "var(--spacer-3)", gridAutoFlow: "column" }}>
{children}
</div>
) : null}
</div>
);
};
ืืคืืืืง ืืื ืืจืื ืืืชืืฉื ืืืกืืืจ ืื ืืืื ืืืจืื ืืืื ืืงืื. ืืชืื ืืืงืกื ืืืื ืกืืคื ืืื ืืชืืืก ื useEffect ืืืืคื ืืื:
Auto-Resizing useEffect:
Efficiency: The effect runs on every change to props.value (i.e., every keystroke). While often fine, for very complex components or extremely rapid typing, this could potentially lead to slight performance hiccups (though usually negligible). Debouncing is an option if performance becomes an issue, but adds complexity.
Initial Render: Ensure the initial height calculation works as expected when the component mounts and props.value might be empty or undefined. The rows={1} attribute helps set a minimum size initially.
CSS box-sizing: The accuracy of scrollHeight can be affected by CSS properties like padding and box-sizing. Ensure your CSS accounts for this (box-sizing: border-box is recommended).
ืืืฆืขื ืฉืื, ืืืจืืช ืฉื ืจืืืช ืืืืื ืืช, ืืื ืื ืืคืืชืจืื ืื ืืื ืืื ืืื ืคื ืืื ื ืืืืืงืช ืฉื ืืืขืื.
ืืืืง 2 - ืงืืืคืื ื ืื ืงืื ื ืืคืืงืืก ืขื ืืืฆืืขืื
ืืชืืชื ืืืจืกื ืืืงืื ืช ืฉื ืืงืืืคืื ื ืื ืืคืืืืืจืืื ื ืื ืืกืืชื ืฉืื, ืืคืขื ืขื ืคืืงืืก ืขื ืืืฆืืขืื:
code review the following component with focus on performance:
const ResizingTextArea = ({
value,
}) => {
const ref = useRef(null);
React.useEffect(() => {
if (!ref.current) return;
ref.current.style.height = "inherit";
ref.current.style.height = \${ref.current.scrollHeight}px\;
}, [value]);
return (
Available now! Telegram Research 2025 โ the year's key insights 
