Assignment Setup

An overview of how to set up a remote code development environment, useful even after 106L!

When developing C++, developers rarely start by copying a pasting a blank Qt Creator project. Although Qt is an excellent integrated development environment (IDE) for learning C++, it's important for you to learn how to build and run your C++ files yourself. To give you the experience of working on C++ projects from scratch, outside of environments like Qt Creator, we’ll be running our code remotely on the myth machines, a set of computers in the Gates building's basement. Don’t fear! You’ll be able to use a code editor on your laptop just like Qt Creator called VSCode while editing files on a completely different myth machine computer.

The technologies that you'll be exposed to in this class (CLIs, remote development, compiling code yourself) will help you far beyond 106L, and even beyond C++!

If that sounds like a lot, don't worry! We'll take you through it step by step. If you follow the instructions shown below, you will rarely (if ever) have issues with your setup. There are two parts to this page: instructions that you need to only run once to first set up for the class, and instructions to follow each time you're starting an assignment.

If you ever have any trouble at all with any part of this page, please feel free to email us at cs106l-aut2122-staff (at) lists (dot) stanford (dot) edu. We'll be happy to help with any issue you find!

Getting Started: Initial Setup Instructions

This entire section will have instructions you only need to run once. The next section will detail what you need to do for each assignment. This quarter, you will be working primarily in VS Code!

  1. First, Install VSCode and open the app.
  2. Next, go to the extension manager (click the tetris icon on the left of your screen). If you can't find the button, check out this link.
    Search for "ssh". Install the first result (Remote - ssh from Microsoft).
    Lastly, search for “GitLens”, and hit install on the first one (GitLens — Git supercharged, by Eric Amodio, over 10 million downloads).
  3. Now, press command + shift + P on a Mac or Ctrl + shift + P on a PC, and start typing “ssh”
  4. The dropdown menu should have the option “Remote-SSH: Add a New SSH Host”. Click that.
  5. Enter “ssh <yourSUnetid>@myth.stanford.edu”, press enter
  6. Select the default configuration file (just pressing enter again should work, otherwise hit the first option in the dropdown menu)
  7. Now, your VS Code will remember that you like to ssh into the myth machines! You only have to do these steps once. Check out the next section for instrutions for each assignment

Next, we'll show you how to log into the myth machines (to eventually run your code) and create a folder that you'll keep your assignments in.

  1. Press command + shift + P on a Mac or Ctrl + shift + P on a PC, and start typing “ssh”
  2. COMMON ISSUE: Sometimes, when you quit VS Code and reopen, the ssh password prompt gets stuck on a loop and wont let you log in. If this is happening to you, press command + shift + P on Mac or ctrl + shift + P on windows and type "kill". Select the option from the dropdown that says "Remote-SSH: Kill VS Code Server on Host". You will have to enter your password (it shouldnt loop).Now restart from step 7 again!
  3. This time, select “Remote-SSH: Connect to SSH Host”.
  4. Select myth.stanford.edu
  5. You will be prompted for your password, enter your SuNet password! You may have to do dual authentication.
  6. Now, you are ssh’d into myth from VS Code! (ssh is a command standing for Secure SHell). Now, If you drag up from the bottom, you should see a terminal (you can also press ctrl-backtick to open it). This terminal is not the same as the terminal on your local computer. It won't give you access to any of your local files. Instead, it is connected to the myth machines.
  7. You're in! Just like the Documents, Downloads, etc. folders on your computer, there are folders (called directories) on the myth machines. When you log in, you're placed in a home directory. Instead of a mouse and nice-looking windows, though, you can navigate the myth computers using the shell that you've logged into. From now on, when we say "enter/run a command", it means to type the command we give to you in and hit enter. For example,
    Ever wanted to learn shell but not know where to start? This will expose you to learning linux commands and navigating the shell!
    • at any given time, you can see what folder you’re in by typing "pwd" (no quotes) and hitting enter (print working directory)
    • To be sure you're in your home directory, run cd ~
    • To see what folders there are, run "ls -la". You’ll see a list of all the folders in your home directory.
  8. Decide where you want to store your assignments. We recommend creating a folder called "cs106L", and putting all your files in there. To do so, type “mkdir cs106L”, which makes a directory called cs106L.
That's the end of our one-time setup. Take a break, or feel free to look up linux shell tutorials to see what else you can do. If you'd like to see how to start working on each assignment, see below!

Instructions for Each Assignment

