It's already being done
Science is better when you build a big tent and make friends. It is sadder when you engage in foolish gatekeeping.
Be like Anonymous 4chan poster, Robin Houston, Jay Pantone, and Vince Vatter, the authors of this paper who discovered an elegant, previously unpublished mathematical proof on a 4chan anime board, cleaned it up, and made "Anonymous 4chan Poster" the first author on their paper (story here).
Help folks feel the warm fuzzies this Tweeter got when he found out this table on Github was cited 10 times. One of those citations being from this arXiv paper which has been cited ~22,000 times.
This Academia.SE answer thinks SO citations are a good idea.
Gatekeeping is BS
The current top answer to this question says
Anyone can write anything, and the only guarantee you have as to the quality of the writing is the reputation of the author and the number of up-votes the answer received.
The folks who wrote this did so before the replication crisis called entire literatures into question and before arXiv (where anyone can write anything) became the de facto journal for machine learning (60% of ML papers are on it).
They wrote this before Brian Wansink's entire scientific output was called into question, before Matthew Walker's widely lauded book "Why We Sleep" was found to contain fraudulent data, before Retraction Watch taught us that journals show only minimal interest in keeping the scientific record correct, at a time when Beall's List was just beginning to show us all the ways you could pay to get your "research" "published" in a "journal".
Sanctimoniously rejecting Stack Overflow as a source of knowledge ignores many real problems in science. It also implicitly encourages folks to use knowledge without crediting the people that create it. That kind of unethical behaviour fits right in with the other problems I've listed above.
Don't gatekeep. Find ways to credit people for their good work.
Stack Overflow is an undervalued resource
If you find code on Stack Overflow or information that solves what would have been a significant problem for you or otherwise greatly accelerates your research, you should find a way to credit that.
Let me make an analogy here. NumPy is the bedrock of mathematical programming in Python. Development began in 2006. NumPy received funding for the first time ever in 2017. In fact, in 2011, Fernando Perez, founder of IPython/Jupyter, gave a keynote at EuroSciPy explaining that the entire scientific Python stack was essentially relying upon on the "free time" work of only about 30 people---and no one had funding!
Software and code is enormously undervalued by academics and funding agencies. Stack Overflow is enormously undervalued in a similar way.
Personally, I donate to software funds and Patreons and have begun trying to cite every software package I use to make a paper happen. This typically adds ~20 citations. Anything that might help volunteers to keep doing what they do, to place more value on their labour.
If you see a good SO answer try to credit it; make the world a better place.