Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
@brainysmurf
brainysmurf / README.md
Last active September 24, 2023 11:53
Learning V8 by re-solving old problems

Learning V8 by re-solving old problems

Here, I'll document some code I found to be much easier or better to do in an appscripts context with modern Javascript.

Breaking A1Notation into constituent parts

You have a string that represents a range speciation using a1Notation. You need to get the starting row number. Or you need to get the last column. Or you need to get all of those things. You'd like to do it in a way that can be reused. And you wonder if some of the new syntax features makes this interesting.

Let's go over the skeleton of the function first:

@brainysmurf
brainysmurf / MeetsAuditActivityInsights.md
Last active April 28, 2020 12:40
A case study in writing reusable code on the Google AppsScripts (GAS) platform, with V8 features

Meets Audit Activity Insights

Interacts with the Activities.list endpoint available on GSuite domains that lists lots of Meets activity information. It's the same endpoint used in its own reporting console, such as the Meets Quality Tool.

It downloads row-by-row all of this raw information, going back days number of days, saves into the spreadsheet into meet data sheet.

Additional sheets contain pivot tables that provide insights into the data, such as IP location info, duration of calls, frequency of use. Leadership boards are derived from those pivot tables.

License

@brainysmurf
brainysmurf / README.md
Last active May 26, 2020 01:02
How to make a timer with a context manager

Timer

This is some sample code that shows how use a design pattern to implement a timer.

To use:

  • Create the new Timer instance, indicating time
  • call .body on the instance, where the first parameter is the function to execute
  • periodically within that function, call this.check() which will raise TimeUpErr error if the duration has expired
@brainysmurf
brainysmurf / README.md
Created June 21, 2020 08:32 — forked from Tynael/README.md
How to use npx to run gist based scripts
@brainysmurf
brainysmurf / CoderVsAppsScriptsIDE.md
Last active December 29, 2023 20:40
A conversation between a coder and the new AppsScripts IDE

A conversation between a coder and the new AppsScripts IDE

The main takeaway I have is that coders are going to be talking to their new IDEs, maybe sometimes loudly but most of the time in thanks, and that is a good thing. This was written in early December 2020:

The view from 3000 ft

With the new IDE for AppsScripts, that platform has completed what you might think of as a nearly complete overhaul. It came in two stages, (with hopefully a third one around the corner, but not the focus of this essay).

  1. Months ago: The new V8 engine, giving it a modern runtime environment, and cool new syntax features
  2. This week: A new IDE, which gives us a proper logger and a dependable debugger, and makes finding easy-to-fix programming mistakes a cinch
@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 {
@brainysmurf
brainysmurf / Bundle.js
Created March 30, 2021 02:27
BundlerPattern for appsscripts libraries
/**
* Should be listed first in the list. Creates the `Import` object and adds properties to it
*/
// create a simple object where we can add namespaces
const Import = Object.create(null);
(function (exports) {
// define your stuff in an iife …
@brainysmurf
brainysmurf / DynamicPropertiesJS.md
Last active December 29, 2023 20:37
Using dynamic property assignments

I was recently wokring on building some objects that had this pattern:

const obj = {
  startRowIndex: 0,
  endRowIndex: 1
}

or

@brainysmurf
brainysmurf / readme.md
Last active December 25, 2023 11:09
Extending classes in Libraries with AppsScripts

A question on an #AppsScripts user forum led me into an investigation into the best way to extend a class, for example a Date class, from inside a library so that the host project can use it.

Let's suppose we want to make a class BetterDate that extends the date object so that it automatically calculates the result of .getTime() once. (Maybe we don't want to waste time? rimshot)

We'll add an instance method on it to calculate how many days we have to wait (until our birthday). We also need a static object now() on it so that we can get a now date that is an instance of BetterDate.

This to me is most elegant:

// lib code