Some forms of cheating are pretty straightforward (for example, glancing at another student's paper during an exam or quiz and using part or all of their answer on your own exam). Other forms of cheating, plagiarism, and academic dishonesty are less obvious, especially in the world of information technology.
Plagiarism is the act of taking someone else's work and presenting it as your own. This applies to all kinds of work, including writing, programming, coding, etc.
All coursework is expected to be the work of the student(s) whose name(s) appear(s) on the assignment/project/quiz/exam (henceforth I will simply write "assignment"). On an individual assignment, turning in code written by another student is plagiarism. On a group assignment, turning in code written by someone outside of the group is plagiarism. On any assignment, turning in code that you copied and/or downloaded from anywhere but your own brain is plagiarism. This applies to single lines of code, blocks of code, pages of code, documents, and entire projects.
Code-sharing is common in the information technology industry. However, in academia, we artifically limit collaboration. These limits are designed to force you to learn fundamental principles and build specific skills. Your academic work must be your own work. All the code that you claim credit for (implicitly or explicitly) must be written by you. All the writing in your documentation, comments, and reports must be your own work.
If you do use sources to help you with your assignments, you must reference/cite them, just like in any other academic discipline. If you use a source to "help you along" but do not cite that source, that is plagiarism. You must be able to explain every line in any program that you turn in. Verbatim copying and/or slight modifications to copied code without citation is cheating (whether copied from a classmate, a former student, a friend, an anonymous online source, etc.). Even with cited sources, you may not technically be committing plagiarism, but if a significant portion of your assignment is copied (whether cited or not) you are not meeting learning objectives and your grade will reflect that.
If you are still unsure if an action you are pursuing or are considering pursuing is acceptable, please ask me. I understand that the lines are blurry sometimes and you may not intend to cheat. However, ignorance will be a feeble and ultimately ineffective defense.