Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
@brainysmurf
brainysmurf / CollectColumnsThatContainsNames.md
Last active September 24, 2023 12:06
Learn how to identify and output all columns that have certain text

GSheets Formula Tipizoid #1

Learn how to collect a series of columns that that contains target text in the header. Link to Example

The data

You have a database-like table in a Google spreadsheet that is the output of a Google Form that asks questions on a variety of topics. The form itself is organized into sections, where the the first question ("What grade are you in?") will then jump to the relevant section with grade-specific questions. Each section has some questions that repeat ("English") but others that do not ("Design" because students don't take Design until 9th Grade). The result is the following:

        (  First section in form   ) (    Second section in form   )
import time
prompt = """
You have a choice:
a) $1 million, right now
b) $0.02 right now, then doubled every month
"""
while True:
function testDailyTrigger() {
var e = {}, f = {};
f.test = true;
f.day = app.libraries.interface.dates.today();
//e.day.add(1, "days");
f.agents = ['[email protected]'];
f.updateSite = false;
triggerDailyTrigger({}, f);
}
@brainysmurf
brainysmurf / README.md
Created January 14, 2019 11:39
A Tour of Concurrent Processing in Apps Scripts

A Tour of Concurrent Processing Techniques in Apps Scripts

The JavaScript engine implemented in Google Apps Scripts is decidedly syncronous and sequential, there is a time-limit to how long a script can execute, and there are a variety of quotas on every API endpoint.

In use cases where there is a large amount of information to be retrieved from APIs, the developer will need to deploy techniques to work around the discussed limitations.

This gist explores the variety of methods available in the stack that works around these. Specifically, we will work with the Google Drive API to explore this topic as learning tool.

A note on the Code

@brainysmurf
brainysmurf / SampleLibrary.gs
Created January 3, 2019 13:05
Example Sample Library
function works () {
return 'Hello World!';
}
@brainysmurf
brainysmurf / Descriptors.gs
Last active January 4, 2019 17:47
Descriptors for Google Apps Scripts
Object.defineProperty(Object.prototype, '__descriptor', {
set: function (options) {
if (options.getter) {
Object.defineProperty(this, options.property, {
get: options.getter,
configurable: true,
enumerable: true
});
}
if (options.set) {
@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 / DatabaseFromSpreadsheet.js
Last active September 24, 2023 12:08
In AppMaker, use this to read in data from a Spreadsheet.
/**
* DataFromSpreadsheet: Read in Spreadsheet info for a Calculated Datasource in AppMaker. Use a spreadsheet to define a datasource.
* Useful for data modeling, simple Apps.
* Does not support paging; sheets with large number of rows will see performance penalties
* @param {object} params
* @param {string} params.spreadsheetId The ID of the source spreadsheet
* @param {string} params.sheetName The name of the source sheet
* @param {string} params.datasource The name of the target datasource
* @param {number} params.numHeaders How many rows are headers (default = 1)
* @param {number} params.headerRow Which row contains the name of the field (default=params.numHeaders-1)
@brainysmurf
brainysmurf / DecoratorPattern.md
Last active September 24, 2023 12:10
Decorator Pattern. A way to manipulate function behavior other than sending parameters.

Decorator Pattern in Apps Scripts

Introduction

We'll identify a problem that can be solved with the decorator pattern. This is essentially "decorating" a wrapping function where there is additional implementation "inside". It's an effective way to define a inject some code around before or after a function executes. Here is an example that times how long it took to execute a function:

var timeit, publicFunction;

timeit = function (f) { /* definition below */ };
@brainysmurf
brainysmurf / jsonp.gs
Created April 24, 2018 13:10
jsonp in google apps scripting
/*
Suppose there is some endpoint that returns a jsonp to you, as in Google Visualization API
It gives you a text response that looks like this:
"some.namespace.nameOfFunction({obj:'blah'})"
We want the object inside that function call.
In a google app scripting context, we have no choice but to evaluate it the old-fashioned way, using "evil" eval().
This solution builds a variable that resolves the namespace some.namespace.blah.blah and which ultimately becomes
a function that returns the passed parameter.
We build the variable with raw text, then eval it, giving the local context the ability to resolve the namespace and