The simple answer is:
don't. The code behind Google search isn't public, the code behind Stripe isn't public, Netflix doesn't release source for how their DRM works, and so on. Absolutely give back to the community, but you don't have to put yourself in the poorhouse in the process.