Linking to your code online

When writing a science research paper, usually there will be some code that was used to do the science being discussed. It is becoming customary to share this code so that others can see what you did and perhaps expand upon it or check the work. Since this code might be long and involve many parts, it is generally the case that it doesn't appear in the paper itself, but is referenced using an online link.

Let's take a look at how to do that.

Example 1: Google Colab

If you've written some plotting routines with Google Colab (and I hope you do), you can make them into a sharable notebook very easily. Just the share button, then set the sharing access Anyone with the link. The default is restricted, but that's won't work unless you have specifically invited someone to view it. This is very much the preferred way to share things for this course.

colab-share-link

Click the share button and then make sure it is set to Anyone with the link.

Example 2: Github

Github is a place where anyone can share code. It's deeper and original function is to be a Version Control system, which let's people and groups keep track of changes made to code (like a history). But, we can use it for simpler things, like just sharing a csv file.

gh-make-repo

Make a repository.

You can make a free account here: Github account (and there are plenty of student perks if you want them as well: Education pack

Once you make an account, you can start by creating a repository.

gh-make-repo

The initial commit.

After you have a repo set up, it should show up like this. There's nothing in it, except the README.md file which can be edited to explain what the repo is about.

There are many ways to start changing things in your repo. The easiest and most middle-of-road in terms of complexity and features is to use the GitHub desktop application.

gh-open-with-desktop

Select the Open with Desktop option.

Once you open it with GH desktop, you'll have to put a local version somewhere on your computer. (This is what you edit, then push to the online version once you are happy with your edits.)

gh-desktop-clone

Pick a good local path for your local version of the repo.

Now, you can make a change to a file in your repo. You'll need a code editor (i.e. NOT ms word). This page has some recommendations. Here, we've added a line to the README.md file.

gh-vs-make-a-change

Editing the README.md file

Now, go back to Github Desktop. You should see that it has automatically detected the change you made.

gh-desktop-change

We've got a change!

  1. Press the Commit to main button. This commits the change to the repo (kinda like saving to the perpetual history of the repository.
  2. Press the Push Origin button on top. This sends the changes to the online version of your repo.
gh-push-to-origin

Send it through the pipes.

Now, when you return to your repo on the github page, you should see the modifications to the README.md file.

gh-push-to-origin

Now the README has changed.

This is just the beginning. You can do all sorts of things now. In this repo, we've added a folder called in-class-measurements. In there, we've put a csv file that contains the data we recorded during class. By following the same process of commitpush to origin, now that data set is hosted in our repo online, and anyone can access it.

gh-csv-hosted

Send it through the pipes.

If you press the Raw button, it will take you the file itself via a URL:
https://raw.githubusercontent.com/hedbergj/PHYS-37100-data/main/in-class-measurements/change-resistance-with-decade-box-9-12-2022.csv

Now, you can use that URL to load the data into a Colab Notebook or other analysis application.

Here is the link to the repository we just made.
https://github.com/hedbergj/PHYS-37100-data This is a great way to host your work online.


Other notes