Skip to content

Instantly share code, notes, and snippets.

View grant's full-sized avatar
Coding daily!

Grant Timmerman grant

Coding daily!
View GitHub Profile
@grant
grant / maps.js
Created September 12, 2022 00:02
Simple Maps Apps Script
/**
* Gets driving directions from Mountain View to San Francisco.
* Derived from https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/maps/maps.gs
* @customfunction
*/
function getDrivingDirections() {
// Set starting and ending addresses
var start = '1600 Amphitheatre Pkwy, Mountain View, CA 94043';
var end = '345 Spear St, San Francisco, CA 94105';
var directions = Maps.newDirectionFinder().setOrigin(start).setDestination(end).getDirections();
@grant
grant / package.json
Last active December 19, 2021 01:07
Hot Reload Node Functions
{
"main": "index.js",
"dependencies": {
"@google-cloud/functions-framework": "^2.1.0"
},
"watch": {
"start": "*.js"
},
"devDependencies": {
"npm-watch": "^0.11.0"
@grant
grant / package.json
Created December 19, 2021 00:53
Simple Node Function package.json
{
"main": "index.js",
"dependencies": {
"@google-cloud/functions-framework": "^2.1.0"
},
"scripts": {
"start": "npx @google-cloud/functions-framework --target=helloWorld"
}
}
@grant
grant / index.js
Created December 19, 2021 00:51
Simple Node Function
const FunctionsFramework = require('@google-cloud/functions-framework');
FunctionsFramework.http('helloWorld', (req, res) => {
res.send('Hot-reload me?');
});
> npm start
> [email protected] start /Users/timmerman/Documents/github/googlecloudplatform/functions-framework-nodejs/docs/esm
> functions-framework --target=esm
Serving function...
Function: esm
Signature type: http
URL: http://localhost:8080/
export function esm(req, res) {
res.send(`Hello, ${MY_CONST}!`);
};
import {MY_CONST} from './consts.js';
export const MY_CONST = 'ESM';
{
"name": "nodejs-ff-esm",
"type": "module",
"engines": {
"node": ">=12.0.0"
},
"scripts": {
"start": "functions-framework --target=esm"
},
"dependencies": {
@grant
grant / setup_iam.sh
Created May 16, 2021 16:40
A script that sets up Workflows IAM for a GitHub Action
# Add secret for project
PROJECT=$(gcloud config get-value project)
gh secret set GCP_PROJECT_ID -b $PROJECT
# Create service account
SERVICE_ACCOUNT=my-wf-service-account
gcloud iam service-accounts create $SERVICE_ACCOUNT
gcloud projects add-iam-policy-binding $PROJECT \
--member "serviceAccount:$SERVICE_ACCOUNT@$PROJECT.iam.gserviceaccount.com" \
--role "roles/workflows.editor"