Canvas API

Every week I create several quizzes on Canvas with several questions each and with several multiple-choice answers for each question.

Using the Canvas Web GUI for this purpose has now become very, very tedious, with lots of pointing, clicking, copy, and pasting…

This should have occurred to me months ago, and that is that there is a Canvas RESTful API that I can use programmatically to create those quizzes, with their questions and their answers.

The first thing you need is a Canvas access token.

Login to Canvas, click on Account at the top of the left sidebar, and then click on Settings.

Scroll down to the Approved Integrations section, and click on + New Access Token.

A window will pop up with a form. Fill in Purpose with a name for the access token, leave Expires blank, and click on Generate Token.

Another window will pop up with the token. Copy it immediately and store it in a safe place. Canvas will not show you that token again. If you lose it, you’ll have to repeat this process to get another token.

The second thing you need is the Unix cURL utility.

Now you can make a RESTful API request to Canvas.

Here’s an example of a curl call to simply get a particular quiz from a particular course:

curl -H 'Authorization: Bearer <your access token>'

Where 1202012 happens to be my course id and 1175681 happens to be my quiz id.

You can get your course id and your quiz id by visiting a particular quiz of a particular course using the Canvas Web GUI.

The response to that curl call will be a JSON document with all of the attributes and corresponding values of that quiz.

Slightly more challenging is the curl call to create a quiz.

curl -d @Quiz.json -H 'Content-Type: application/json' -H 'Authorization: Bearer <your access token>'

Again, 1202012 is my course id and the file Quiz.json contains the JSON that configures the quiz the way that I want:

  "quiz": {
    "due_at": "2017-10-17T18:05:00Z",
    "lock_at": "2017-10-17T18:05:00Z",
    "quiz_type": "assignment",
    "time_limit": 4,
    "title": "Quiz #1",
    "unlock_at": "2017-10-17T18:00:00Z"

Of course the Canvas API responds to many, many, more kinds of requests, and therefore is rich with opportunities to automate many other things.

Finally, if you’re familiar with Python, there’s a beautiful library for making API calls: requests.

Google Cloud Platform (GCP)

Dr. Fares Fraij and I attended the second annual Google Cloud Platform (GCP) Faculty Institute from Sun, 30 Jul, to Tue, 1 Aug, of this year.

We also attended the first one last year.

Google (GCP) (started in 2011, 4% market share) is trying its best to compete with Microsoft (Azure) (started in 2011, 10% market share) and Amazon (AWS) (started in 2006, 47% market share).

Around 50 faculty members attended from various institutions across the U.S.

And the institute consisted of various Google talks including a very inspiring one by Vint Cerf who joined Google in 2005 as their Chief Internet Evangelist.

For me, though, the best part of gatherings like these is the opportunity to find out how other faculty are delivering CS courses, including their pedagogy and their tools.

Last year the biggest revelation for me was Docker.

This year it was Kaggle, Google Course Builder, and SIGCSE mailing lists.

Google also gave us tutorials and compute credits to get started with GCP.

And, finally, they gave us compute credits to give to our students.

For my students in CS373: Software Engineering I think GCP offers an equivalent functionality to AWS and I intend to have them try that this fall.

HackerRank for Work

This is a followup to my previous post about HackerRank.

With a regular HackerRank account, when my students submit a solution to a challenge in a contest, I can not see my student’s solution. I only know that HackerRank has confirmed that their solution passed my tests.

In the context of a programming project, I don’t care about that, because I only award half of the credit of the assignment based on the correctness of the solution. Students separately submit their solution through GitHub for many other types of assessment: design, documentation, efficiency, style, etc.

But, I’m also using HackerRank now in the context of exams. In the context of an exam, if I can create the usual type of HackeRank question, one that reads from stdin and writes to stdout, and can create good tests, then again, I don’t really need to see the code.

As an example, one of my HackerRank exam questions is to implement root mean squared error. It’s easy enough to create many tests for that.

But, there are also questions that I’m interested in giving that require the writing of a function or a class that exhibits some kind of behavior that has nothing to do with reading or writing anything.

Then, I need to provide some code that would test the student-written code, I need to be sure the student doesn’t change my test code, and I need to see the student’s code to confirm that they haven’t simply hardwired results that would fool my tests.

For all of that there is HackerRank for Work!

That’s the kind of account that companies buy so their recruiters can evaluate prospective software engineers.

The great news is that a HackerRank for Work account is free for education purposes. You just have to request it.

With that kind of account I can create code stubs that students can not edit and once submitted I can see the code of the submission.

This has been huge in my ability to now create electronic exams that test coding ability.


I am enamored with HackerRank!

HackerRank is an online judge, similar to Codeforces, Kattis, Sphere, and UVa.

All of these have the following in common:

  • a large set of challenges (ACM-ICPC) like problems)

  • contests

  • a variety of languages can be used to solve the challenges

  • a global leaderboard

Features that are somewhat unique to HackerRank are:

  • it’s being used by many companies to screen prospective employees

  • challenges are categorized by type (e.g. dynamic programming)

  • a submission is given several tests, you’re told how many tests failed and how many succeeded, and receive a grade accordingly

  • you can create your own contests with HackerRank challenges or your own challenges with leaderboards just for your students