Here are instructions to follow when you start work on each of our assignments (you'll need to repeat these for each assignment).

  1. Open VS Code and Press command + shift + P on a Mac or Ctrl + shift + P on a PC, and start typing “ssh”
  2. This time, select “Remote-SSH: Connect to SSH Host”.
  3. Select myth.stanford.edu
  4. You will be prompted for your password, enter your SuNet password! You may have to do dual authentication.

  5. COMMON ISSUE: Sometimes, when you quit VS Code and reopen, the ssh password prompt gets stuck on a loop and wont let you log in. If this is happening to you, press command + shift + P on Mac or ctrl + shift + P on windows and type "kill". Select the option from the dropdown that says "Remote-SSH: Kill VS Code Server on Host". You will have to enter your password (it shouldnt loop).Now restart from step 7 again!

Now, we'll need to download the assignment into the folder we created in the previous section (we called ours "cs106L"). Let's connect to the myth machines first!

  1. Open your terminal in VS Code. Run cd ~ to get to your home directory.
  2. Next, enter "ls -la". You should see the folder for 106L assignments you made in the previous section. To navigate into that directory, type "cd nameOfYourFolderHere". For instance, since we named our folder cs106L, we'd run the following command:
    cd cs106L
  3. Next, we'll download our assignment. We'll use assignment1 as an example, but in the future, you can follow these same instructions, replacing wherever you see assignment1 with assignment2 (for the second assignment, and so on). To do so, type the following command in to download a folder named "assignment1" with starter code:
    git clone https://github.com/snme/cs106L-assignment1.git
  4. We're using git for storing and developing our assignments. You don't need to use git to version control your work, but if you'd like to, send us an email!
  5. Next, navigate into this directory, named cs106L-assignment1. Which command would you use to change directories into the folder? (Spoiler: cd cs106L-assignment1)
  6. Now, run this command to download dependency packages, install them, link, and build your files is to run this simple command. It might take 5-10 minutes, so sit back and watch!
    ./setup.sh
    ahh, the power of abstraction. If you're interested to see what went on behind the scenes in setup.sh, send us an email or open the file by following the steps below!
  7. Lastly, get the full path to the folder that you're in by printing your working (current) directory. (Run pwd.). Save this output!

Leave this window open, but that's it! To recap, we've connected to the myth machines, downloaded our assignment, set up the project, and got the full path to our working directory. Now, you may be wondering--how do I edit files? Let's get you editing code with VSCode! By the end, you'll be able to edit code files stored on the myth machines on VS Code on your machine!

  1. Make sure you are ssh'd in VS Code. You should see a little green box in the lower right bottom bar that says "SSH: myth.stanford.edu". If not, go do steps 1-4 from the previous section.
  2. cd into your assignment directory (remember how you got there when you downloaded it?). You are probably already in it from the previous steps.
  3. run code . this should open a new VS Code window with your assignment folder open. You should be able to access and edit all the files now!

Congratulations! You've just been exposed to several technologies that developers of all code will use throughout their careers, from bash (shell) to git to C++ project files. You're all set!

Turning In Assignments

If you are editing code this way, when its time for you to turn in the assignment, you will need to make a local copy of the files you've been editing in myth. You can do this with a single command line command!

  1. First, you will need to make a local CS106L folder (not one on myth). Open your computer's command line or terminal. For Macs, open the "Terminal" app (click here for help). For Windows, open your start menu, type "command prompt", and open the Command Prompt app.
  2. Run ls to see all the folders and files in your local home directory! You should see Desktop, Documents, etc.
  3. Decide where you would like your local CS106L folder. You might want it on your Desktop. If so, cd Desktop!
  4. Run mkdir CS106L to make a folder called CS106L in your current directory.
  5. Make sure you know the path to your local 106L folder! Its probably something like ~/Desktop/CS106L! We will refer to this as LOCAL_PATH. You also need the path to your assignment folder in myth, which is what you saved in step 6 in "Instructions for Each Assignment", this will be MYTH_PATH.
  6. You will need to do this step for each file in the assignment folder that you have to turn in. The file name will be referred to as FILE_NAME. In a terminal window on your computer (not one ssh'd into myth), enter
    scp <yoursunetid>@myth.stanford.edu:MYTH_PATH/FILE_NAME LOCAL_PATH
  7. Go check LOCAL_PATH to see if it worked! Submit on Paperless per usual :)
  8. You can change the direction of the scp command as well to upload things on your computer to myth! Run scp [-r] [HOST:]SOURCE [HOST:]DESTINATATION (where [] denotes including this is optional, you would want to include sunet@myth.stanford.edu: in the relevant [HOST:]). If you are moving a directory instead of just one file, you will need to use the -r flag after scp

Lastly, to submit, visit paperless.stanford.edu, navigate to the appropriate assignment (assignment 1) under the CS106L class, and submit the suggested files (and ONLY the suggested files, please!).

Alternate VS Code Setup: SFTP

If the above coding environment using SSH in VS Code isn't working for you, you can try setting up with SFTP. If you've already done a step below, feel free to skip it! However, this section is written assuming you're starting fresh from the first time, so don't worry if you haven't read the sections above!

The gist of using SFTP is as follows. You'll download assignment files onto the Myth machines, just like you would've done in the approach above! However, in addition, you'll also create a folder for those assignment files on your local machine (aka the laptop/PC you're on right now). You'll then set up "SFTP", which will copy the files you've downloaded onto Myth to your local computer's folder. From then on, all changes you make to your files on VSCode (which are the files on your own computer) will automatically be synced to the Myth machines!

  1. First, Install VSCode and open the app.
  2. Follow these instructions to log into your home folder on the Myth machines and create a folder to store your assignments. If you've already done this, feel free to skip!

    Let's connect to the myth machines first!

    1. Open terminal, either in VS Code, or your computer's command line app (For Macs, open the "Terminal" app (click here for help). For Windows, open your start menu, type "command prompt", and open the Command Prompt app).
    2. Run ssh yourSUNetID@myth.stanford.edu. This makes it so that your terminal window (either on VS Code or on your computer's app) is connected to the myth machines, and you'll be logged into your home directory.
    3. Now, we'll create a directory for this class (it will contain all of the assignment code we'll need for this quarter). To do so, run this command to MaKe a DIRectory (a folder) called "cs106L":
      mkdir cs106L
    4. Next, enter "ls -la". You should see the folder for 106L assignments you made in the section above. To navigate into that directory, type "cd nameOfYourFolderHere". For instance, since we named our folder cs106L, we'd run the following command:
      cd cs106L
    5. Next, we'll download our assignment. We'll use assignment1 as an example, but in the future, you can follow these same instructions, replacing wherever you see assignment1 with assignment2 (for the second assignment, and so on). To do so, type the following command in to download a folder named "assignment1" with starter code:
      git clone https://github.com/snme/cs106L-assignment1.git
    6. We're using git for storing and developing our assignments. You don't need to use git to version control your work, but if you'd like to, send us an email!
    7. Next, navigate into this directory, named cs106L-assignment1. Which command would you use to change directories into the folder? (Spoiler: cd cs106L-assignment1)
    8. Now, run this command to download dependency packages, install them, link, and build your files is to run this simple command. It might take 5-10 minutes, so sit back and watch!
      ./setup.sh
      ahh, the power of abstraction. If you're interested to see what went on behind the scenes in setup.sh, send us an email or open the file by following the steps below!
    9. Lastly, get the full path to the folder that you're in by printing your working (current) directory. (Run pwd). Save this output!

    Leave this window open, but that's it! To recap, we've connected to the myth machines, downloaded our assignment, set up the project, and got the full path to our working directory. Now, you may be wondering--how do I edit files? Let's get you editing code with VSCode! By the end, you'll be able to edit code files stored on the myth machines on VS Code on your machine!

  3. In the VS Code marketplace (Tetris Icon left hand side), search SFTP and download the first result.
  4. Now, we'll set up our automatic file syncing to sync our changes from your computer to the myth machines. First, create a folder on your computer (like you normally would, e.g. through Finder on a mac or Explorer on windows) that you'll use for this class, except now on your local computer (as opposed to above, where we created a similar folder on the Myth machiens). You can call it whatever you'd like, but we'd recommend "CS106L". Inside of it, also add another folder for the assignment you're working on now, like A1!
  5. Now, switch to VSCode window and hit "File">"Open" and in the upper lefthand corner of VSCode and open the folder you've made above!
  6. Now, press "Command + shift + P" on Mac or "Ctrl + shift + P" type "SFTP: Config", and hit enter.
  7. Delete everything in the file that pops up and paste the text below. Add your username where indicated (in quotes, after "username":), and replace the text in the quotes after "remotePath:" with the output from step 6 above.

    {
        "name": "Myth",
        "host": "myth.stanford.edu",
        "protocol": "sftp",
        "port": 22,
        "username": "YOURUSERNAMEHERE",
        "interactiveAuth" : true,
        "remotePath": "replace this with the path to your assignment1 directory on the myth machine (output from the pwd command, step 6, above)",
        "uploadOnSave": true, 
        "ignore" : [
            "build/",
            "vcpkg/",
            "build_and_run.sh"
        ]
    }
  8. Hit save on VSCode! Make sure these changes are saved.
  9. In the top left, hit the icon that looks like two pages (the file explorer). Now, in the large empty space to the left of the file you just edited, right click, and click "Sync Remote - Local". If that doesn't work, add "Download Folder".
That's it! Now, your workflow will be as follows. You can make changes in VSCode to files and save. Then, switch to your terminal window (or use the terminal in VSCode through pressing Ctrl+backtick) after ssh-ing in and navigating to your cs106L/cs106L-assignment(number) folder, and type "./build_and_run.sh" to test your code!

To submit, visit paperless.stanford.edu, navigate to the appropriate assignment (assignment 1) under the CS106L class, and submit the suggested files (and ONLY the suggested files, please!).