Live data from Hacker News

Show HN: HN Avatars in 357 bytes

news.ycombinator.com

61–70 of 536 posts

Re: Show HN: HN Avatars in 357 bytes

#61
post #43

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…

[deleted]

Re: Show HN: HN Avatars in 357 bytes

#62

Ive 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…

[deleted]

Re: Show HN: HN Avatars in 357 bytes

#66

Hah! 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.

No post body was provided.

Re: Show HN: HN Avatars in 357 bytes

#67
post #43

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…

Does the canvas need to be created and removed as it comes in and out of view? Using requestAnimationFrame() might also further improve responsiveness.

Re: Show HN: HN Avatars in 357 bytes

#68
post #67
post #43

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…

Does the canvas need to be created and removed as it comes in and out of view? Using requestAnimationFrame() might also further improve responsiveness.

Does the canvas need to be created and removed as it comes in and out of view?

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

#69
post #6

Wow 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...

I don't know about you, but I really don't want an extension for every small change one might want to apply to one specific site.

Re: Show HN: HN Avatars in 357 bytes

#70
post #43

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…

Speaking performance/optimisations, interesting choice to destroy canvas when it leaves viewport and recreate it upon each re-entry.

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?)
Post reply on HN