Skip to content

Instantly share code, notes, and snippets.

View andrewroberts's full-sized avatar
💭
Cranking out the code... 👨‍💻

Andrew Roberts andrewroberts

💭
Cranking out the code... 👨‍💻
View GitHub Profile
@andrewroberts
andrewroberts / testOpenStackGASLibrary.gs
Created October 7, 2015 09:06
GAS OpenStack API Library example
// Memset/OpenStack API
// --------------------
// Include the GAS OpenStack library - Mo6MqgzKidu5VYzZ7NzIM-tnfWGfgtIUb
// Complete these fields appropriately for your storage provider
var OPENSTACK_ROOT_URL = '[URL of storage using OpenStack API]' // e.g. 'https://auth.storage.memset.com/v2.0/'
var OPENSTACK_USERNAME = '[Enter username here]'
@andrewroberts
andrewroberts / OpenStack.gs
Created October 7, 2015 09:11
Google Apps Script library for the OpenStack RESTful API
// 34567890123456789012345678901234567890123456789012345678901234567890123456789
/**
* @fileOverview GAS Library for accessing an <a href="http://developer.openstack.org/api-ref.html">OpenStack API</a>. Library ID - Mo6MqgzKidu5VYzZ7NzIM-tnfWGfgtIUb
* @author <a href="mailto:andrew@roberts.net">Andrew Roberts</a>
* @copyright <a href="http://www.andrewroberts.net">Andrew Roberts</a>
*/
/*
* This program is free software: you can redistribute it and/or modify it under
@andrewroberts
andrewroberts / GASNeverBounce.gs
Created January 29, 2016 09:27
Google Apps Script for accessing NeverBounce RESTful API (and writing to a GSheet)
var VALID_COLUMN_INDEX = 4
var EMAIL_COLUMN_INDEX = 3
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Validate Emails')
.addItem('Validate Sheet', 'validateEmail')
.addToUi()
}
@andrewroberts
andrewroberts / StackTraces-Logging-GAS.md
Last active July 7, 2017 11:58 — forked from hlecuanda/StackTraces-Logging-GAS.md
Example using Stackdriver logging for debugging a custom function for sheets in Google Apps Script. / Writing a Caching custom function

Logging custom functions using stackdriver in google apps script

Recently, console logging became available for Google Apps Script projects. It used to be impossible to use the Log service that comes with the GAS runtime, but now all you need to do is throw an exception. Exceptions get logged in stackdriver logging and when enabled, unhandled exceptions will not stop your script execution. This adds up to nearly 0 lag if you are using this feature (?) by purposely throwing exceptions, and you can get creative with your error message to avoid having to expand stackdriver's log messages (which are pretty comprehensive stacktraces!)

Setup

@andrewroberts
andrewroberts / TrialBalance.gs
Last active December 17, 2017 15:27
Google Apps Script request to Xero API for trial balance - snippet for Xero Forum question
function getTrialBalancesWithNoDate() {
// .
// .
// .
fetchPublicAppData('Reports/TrialBalance', '', '') // OK
// .
// .
@andrewroberts
andrewroberts / getAddress.gs
Created November 16, 2015 19:44
Google Sheets custom function to get Google's best guess at the address of a place.
function GET_ADDRESS(placeName) {
var response = Maps.newGeocoder().geocode(placeName);
return response.results[0].formatted_address 
}
@andrewroberts
andrewroberts / Terrain.gas.js
Created February 14, 2015 17:24
Generates terrain values for a 257x257 Google sheet
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Terrain')
.addItem('Generate terrain map', 'createTerrain')
.addToUi();
}
@andrewroberts
andrewroberts / CreatePDFRenameAndEmail.gs
Last active October 10, 2019 15:19
A Google Apps Script that uses the values from a Google Sheet to construct a PDF from a GDoc template. It allows you to specify a name for the file and email it to someone. This is a demo sheet: https://docs.google.com/spreadsheets/d/1jLpPtmUS8__PceJx9z5iSSaLSfENojWK7hfsH6uHa9Y/edit#gid=0. It is a development of the CreatePDF script (https://gis…
/*
PDF Create - with rename and email
==================================
When you click "Create PDF>Create PDF" this script uses the data from
the active row to construct a PDF in your GDrive. The value in the
"File Name" column is used to name the file and - if there is a
value - it is emailed to the recipient in the "Email" column.
@andrewroberts
andrewroberts / Log.gs
Last active January 4, 2020 14:32
A simple wrapper for the BetterLog Google Apps Script Library - GAS Library MqTFuiXcPtS5rVUZ_jC9Z4tnfWGfgtIUb
// 34567890123456789012345678901234567890123456789012345678901234567890123456789
// JSHint: 22 March 2015 08:56 GMT
// Unit Tests: 22 March 2015 08:50 GMT
/*
* Copyright (C) 2015-2017 Andrew Roberts (andrew@roberts.net)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@andrewroberts
andrewroberts / formatString.js
Created February 14, 2020 07:26
JavaScript function to format various value types as a string.
function testNumber() {
var value = 1234.56789
var a = format(value, {numberOfDecimalPlaces: 2})
debugger
}
function testDate() {
var value = new Date()
var a = format(value)