First of all, in many cases, writing new code is lot easier than trying to modify/salvage old code from someone else. Unless you can just plug it in for a modular function in that case your code is not useless.
And if they think your code is valuable enough to save that many people after they improve it, they can approach you for dual license or other agreements. They pay people with patent all the time, so they can do the same for people who’s volunteering their time for open source.