In short: respect the copyright claims on any code you're using. Some might require you to publish your code, some won't, so verify which code you're using and read up on the various licencing types.
Usually you can publish your code any way you like: as a download on a website, on a public repository like github, etc.