Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
@brainysmurf
brainysmurf / example.json
Last active January 11, 2022 22:39
PYP term grade response object
{
"id": 11084391,
"name": "Harris, Mark",
"term_grade":
{
"comments": "<p>observ comment</p>",
"rubrics":
[
{
"id": 6484,
@brainysmurf
brainysmurf / tests.js
Last active November 16, 2021 02:18
Use datatables.net from within Postman as visualizer
/**
* Get an overview table of all items returned from the endpoint, useful for when there lists of objects are returned.
* See comments below for screenshots.
*
* https://gist.github.com/brainysmurf/e45f608b68609f8a0b222ac99b8905d8
*
* To use, copy the below code into the "Tests" tab of the endpoint
* Click blue "Send" button
* Click on "Visualize" in the Body tile
* Note that it only displays the returned objects, there's nothing magical that's getting "all" objects via pagination
@brainysmurf
brainysmurf / README.md
Last active September 12, 2021 12:03
FEG

FEB Virtual Community: Visualizations

Please find attached!

@brainysmurf
brainysmurf / snippet.js
Last active July 9, 2021 06:33
outputSheet snippet
/**
* Append a 2d array to an existing sheet or can create a new sheet
* to match the largest row in the dataset.
* davidsottimano.com
* @param {array} data 2d array of data
* @param {string} sheetName (optional) The sheet you want to output to. If the sheet does not exist, this script will auto-create a new sheet with the specified sheet name. If the sheetName is not specified, a new sheet will be created
*/
function outputToSheet(data, sheetName=null) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
if (sheetName==null) sheetName = 'Default Sheet Name';
@brainysmurf
brainysmurf / README.md
Last active June 22, 2021 12:53
Performance of Endpoins library using fetch requests compared to advanced service.

Motivation

After a few months of using my Endpoints library to help solve myriad of problems in production, I've only had anecdotal evidence that it was a "way more" performant way of interacting with API endpoints, compared to more traditional method of using AppsScripts advanced services. So I decided to actually measure it.

The Test

In my domain, there are 26 google groups, a set for each grade in the school, where a set is one for students and one for parents. We have about 30 students per grade, which means membership of the each students group is about 30, but for the parents, it is twice that (as both parents are a member).

With two different code bases, I download all memberships of all these groups.

@brainysmurf
brainysmurf / Code.gs
Last active June 6, 2021 08:46
Performance of various iterations in AppsScripts
function measure_({func, arr}) {
const start = new Date().getTime();
func.call(null, arr);
const end = new Date().getTime();
const delta = end - start;
const report = `${func.name} took ${delta} milliseconds`;
Logger.log(report);
return delta;
/**
* This is my version of what I embed into libraries I want to track, as cluster.
* This way it ensures that consistent name, version used throughout, and easy to define namespace
* Note use of "name" "space" parameters
*/
function TrackMyself ({name='dottie', space=null, version='v1.5', ...kwargs}={}) {
if (Object.keys(kwargs).length>0) throw new TypeError("Unexpected param received");
const track = cttLibTracker.TrackMyself;
const options = {
@brainysmurf
brainysmurf / README.md
Last active May 7, 2021 05:44
ManageBac -> Google Spreadsheet API integration

ManageBac -> Google Spreadsheet API integration

About

Hi there! This gist is a bit outdated. The good news is that you can go here instead:

As of May 2021, it is actively supported.

@brainysmurf
brainysmurf / ResolveAlias.js
Created December 10, 2020 15:51
Resolve aliases given email in appscripts.
function resolveAlias_(email) {
var resp, ret;
try {
resp = AdminDirectory.Users.Aliases.list(email);
} catch(e) {
if (e.message === 'Resource Not Found: userKey') {
return null;
}
return null;
}
@brainysmurf
brainysmurf / DependencyInjection.js
Created February 23, 2021 02:05
Illustrating how one can orchestrate mocks using dependency injection
function work_ (url, {UrlFetchApp_=UrlFetchApp}={}) {
Logger.log(url);
return UrlFetchApp_.fetch(url).getContentText();
}
function testWork() {
const url = 'https://example.com';
const response1 = work_(url);
Logger.log(response1);
class Mocked {