Skip to content

Instantly share code, notes, and snippets.

@bennettscience
bennettscience / config
Created March 17, 2018 18:30
git config sample
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
@bennettscience
bennettscience / outcome.py
Created February 1, 2018 16:34
Playing with the Canvas LMS python API
from canvasapi import Canvas
API_URL = 'https://my.url.com'
API_KEY = 'mySTringKEy123'
canvas = Canvas(API_URL, API_KEY)
outcome = canvas.get_outcome(5426)
class Rating:
@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 / index.js
Created December 31, 2017 02:34
Node JS function to watch Firebase realtime database
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
admin.initializeApp(functions.config().firebase);
// set up email credentials in firebase.config
// See https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users for example
const gmailEmail = functions.config().gmail.email;
@bennettscience
bennettscience / code.gs
Last active November 28, 2017 19:32
Automatically create bit.ly shortlinks of Google Forms via the API
// Copyright 2017 Brian E. Bennett
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@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 / 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 / isTimeUp.gs
Last active November 16, 2017 13:35
Prevent script timeouts in Google Apps Script
function isTimeUp_(starttime) {
var now = new Date();
return now.getTime() - starttime.getTime() > 270000; // 4.5 minutes
}
// Set the start time outside the loop
var starttime = new Date();
// Inside your function, check the time and break to prevent failure mid-loop
for(var i=0; i<data.length; i++) {
@bennettscience
bennettscience / logs.py
Created October 7, 2017 18:52
Download and sort a Google Sheet as JSON
#! /usr/local/bin/python
import json, requests
# Your Google Sheet as JSON feed
url = "https://spreadsheets.google.com/feeds/list/YOUR_KEY_HERE/od6/public/values?alt=json"
# Get the data and store it as a dictionary you can sort
r = requests.get(url)
logs = r.json()
@bennettscience
bennettscience / revisionHistoryLite.gs
Created September 26, 2017 00:56
Proof of concept for a lite-style revision history in Google Docs
function revisionHistoryLite() {
var doc = DocumentApp.getActiveDocument();
var eds = doc.getEditors();
var original = doc.getBody().getParagraphs();
var revs = Drive.Revisions.list(doc.getId())
var editsList = [];
for(var i=0; i<revs.items.length; i++) {