Skip to content

Instantly share code, notes, and snippets.

@bennettscience
bennettscience / chart.gs
Last active September 19, 2018 07:58
Code to display Google Sheets data as a web-based dashboard
// Pie Chart visualization client-side scripting
// Initialize the script and grab the data from the spreadsheet.
google.script.run.withSuccessHandler(drawChart).getSpreadsheetData();
google.load("visualization", "1", {packages:["corechart"]});
// Using the returned data from the spreadsheet, draw the chart.
// ssData is a 2D array of the candidate name and their electoral vote totals from the spreadsheet.
function drawChart(ssData) {
@bennettscience
bennettscience / code.gs
Last active November 8, 2016 02:34
Displaying data using AJAX from a Google Sheet
// Server side scripts to draw and load the page.
// Call the sheet
var ss = SpreadsheetApp.openById('SPREADSHEET_KEY');
// Initialize the HTMLService and draw the page from the template.
function doGet() {
return HtmlService
.createTemplateFromFile("index")
.evaluate();
@bennettscience
bennettscience / assignCons.gs
Created November 18, 2016 16:35
Custom spreadsheet to track students missing an ID
/**
* @param {Obj} a - array from daily list built
**/
function assignCons(a) {
// These rely on the global variables set at the top of the script
var sheet = ss.getSheets()[2];
var data = sheet.getDataRange().getValues();
var target = ss.getSheets()[3].getRange("A2").getValue();
@bennettscience
bennettscience / linkTranslatedDocs.gs
Created November 24, 2016 01:59
Link two documents for translation updates
var ui = DocumentApp.getUi();
var docProps = PropertiesService.getDocumentProperties();
// Grab the document body.
// No formatting, tables, etc are kept.
function getText() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
Logger.log(body.getText());
var array = [];
@bennettscience
bennettscience / edit_content_img.php
Last active January 2, 2017 04:08
flickr RSS XML object
/* Put this into the WordPress functions.php file to embed a large image from the Flickr RSS feed */
function edit_content_img($content) {
$content = preg_replace("/(_m)/", "_b", $content);
return $content;
}
add_filter( 'the_content', 'edit_content_img');
@bennettscience
bennettscience / code.gs
Last active March 28, 2024 10:12
Custom course registration site with Google Apps Script
// ALL SERVER CODE RUNNING ON THE SPREADSHEET
// new property service GLOBAL
// see: https://developers.google.com/apps-script/reference/properties/
var SCRIPT_PROP = PropertiesService.getScriptProperties();
// Grab the correct spreadsheet
var sheet = SpreadsheetApp.openById("spreadsheetIdHere");
/**
@bennettscience
bennettscience / form.html
Created June 15, 2017 00:24
Form for Ray Bird snail mail
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Camp Ray Bird Summer Camp</title>
<meta name="description" content="Summer Camp and Mission Work at Camp Ray Bird"/>
<meta name="rating" content="safe for kids" />
<link rel="stylesheet" href="styles/style.css" type="text/css"/>
<script type="text/javascript">
@bennettscience
bennettscience / gifify2.sh
Last active September 8, 2017 18:51
gifify hack
#!/bin/bash
set -euo pipefail
function printHelpAndExit {
echo 'Usage:'
echo ' gifify [options] filename'
echo ''
echo 'Options: (all optional)'
echo ' c CROP: The x and y crops, from the top left of the image, i.e. 640:480'
@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++) {
@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()