Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
@brainysmurf
brainysmurf / StringFormat.gs
Last active January 12, 2018 03:32
StringFormat: A simple templating for strings: Every string gets a String.format method so we can do "{greeting}, {noun}".format({greeting:"Hello",noun:"world")
/*
Note we don't need typical boilerplate here because it polyfills String.prototype
*/
(function (global) {
// Taken from davidchamber's string-format
// https://github.com/davidchambers/string-format
// To use, simply:
// "Hello, {}".format('world');
"""
"""
import time # for sleeping
class App:
def __init__(self, stage):
self.stage = stage
def run(self):
@brainysmurf
brainysmurf / ContextManager.gs
Last active December 24, 2017 22:43
G Suite App Scripting utilities
(function (global, Factory) {
global.pkg = global.pkg || {};
global.pkg.contextManager = function () { return Factory.apply(Factory, arguments); }
})(this,
/*
@param {Function} body: optional
@param {Object} options: @prop {Function} enter: The function called on entry
@prop {Function} exit: The function called on exit
@prop {Function} onError: The function called on error, not re-raised if returns null
@brainysmurf
brainysmurf / PackageManager.js
Last active September 24, 2023 12:17
Package Manager: Manage libraries in apps script, establish convention for including packages, optionally use TDD.
/*
* PackageManager © Adam Morris classroomtechtools.ctt@gmail.com
* A toolchain solution for test-driven development and package management
* What it does:
* - Provides boilerplate code to make modular packages publishable as gists
* - Define and adds all those dependencies to the project so that there are completely modular
* - Access them in your own code with "pgk.namespace" where the namespace is defined in the dependency setup file
* - Test the modules with TDD practices!
* To use:
* - Make a copy: https://script.google.com/a/igbis.edu.my/d/1ClAoUIZdC5VJ0nM3_1NIYwW-sr-LLXT_9rLc9B0Tj5SikYWwBuFucyRu/edit)
@brainysmurf
brainysmurf / Utgs.gs
Last active January 20, 2021 01:29
Utgs
/*
Imported via dev.gs
*/
(function (global, Factory) {
global.pkg = global.pkg || {};
global.pkg.utgs = (function wrapper (args) {
var wrapped = function () { return Factory.apply(Factory, [global].concat(Array.prototype.slice.call(arguments))); };
for (i in args) { wrapped[i] = args[i]; }
return wrapped;
@brainysmurf
brainysmurf / Other.gs
Last active December 9, 2017 13:51
Other
function Package () {
return {
spooky: function () { return "BOO!" },
}
}
@brainysmurf
brainysmurf / Mine.gs
Last active December 9, 2017 13:51
Mine
function Package () {
return {
output: function () { return "works"; }
}
}
@brainysmurf
brainysmurf / DBSheets.gs
Last active September 24, 2023 12:13
DBSheeets
(function (global, Factory) {
global.pkg = global.pkg || {};
global.pkg.dbsheets = (function wrapper (args) {
var wrapped = function () { return Factory.apply(Factory, arguments); }
for (i in args) { wrapped[i] = args[i]; }
return wrapped;
}({
extend: {
registered: [],
registerInit: function (func) {
@brainysmurf
brainysmurf / ArrayPolyfills.gs
Created December 16, 2017 03:09
ArrayPolyfills: Including Array.from
// from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
(function (global) {
// Production steps of ECMA-262, Edition 6, 22.1.2.1
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
@brainysmurf
brainysmurf / Moment.gs
Last active December 16, 2017 04:20
Moment.js for App Script
//! moment.js
//! version : 2.18.1
//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
//! license : MIT
//! momentjs.com
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.pkg = global.pkg || {};