I’ve successfully run two contests for my students this term, one with a HackerRank challenge and another with a UVa challenge that I copied, and for which I have several test cases.

So, if you have a programming project that only reads ASCII from stdin and only writes ASCII to stdout, and for which you have several test cases, I think it’s very attractive to create a HackerRank contest with either HackerRank challenges or your own.

Canvas Set Default Grade

If you use the gradebook in Canvas this may be of interest to you.

Canvas displays the grades to you and to your students in two modes:

  1. Don’t treat ungraded as zero. (default)
  2. Treat ungraded as zero.

You can select (2) in the gradebook by clicking the gear wheel on the upper right, but that only effects your view, not your students’ view.

The problem is that as more and more assignments are not turned in by a particular student they then get a distorted view of their total grade, since their undone work is not treated as zero.

To solve this problem I routinely change all not submitted assignments to zero in the gradebook after an assignment has been graded.

This can be done at the top of the column of an assignment in the gradebook, by selecting Set Default Grade, and typing in zero.

Then, (1) or (2), above, doesn’t matter. The totals will be the same.

It’s important to do Set Default Grade after the assignment has been graded, because the student will receive a Canvas notification about that, and that would be a very confusing thing to get before the assignment was graded.

It’s also very good for the student to get an explicit notification every time they don’t submit work.

Hope this is helpful.

GitHub Classroom

I want to be known as the king of software-development tools!!!

Just discovered GitHub Classroom.

I’ve been having my students develop and submit their software to me via git and GitHub for several years.

Students can apply to GitHub for an educational account which will give them unlimited private repos.

In the past I would then have the students invite the graders and me as collaborators, so that we could then clone their repo and grade it.

GitHub classroom makes that last step unnecessary.

You create a GitHub Organization, attach it to GitHub Classroom, and then apply for a discount on repos for that organization.

I got the discount in about a day, and I now have unlimited private repos in that organization for my students.

The graders and I are now automatically co-owners with the students of all the repos, and we can now avoid the hassle of getting many, many requests for collaboration.

Canvas Quizzes

I create daily quizzes on Canvas.

When I do there are several settings that I choose.

It gets tedious to re-choose those settings every time I create a new quiz.

Instead, I create a blank quiz with those settings, but no content, yet, and then export that quiz.

I later import that blank quiz and just fill in the content.


When Bruce gave me CS373: Software Engineering to teach in 2008, he asked that I make my students aware of the various software-development tools used in industry.

I barely knew any, but I’ve learned about many of them from my students and sometimes from the guest speakers from industry that have visited.

I’m now currently using the following:

  • git and GitHub for source control: I also now use this as a substitute for the old turnin program. Students provide us with a git SHA and we pull that particular commit to grade.

  • GitHub for issue tracking, too: Issue tracking tracks bugs and enhancements to the software. There’s also a very nice connection between git commits in GitHub and the closing of issues in GitHub.

  • pylint (Python) and clang-check (C++) for static code analysis: These provide additional checks beyond what the interpreter or compiler would provide.

  • unittest (Python) and Google Test (C++) for unit testing: Both are very much like JUnit. And probably the single most important thing that I teach my students is to write tests BEFORE writing code!

  • coverage (Python) and gcov (C++) for test coverage: It’s important to know what percentage of your code your tests are actually testing.

  • valgrind (C++) for memory checking: I only rarely allow my students to use new and delete, directly, but when they do, valgrind is invaluable.

  • cProfile (Python) and gprof (C++) for code profiling. This is of very limited value in my class, because none of my programming projects is compute intensive.

  • pydoc (Python) and Doxygen (C++) for automated documentation: Both are very much like javadoc.

  • autopep8 (Python) and clang-format (C++) for automated formatting: Everyone has their own favorite coding style. It’s very convenient when we grade for all submissions to have the same style.

  • NumPy (Python) and Boost (C++) for third-party libraries: Writing real software without making use of libraries is almost impossible, so I show a tiny bit of each of these.

  • Travis CI for continuous integration: The second most important thing that I teach my students is to set up a system that will automatically run all regression tests as a result of a commit. It’s also invaluable for students to get their software running on “naked” systems that they have to configure with all the dependencies that their software needs (e.g. all of the above).

Now, I’d like to tell you about my latest find. It’s hardly new, but however much I try to stay on top of things, it sometimes still takes me a while to become aware of a very cool tool out there for a particular purpose.

This time the tool is Docker and DockerHub.

Docker is free and runs on Linux, OS X, and Windows, but it will not run on the CS machines, because it has to run as root.

Docker creates light-weight Linux virtual machines to run on top of your non-virtual machine.

Like Travis CI, the value to the student is again to get their software running on “naked” systems that they have to configure with all the dependencies that their software needs.

But, now, there’s another value, and this time it’s to the instructor.

It is often the case that my students don’t have the most up-to-date versions of the interpreter or the compiler or some tool on their laptop. When that happens I point them to the CS machines, and dictate that their submissions will be graded there, as well.

Now, with Docker, I can configure an image with a particular set of versions (some even more up-to-date than the CS machines have), I can publish that image to DockherHub (again, free, for public images), and I can ask students to get their software running with that image and we can later grade their submissions with that image.

I think that’s huge.

And I wanted to share it with all of you.


Clang-Check is a static analysis tool for C++.


Posted my first StackOverflow answer and it got upvoted!!!