Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
@brainysmurf
brainysmurf / Timetabling-ASC-ManageBac.md
Last active April 4, 2023 13:52
Timetabling with aSc and ManageBac

Timetabling with aSc and ManageBac

This gist will explain how I built a schedule with aSc timetables, and used the exported XML data to turn it into CSVs compatible with ManageBac's bulk imports for classes and timetable uploads.

This is not intended to provide a complete end-to-end solution, but to provide timetablers with general strategies with specific examples. In particular, the use of aSc subjects and divisions, how they should coincide with complex scheduling needs, and then how to get it to a "flat" output for csv upload. There are a variety of ways to specify a timetable with aSc; this solution only uses constraints provided by subject and division specifications.

This example uses a 7-Day Timetable (Day 1, Day 2, … Day 7), where each day has four blocks (Block 1, Block 2, … Block 4), and each block can be divided into two periods. (Block 1 consists of periods 1 and 2, Block 4 consists of periods 7 and 8). There are seven subjects, plus some school-specific subj

/**
* 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 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
@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 / 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 / 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 / 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 / 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 / README.md
Created June 21, 2020 08:32 — forked from Tynael/README.md
How to use npx to run gist based scripts
@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