Skip to content

Instantly share code, notes, and snippets.

@bennettscience
bennettscience / iterator.js
Last active September 18, 2021 22:18
Use a JS generator to create an iterator for paginated API responses
'use strict'
/**
* Objeect Oriented implementation of an iterable to handle paginated requests
*
* @param {string} requestMethod HTTP method for the request
* @param {string} firstUrl Endpoint for the request
*
*/
class PaginatedList {
constructor(requestMethod, firstUrl) {
@bennettscience
bennettscience / comment.js
Created December 31, 2017 02:38
Push a comment to a firebase database from a static HTML page
$(function() {
var ref = new Firebase("https://nodes-commenting.firebaseio.com/"),
postRef = ref.child(window.location.pathname);
postRef.on("child_added", function(snapshot) {
var newPost = snapshot.val();
if(newPost.moderated) {
$("#comment-list").prepend('<div class="comment">' +
'<h4>' + escapeHtml(newPost.name) + '</h4>' +
'<div class="profile-image"><img src="http://www.gravatar.com/avatar/' + escapeHtml(newPost.md5Email) + '?s=100&d=retro"/></div> ' +
@bennettscience
bennettscience / fixtures.gs
Last active February 24, 2021 02:45
A simple Mocking framework in Google Apps Script
/**
* Fixtures provide a conventient way to define expected data strucures from API calls. This
* works based on JSON keys and gives a flexible, namespaced access for quickly making Mocks.
*/
const fixtures = (function() {
const init = function() {
return this;
}
@bennettscience
bennettscience / assignment_rubrics.py
Created November 4, 2020 17:42
Get outcome results from a rubric on Canvas LMS assignments
"""
This script will fetch Outcome ratings from assignment rubrics and return a list of dicts.
Requires the use of UCF Open's canvasapi library. Install with `pip install canvasapi`.
Replace PROD_URL and PROD_KEY with your own Canvas URL and API key.
"""
from canvasapi import Canvas
from config import PROD_KEY, PROD_URL
from pprint import pprint
def build_assignment_rubric_results(canvas, course_id, assignment_id):
@bennettscience
bennettscience / update_student_notifications.py
Last active September 24, 2020 22:24
Update student email notifications as an admin in Canvas LMS
import csv
import re
import requests
import concurrent.futures
import time
# pip install tqdm for progress monitoring
from tqdm import tqdm
from functools import partial
"""
@bennettscience
bennettscience / feedback.gs
Last active September 11, 2020 13:46
Automating feedback forms with Google Apps Script
// Copy this script into the feedback spreadsheet TEMPLATE
/************************ OnOpen *******************************/
function onOpen(e) {
var ui = SpreadsheetApp.getUi().createMenu("Shortlink")
.addItem("Show URL and QR code", "showQrAndLink")
.addToUi()
}
/************************ GLOBALS *******************************/
@bennettscience
bennettscience / missing_report.py
Last active May 18, 2020 12:44
Generate a report of missing assignments for all students in a Canvas course. Returns a CSV.
from canvasapi import Canvas # pip install canvasapi
import csv
import concurrent.futures
from functools import partial
KEY = '' # Your Canvas API key
URL = '' # Your Canvas API URL
COURSE = '' # Your course ID
@bennettscience
bennettscience / code.gs
Created November 17, 2017 02:54
Auto-tweet images of slides as a Google Slideshow is presented
// The rest of the backend code.
// postTweet.gs and getThumbnails.gs can be appended to this file.
// When combined, click Publish > Deploy as web app
// You can then test by visiting your app page.
var KEY = "YOUR_APP_KEY";
var SECRET = "YOUR_APP_SECRET";
// Initialize Twitter login
// See https://mashe.hawksey.info/2014/10/twtrservice-a-twitter-api-client-for-google-apps-script/
@bennettscience
bennettscience / script.gs
Last active October 31, 2019 15:30
Automatically set a programmatically-created Google Doc to the correct owner.
/*********** SETUP ***************/
// Store two global variables with columns to use as references.
// These should be zero-based because they're used in a loop.
var docIdCol = 0 // Int of col to check for a document ID
var emailCol = 0 // Int of col with submitter email address
/********** END SETUP **************/
@bennettscience
bennettscience / studentOutcomes.user.js
Last active September 6, 2019 11:53
Collect and display student Outcome score averages in Canvas LMS
// ==UserScript==
// @name Student LMG Viewer
// @namespace https://gist.github.com/bennettscience/cf6a0ec2526844aa672bd3850dee85ee
// @description Show calculated Outcome socres for students in Canvas
// @author Brian Bennett
// @match https://*.instructure.com/courses/*/grades/*
// ==/UserScript==
(function() {
'use strict';