According to the MIT handbook in relation to writing code you should use the following when citing code.
- Generally, the URL and the date of retrieval are sufficient. Add more details if it will help the reader get a clearer understanding of the source.
- If you adapted the code, you should indicate “Adapted from:” or “Based on” so it is understood that you modified the code.
The page link above also includes the following in relation to open-source material
When you use code from an open source project, you need both to attribute the source and follow the terms of any open source license that applies to the code you are using.
Finally, as always with citing, you should check with your Department to see if they have guidance or a citation style-sheet.