It's always nice to provide good pieces of code to the community, but maybe the best way is to push it on GitHub (or equivalent) and provide the link of your GitHub project at the end of your paper. Among other advantages, your code could evolve after the date of publication of your article, and readers could benefit from the latest version.