This is fun. One suggestion.. rather than creating a canvas for each user using a querySelectorAll and a loop, I'd use an IntersectionObserver and only create the canvases as they scroll into view. That way the user's device won't need to create hundreds of elements when the code runs. let observer = new IntersectionObserver( (entries) => { entries.forEach((entry, i) => { if (entry.isIntersecting) { const p = 2; cons…
Show HN: HN Avatars in 357 bytes
61–70 of 536 posts
Re: Show HN: HN Avatars in 357 bytes
#62Ive been a dev for over 2 decades but I still cant grok bitwise operators - anyone have a reference that may help with that?
I struggled with this as well. Now I'm a bit rusty as I haven't used it for a while, but what really helped me was to start thinking about binary numbers more as strings. It also really helps me to visualize binary operations in binary space, not hex or decimal. That's still very confusing to me. For example left shift by 1 on this 8 bit number (decimal is 32) 00100000 you just shift all the numbers to the left 01000…
Re: Show HN: HN Avatars in 357 bytes
#63Edit: hmmm, kinda looks like a Tori gate.
Re: Show HN: HN Avatars in 357 bytes
#64Re: Show HN: HN Avatars in 357 bytes
#65Re: Show HN: HN Avatars in 357 bytes
#66Hah! I got a really cool little icon that looks almost like the cassette tape pirate logo of Piratbyrån back in the day. I have old t-shirts with that logo. MAKE. THIS. PERMANENT! On the functional side, this really helps you see who is who in a long threaded discussion. Your eye is much quicker at following the little color icons than their names.
Re: Show HN: HN Avatars in 357 bytes
#67This is fun. One suggestion.. rather than creating a canvas for each user using a querySelectorAll and a loop, I'd use an IntersectionObserver and only create the canvases as they scroll into view. That way the user's device won't need to create hundreds of elements when the code runs. let observer = new IntersectionObserver( (entries) => { entries.forEach((entry, i) => { if (entry.isIntersecting) { const p = 2; cons…
Re: Show HN: HN Avatars in 357 bytes
#68This is fun. One suggestion.. rather than creating a canvas for each user using a querySelectorAll and a loop, I'd use an IntersectionObserver and only create the canvases as they scroll into view. That way the user's device won't need to create hundreds of elements when the code runs. let observer = new IntersectionObserver( (entries) => { entries.forEach((entry, i) => { if (entry.isIntersecting) { const p = 2; cons…
Does the canvas need to be created and removed as it comes in and out of view? Using requestAnimationFrame() might also further improve responsiveness.
Not really. You could just create them and not bother removing them. You'd need to check if the user already had an avatar if you did that though, or you'd end up with lots of repeated avatars when you scroll up and down the page.
Re: Show HN: HN Avatars in 357 bytes
#69Wow this is really great! Noob question, but let's say I wanted to permanently load this JS in my browser? How would I achieve that? Grease monkey? Extension? Thanks :)
Why not create your own web extension? It will take just a few lines of code, you can look at this example for reference[0] (also on Github[1]). [0]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Web... [1]: https://github.com/mdn/webextensions-examples/tree/master/bo...
Re: Show HN: HN Avatars in 357 bytes
#70This is fun. One suggestion.. rather than creating a canvas for each user using a querySelectorAll and a loop, I'd use an IntersectionObserver and only create the canvases as they scroll into view. That way the user's device won't need to create hundreds of elements when the code runs. let observer = new IntersectionObserver( (entries) => { entries.forEach((entry, i) => { if (entry.isIntersecting) { const p = 2; cons…
Personally I'd leave it created and stop observing the element instead, à la
/* … */ if (entry.isIntersecting) { observer.unobserve(entry.target); /* … */ }
Do you think (or know) that swapping observed node for canvas (potentially producing many canvases) is more expensive than keeping all observers and having smallest possible amount of canvases? (Maybe I'm biased towards saving CPU but saving RAM is better after all?)