It is not the case that a contract would make it their code and not yours.
The other answers suggest that a contract would make the code belong to them and not you. This is not the case. Contracts cannot break the law, and to my knowledge that's the case in US law, EU law, Russian Federation law, and Australian law. If a contract states that you will be compensated for running a gambling service, and gambling is illegal, you are not protected by that contract.
EU - Unfair Contract Terms
National Labour Law Profile: Russian Federation
Copyright law is no different. A contract cannot circumvent the copyright laws of your nation. Your employer does not somehow overrule the law, though they like to believe their contracts can. Over and over, this has come up in multiple countries. Contracts such as "Do Not Compete" or "We Own Your Creations" have been fought in court, and have been struck down by judges very quickly.
There is an exception: If the origin of that code is under your company, then in most jurisdictions, that code would belong to your company, unless it's licensed in a manner where you can take it elsewhere. However, this is not your situation.
See: Article 22 of the Labour Law of the Russian Federation, Part IV of the Civil Code of the Russian Federation, 17 USC 101 for US Law, and Part 15 of Directive 2009/24/EC (European Union Computer Programs Directive.)
You created this work out of the scope of your employment, in your own time, on your own computer, out of the scope of the work you were employed to do. This is yours.
Copyright law is almost universal on one thing: If you created a thing, and you have proof that you owned it prior to its existence in the public domain, that thing is yours. You can provide proof simply by timestamps of Git repos, e-mail transfer, hosting, and sometimes even file timestamps (although this is weaker, as one can modify these timestamps if they wanted to.)
This does have its limits, though. As far as I know, US law, EU law, and Russian Federation law states that it will observe contracts such as software licenses. This can protect you, if you put your code in the public domain under a specific license and license it to your company.
In effect, I would do this if I were you:
- Keep a chain of custody on the code.
- Maintain timestamps and proof of ownership of your code.
- Do not simply copy and paste your code. Pull it from an online source if it makes sense (such as a package), or ensure the chain of custody was put into the source control of your company, so there's a trail. An author note, a license, something.
- Include a license on your code that outlines the agreement of its usage.
This would ensure you're covered.