Skip to content

Instantly share code, notes, and snippets.

View grant's full-sized avatar

Grant Timmerman grant

View GitHub Profile
@grant
grant / helloPubSub.js
Last active December 8, 2022 12:56
Hello Cloud Pub/Sub
/**
* Background Cloud Function to be triggered by Pub/Sub.
* This function is exported by index.js, and executed when
* the trigger topic receives a message.
*
* @param {object} data The event payload.
* @param {object} context The event metadata.
*/
exports.helloPubSub = (data, context) => {
const pubSubMessage = context;
@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 / index.html
Last active December 22, 2021 04:05
Docs Quickstart
<!DOCTYPE html>
<html>
<head>
<title>Google Docs API Quickstart</title>
<meta charset="utf-8" />
</head>
<body>
<p>Google Docs API Quickstart</p>
<!--Add buttons to initiate auth sequence and sign out-->
<button id="authorize_button" style="display: none;">Authorize</button>
@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?');
});
{
"name": "nodejs-ff-esm",
"type": "module",
"engines": {
"node": ">=12.0.0"
},
"scripts": {
"start": "functions-framework --target=esm"
},
"dependencies": {
> npm start
> nodejs-docs-samples-esm@0.0.1 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';