John Paul Mueller

Algorithms For Dummies


Скачать книгу

a significant number of options for saving your notebook. However, none of these options works with your local drive. After you upload content from your local drive to Google Drive or GitHub, Colab manages the content in the cloud and not on your local drive. To save updates to your local drive, you must download the file to your local drive. The following sections review the cloud-based options for saving notebooks.

      Using Drive to save notebooks

      The default location for storing your data is Google Drive. When you choose File ⇒ Save, the content you create goes to the root directory of your Google Drive. If you want to save the content to a different folder, you need to select that folder in Google Drive (https://drive.google.com/).

      

Colab tracks the versions of your project as you perform saves. However, as these revisions age, Colab removes them. To save a version that won’t age, you use the File ⇒ Save and Pin Revision command. To see the revisions for your project, choose File ⇒ Revision History.

      You can also save a copy of your project by choosing File ⇒ Save a Copy In Drive. The copy receives the word Copy as part of its name. Of course, you can rename it later. Colab stores the copy in the current Google Drive folder.

      Using GitHub to save notebooks

      GitHub provides an alternative to Google Drive for saving content. It offers an organized method of sharing code for the purpose of discussion, review, and distribution. You can find GitHub at https://github.com/. The source code for this book appears at https://github.com/lmassaron/algo4d_2ed, so you can access it easily from Colab.

You may use only public repositories when working with GitHub from Colab, even though GitHub also supports private repositories. To save a file to GitHub, choose File ⇒ Save a Copy in GitHub. If you aren’t already signed into GitHub, Colab displays a window that requests your sign-in information. After you sign in, you see a dialog box similar to the one shown in Figure 3-8.

Snapshot shows Using GitHub means storing your data in a repository.

      FIGURE 3-8: Using GitHub means storing your data in a repository.

      Using GitHub gists to save notebooks

      You use GitHub gists as a means of sharing single files or other resources with other people. Some people use them for full projects as well, but the idea is that you have a concept that you want to share — something that isn’t quite fully formed and doesn’t represent a usable application. You can read more about gists at https://help.github.com/articles/about-gists/.

      Most tasks in Colab and Notebook work the same. Each has both code cells and noncode cells, and you can create code cells in both Colab and Notebook by using the options on the Insert menu. Likewise, both environments have noncode cells that come in three forms:

       Text

       Section header

       Form field, which comes in these types:DropdownInputSliderMarkdown

      Noncode cells in Colab work somewhat differently from the Markdown cells found in Notebook, but the idea is the same. Two interesting additions in Colab that aren’t found in Notepad are the scratch code cell, which allows you to experiment with code in real time, and code snippets, which are canned code for performing specific tasks (you just insert them where needed).

      You can also edit and move cells. One important difference between the two environments is that you can’t change a cell type in Colab, but you can in Notebook. A cell that you create as a section header can’t suddenly transform into a code cell. The following sections offer a brief overview of the various features.

      Creating code cells

Snapshot shows Colab code cells contain a few extras not found in Notebook.

      FIGURE 3-9: Colab code cells contain a few extras not found in Notebook.

      You use the icons shown in Figure 3-9 to augment your Colab code experience. Here’s what these features do (in order of appearance, left to right, in the figure):

       Move cell up: Moves the cell up one position in the cell hierarchy.

       Move cell down: Moves the cell down one position in the cell hierarchy.

       Link to cell: Displays a dialog box containing a link you can use to access a specific cell within the notebook. You can embed this link anywhere on a web page or within a notebook to allow someone to access that specific cell. The person still sees the entire notebook but doesn’t have to search for the cell you want to discuss.

       (Optional) Add a comment (assuming that you have the right to make a comment): Creates a comment balloon to the right of the cell. This is not the same as a code comment, which exists inline with the code but affects the entire cell. You can edit, delete, or resolve comments. A resolved comment is one that receives attention and is no longer applicable.

       Open editor settings: Opens the same dialog box shown in Figure 3-2 and discussed in the “Getting familiar with Google Colab features” section, earlier in this chapter. You need to select some code before this option appears.

       Mirror cell in tab: Mirrors the currently selected cell in a Cell pane that appears on the right side of the window. You can scroll wherever you want within the code in the left pane and keep this code accessible. The right-pointing arrow lets you execute the cell at any time after making changes in left-pane code. A pair of double-pointing arrows lets you move the focus back to the selected code in the left pane with a single click. You can also move the cell code to a scratch cell, where you can play with it without modifying your original code. You can have more than one Cell pane. You simply select the one you want and move between them as needed, which lets you move easily from place to place in your code. Close a Cell pane by clicking the X next to the word Cell.

       Delete Cell: Removes the cell from the notebook.

       Vertical ellipses: Contains a number of additional features in a menu (not all of which may appear because they depend on the file you have opened, the tasks you have performed, and your rights to work with the file content):Copy Cell: Copies the content of the currently selected cell to the clipboard.Cut Cell: Deletes the content of the currently selected cell and places it on the Clipboard.Clear