Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
@brainysmurf
brainysmurf / Other.gs
Last active December 9, 2017 13:51
Other
function Package () {
return {
spooky: function () { return "BOO!" },
}
}
@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 || {};
@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 / DbSheets_Temp.gs
Last active December 25, 2017 04:01
DbSheets_Temp Adds the ability to use temporary spreadsheets within dbsheets.
(function (global, Factory) {
/*
Build upon dbsheets
*/
if (pkg && pkg.dbsheets && pkg.dbsheets.extend) {
pkg.dbsheets.extend.registerInit(function (dbObj) {
dbObj.makeTemp = function (title) {
title = title || "Temporary";
return dbObj.createWithTitle(title);
@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');
@brainysmurf
brainysmurf / FormatLogger.gs
Last active January 21, 2018 10:05
FormatLogger is an alternative logging module for google app scripting. This gist is for the package manager.
(function (global, Factory) {
global.pkg = global.pkg || {};
pkg.formatLogger = function () { return Factory.apply(Factory, [global].concat(Array.prototype.slice.call(arguments))); }
pkg.formatLogger(); // can be overwritten with another call if transformers are desired
})(this,
function Package (global, options) {
options = options || {};
if (options.useLogger)
options.loggerObject = Logger;
@brainysmurf
brainysmurf / MBRequests.gs
Last active March 10, 2018 08:53
ManageBac Endpoint Requests
(function (global, Package) {
global.Requests = (function wrapper (args) {
var wrapped = function () { return Package.apply(Package, arguments); }
for (i in args) { wrapped[i] = args[i]; }
return wrapped;
}({
utils: {
/*
Merge keys from target into source
@brainysmurf
brainysmurf / Minified.gs
Last active March 17, 2018 01:54
Package Wrapper
(function(global,name,Package,helpers){var ref=function wrapper(args){var wrapped=function(){return Package.apply(global.Import&&Import.module?Import._import(name):global[name],arguments)};for(i in args){wrapped[i]=args[i]}return wrapped}(helpers);if(global.Import&&Import.module){Import.register(name,ref)}else{Object.defineProperty(global,name,{value:ref});global.Import=global.Import||function(lib){return global[lib]};Import.module=false}})(this,
"Name",
{ /* helpers */ }
);
@brainysmurf
brainysmurf / Import.gs
Created April 1, 2018 11:26
Import other modular libraries.
(function Package_ (global) {
global.Import = function (lib, options) {
options = options || {};
options.namespace = options.namespace || false;
options.base = options.base || false;
if (options.namespace) {
var p = global, g = global, last;
options.namespace.split('.').forEach(function (namespace) {
g[namespace] = g[namespace] || {};
p = g