Skip to content

Instantly share code, notes, and snippets.

@tanaikech
tanaikech / submit.md
Created October 15, 2021 00:39
Large Decimal Numbers and Exponential Notation for Google Spreadsheet

Large Decimal Numbers and Exponential Notation for Google Spreadsheet

In this report, it has investigated the large decimal numbers and the exponential notation for Google Spreadsheet. When the large decimal numbers are put to the Spreadsheet, the Spreadsheet automatically sets the display value using the exponential notation. In this report, the result when the values are retrieved by Spreadsheet service and Sheets API is shown.

Sample script

At first, please create new Spreadsheet and open the script editor. And please copy and paste the following script. And, please enable Sheets API at Advanced Google services.

function myFunction() {
@tanaikech
tanaikech / submit.md
Last active November 8, 2021 08:23
Parsing Query Parameters from URL using Google Apps Script

Parsing Query Parameters from URL using Google Apps Script

This is a sample script for parsing query parameters from an URL using Google Apps Script. Also this can be used at Javascript. The process cost becomes a bit lower than that of the script using the regular expression.

Sample script

function parseQuery(url) {
  var query = url.split("?")[1];
  if (query) {
    return query.split("&")
 .reduce(function(o, e) {
@tanaikech
tanaikech / submit.md
Last active November 8, 2021 08:25
XPath Tester using Web Apps Created by Google Apps Script

XPath Tester using Web Apps Created by Google Apps Script

In this post, I would like to introduce the xpath tester using Web Apps created by Google Apps Script.

Demo

Usage

;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var BigNumber = require('bignumber.js');
/*
json_parse.js
2012-06-20
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
@erickoledadevrel
erickoledadevrel / FormSubmitFallback.gs
Last active April 9, 2022 18:56
Demonstrate how to create a form submit processing script that can handle missing or duplicate trigger firings.
// Change this values based on your spreadsheet.
var SHEET_NAME = 'Form Responses 1';
var STATUS_COLUMN_NUMBER = 4;
var PROCESSED_STATUS = 'Processed';
var LAST_ROW_KEY = 'lastRow';
var LOCK_TIMEOUT_MS = 60000; // 1 minute
var MAX_RUNTIME_MS = 240000; // 4 minutes
/**
@tanaikech
tanaikech / submit.md
Created September 22, 2021 07:04
Executing Function with Minutes timer in Specific Times using Google Apps Script

Executing Function with Minutes timer in Specific Times using Google Apps Script

This is a sample script for executing a function with the minutes timer in the specific times using Google Apps Script. For example, when this sample script is used, the following situation can be achieved.

  • Execute a function every 10 minutes only in 09:00 - 12:00 and 15:00 - 18:00 for the weekday.

When the above situation is shown as an image, it becomes as follows.

@tanaikech
tanaikech / submit.md
Last active May 31, 2022 01:44
Request of multipart/form-data with Simple Request Body using Google Apps Script

Request of multipart/form-data with Simple Request Body using Google Apps Script

This is a sample script of the request of multipart/form-data with a simple request body using Google Apps Script. I hope that the users will easy to use Class UrlFetchApp by this report.

This report is the updated post of "Multipart-POST Request Using Google Apps Script".

Description

I had already reported about this at this report. In that case, it was required to create a bit complicated request body to request multipart/form-data. Today, by a comment, I could notice the sample script of Class UrlFetchApp in the official document had been updated. By this, I thought that multipart/form-data

@tanaikech
tanaikech / submit.md
Last active December 23, 2022 07:29
Using Google API Client Library (gapi) for JavaScript with Service Account

Using Google API Client Library (gapi) for JavaScript with Service Account

This is a sample script for using Google API Client Library (gapi) for JavaScript with the service account. Unfortunately, in the current stage, gapi cannot directly use the service account. So, in this case, it is required to implement the script for retrieving the access token from the service account. In this report, I would like to introduce the method for using gapi with the service account using a Javascript library.

Sample script

In this sample script, GetAccessTokenFromServiceAccount_js of Javascript library is used. Before you use this script, please set your private_key, client_email and scopes to the variable of object.

<input type="button" value="Run" onClick="run()" />
@peterherrmann
peterherrmann / outerLoop.js
Last active February 28, 2023 12:38
outerLoop for Google Apps Script triggered functions is some boilerplate that encapsulates best practice ways to deal with running workloads that may take longer to process that the time available in an Apps Script triggered run.
//load configuration details and start logging - creates and sets up sheets the first time they are run
var CONFIG_SPREADSHEET_KEY = '<ssid_goes_here>';
var Config = SettingsManager.load(CONFIG_SPREADSHEET_KEY); //Add Mafviu9bMfg9xVu21LGfpWnHAGDwXQ1CH in Resources > Libraries
Logger = BetterLog.useSpreadsheet(Config['logSpreadsheetId'].value);//Add MYB7yzedMbnJaMKECt6Sm7FLDhaBgl_dE in Resources > Libraries
// trigger this function
function outerLoop() {
try {
// to calc elapsed time
var isOverMaxRuntime = false,
@erickoledadevrel
erickoledadevrel / xmlToJson.js
Created December 1, 2014 14:30
A function to convert an XML string to a JSON object in Apps Script, using logic similar to the sunset method Xml.parse().
/**
* Converts an XML string to a JSON object, using logic similar to the
* sunset method Xml.parse().
* @param {string} xml The XML to parse.
* @returns {Object} The parsed XML.
*/
function xmlToJson(xml) {
var doc = XmlService.parse(xml);
var result = {};
var root = doc.getRootElement();