Assignment Setup

An overview of how to set up 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-win2223-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'll usually have two windows open--one to edit your code, and another to run it. Let's download and set up the first, a code editor called VSCode!

  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.
    1. Search for “sftp”, and install the second result, not the first result! It should be by Natizyskunk, and have around 49,000 downloads and 5 stars.
    2. Lastly, search for “GitLens”, and hit install on the first one (GitLens — Git supercharged, by Eric Amodio, over 10 million downloads).

That's it for VSCode for now! 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. First, open your command line app, or hit Ctrl + ` to use VSCode's command line. If that doesn't work for you, 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. Type the following into your terminal to connect to the myth machines (ssh is a command standing for Secure SHell). Type yes if prompted about continuing to connect (a message along the lines of "The authenticity of host 'myth.stanford.edu (171.64.15.19)' can't be established"), and enter your password when prompted:
    ssh yourSUIDHere@myth.stanford.edu
  3. You're in! You should see a welcome message. 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 see what folders there are, run "ls -la". You’ll see a list of all the folders in your home directory.
  4. 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!

Start Learning: 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).

First, 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. First, open your command line app and enter the following, just as you did in the previous section:
    ssh yourSUIDHere@myth.stanford.edu
  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: NOTE: Yes, the link says cs106L-assignment2 even for assignment 1. This quarter we renumbered the assignments but didn't move where the code lives.
    git clone https://github.com/snme/cs106L-assignment2.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. Now we're going to rename our folder to deal with the renumbering quirk.
     mv cs106L-assignment2 cs106L-assignment1 
  6. Next, navigate into this directory, named cs106L-assignment1. Which command would you use to change directories into the folder? (Spoiler: cd cs106L-assignment1)
  7. 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!
  8. 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? There are ways to edit files through your shell, but we'll spare you of learning that now (if you'd like to, send us an email).

If the below steps havent been working for you (or if you want to learn a different way to edit files stored in the myth machines), jump to here! If you have not yet set up your VSCode, please jump to that link.

Let's get you editing code with VSCode! By the end, you'll be able to edit code files locally, with your changes automatically syncing to the myth machines whenever you hit save!

  1. First, we need to create a folder that we'll download our code files from the myth machines into. Create a folder wherever you want on your computer (with Finder or Windows Explorer). Next, open VSCode, click File>Open... and select your folder.

  2. Now, we'll set up our automatic file syncing to sync our changes from your computer to the myth machines. Click View>Command Palette..., type "SFTP: Config", and hit enter.

  3. 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"
        ]
     }
  4. Hit save on VSCode! Make sure these changes are saved.
  5. In the top left, hit the icon that looks like two pages (the file explorer). Now, in the large empty space below the file you just edited, right click, and click "Download Folder". If that doesn't work, try to click "Sync Remote - Local"
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, and type "./build_and_run.sh" to test your code!

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!

Good luck! :)

Alternate VS Code Setup

This verison gets you set up with VS Code SSH instead of VS Code SFTP. In the version above, you were setting up a protocol which allowed you to download files from myth, edit them locally, and then reupload your local files to myth every time you saved. Basically, you are working on a local copy of your assignment files and constantly uploading that copy to myth as you work. With this method, you will have no local copy of your work, you will simply use VS Code to ssh into myth, and then the VS Code editor will be like a window into the myth machines, and all edits you make in the editor will be on the actual files in myth, not on local files!

  1. In VS Code, go to the marketplace (click the tetris icon on the left) and search for "ssh". Install the first result (Remote - ssh from Microsoft).
  2. Now, press command + shift + P on a Mac or Ctrl + shift + P on a PC, and start typing “ssh”
  3. The dropdown menu should have the option “Remote-SSH: Add a New SSH Host”. Click that.
  4. Enter “ssh <yourSUnetid>@myth.stanford.edu”, press enter
  5. Select the default configuration file (just pressing enter again should work, otherwise hit the first option in the dropdown menu)
  6. Now, you VS Code will remember that you like to ssh into the myth machines, so in the future, you will only have to do steps 7-11 to code!
  7. Press command + shift + P on a Mac or Ctrl + shift + P on a PC, and start typing “ssh”
  8. 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!
  9. This time, select “Remote-SSH: Connect to SSH Host”.
  10. Select myth.stanford.edu
  11. You will be prompted for your password, enter your Sunet password!
  12. Remember, you are ssh’d into myth from VS Code! If you drag up from the bottom, you should see a terminal. This terminal is exactly the same as your computer’s terminal when you are ssh’d into myth there. To open your code, cd into the path you saved while dowloading the code and type code . into the terminal. It should open up a new window with all the files in the direcotry you chose! Voila!

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. 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 copied in the step before VS Code setup, this will be MYTH_PATH.
  2. In a terminal window on your computer (not one ssh'd into myth), enter
    scp -r <yoursunetid>@myth.stanford.edu:MYTH_PATH LOCAL_PATH
  3. Go check LOCAL_PATH to see if it worked! Submit on Paperless per usual :)
  4. 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