Is it legal to reproduce open source code in a book
Say I want to write a book which contains code examples from open source repos (with MIT licenses). I want to sell this book commercially for my own profit (ha!). Are there any legal obstacles I should consider?
MIT license doesn't restrict commercial usage or distribution. Add proper attribution, but you can "link" that to another page, e.g. "Author XZ, MIT license, see page 251" https://choosealicense.com/licenses/mit/