Skip to content

Instantly share code, notes, and snippets.

View DinoChiesa's full-sized avatar

Dino Chiesa DinoChiesa

View GitHub Profile
@DinoChiesa
DinoChiesa / JS-ShredJSON.xml
Last active June 10, 2021 17:15
Shred JSON into context variables
<Javascript name='JS-ShredJSON' timeLimit='200' >
<Properties>
<Property name='output-prefix'>private</Property>
<Property name='source'>ContextVariableContainingJSON</Property>
</Properties>
<ResourceURL>jsc://extractJsonToContextVars.js</ResourceURL>
</Javascript>
@DinoChiesa
DinoChiesa / getTokenWithServiceAccount.js
Last active April 16, 2021 00:18
get a GCP token using a Service Account .json file
// getTokenWithServiceAccount.js
// ------------------------------------------------------------------
// uses only builtin modules, no external dependencies.
/* jshint esversion:9, node:true, strict:implied */
/* global process, console, Buffer */
const crypto = require('crypto'),
util = require('util'),
// invokeCallsWithLimit.js
// ------------------------------------------------------------------
//
/* jshint esversion:6, node:false, strict:implied */
/* global properties, httpClient, context, Request */
// Specify the limit of concurrent outbound requests
const ASYNC_LIMIT = 3;
/* tweak-expiry-display.js */
/* jshint esversion:9, browser:true, strict:implied */
/* global window, navigator, console, fetch, Buffer */
/*
Instructions
Add this as a "custom script" in the "Settings" dialog for the portal.
Be sure to bracket this source with open-and-close script tags.
@DinoChiesa
DinoChiesa / 0-gcloud commands
Last active January 28, 2021 00:32
gcloud commands for interacting with Apigee, and also nodejs code to sign a JWT, for use in a request-for-token sent to Google APIs
(First create a service account and create+download a keyfile for it)
KEY_FILE=~/Downloads/name-of-the-downloaded-keyfile.json
(download and install gcloud if you don't have it)
gcloud components update
gcloud auth list
// weightedRandomSelector.js
//
// simple weighted random selector.
//
// Copyright © 2013, 2014 Dino Chiesa and Apigee Corp
// All rights reserved.
//
// created: Fri, 26 Jul 2013 11:14
// last saved: <2019-June-24 06:13:20>
//
// fixupCookies.js
// ------------------------------------------------------------------
//
// Intended to modify cookies within an API Proxy to
// add SameSite=None; Secure to each cookie.
//
// Implements a parser to extract cookies from a header.
//
// This is necessary because Apigee folds all the
// Set-Cookie header values into one, which isn't right
@DinoChiesa
DinoChiesa / updateSheets.js
Last active January 14, 2020 14:40
boilerplate for building a command-line app in nodejs that uses OAuth2 client id to update Google sheets
// updateSheets.js
// ------------------------------------------------------------------
//
// created: Tue Jan 14 05:22:42 2020
// last saved: <2020-January-14 06:34:31>
const fs = require('fs'),
path = require('path'),
util = require('util'),
{google} = require('googleapis'),
// base64.js
// ------------------------------------------------------------------
//
// Bas64 encoder and decoder
//
// created: Sat Feb 20 12:30:51 2016
// last saved: <2016-May-19 11:48:04>
(function (){
const app = require('express')(),
bodyParser = require('body-parser'),
yes = require('yes-https'); // HSTS => https always
var gStatus = {
version : '20180619-1845'
};
// HSTS on only if process.env.NODE_ENV == 'production'
app.use(yes());