Skip to content

Instantly share code, notes, and snippets.

Grant Timmerman grant

Block or report user

Report or block grant

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@grant
grant / package.json
Created Aug 3, 2019
Run Node 12 package.json
View package.json
{
"name": "ffnode12",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "functions-framework"
},
"dependencies": {
"@google-cloud/functions-framework": "^1.2.1"
}
@grant
grant / Dockerfile
Created Aug 3, 2019
Run Node 12 Dockerfile
View Dockerfile
# Use the official Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
@grant
grant / index.js
Last active Jul 20, 2019
GCF Debugging VSC List Google APIs
View index.js
const {google} = require('googleapis');
/**
* Returns a list of Google APIs and their descriptions.
* @param {Express.Request} req The API request.
* @param {Express.Response} res The API response.
*/
exports.listGoogleAPIs = async (req, res) => {
// Call the API
const apis = await google.discovery('v1').apis.list();
// Build the response
@grant
grant / settings.json
Created Jul 20, 2019
GCF Debugging VSC settings.json
View settings.json
{
"debug.node.autoAttach": "on"
}
@grant
grant / launch.json
Created Jul 20, 2019
GCF Debugging VSC launch.json
View launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
}
]
@grant
grant / index.js
Last active Jul 22, 2019
GCF Debugging Index
View index.js
/**
* Returns a list of Google APIs and the link to the API's docs.
* @param {Express.Request} req The API request.
* @param {Express.Response} res The API response.
*/
exports.listGoogleAPIs = async (req, res) => {
let sum = 0;
for (let i = 0; i < 10; ++i) {
sum += i;
}
@grant
grant / btc_sheets.js
Last active Apr 12, 2019
BTC API – GCF + Apps Script
View btc_sheets.js
/**
* Get's the bitcoin price at a date.
*
* @param {string} date The date in yyyy-MM-dd format. Defaults to today.
* @return The value of BTC in USD at the date. From Coinbase's API
* @customfunction
*/
function BTC_CF(date) {
var dateString = Utilities.formatDate(new Date(date), "GMT", "yyyy-MM-dd");
var res = UrlFetchApp.fetch("https://us-central1-new-project-as-test.cloudfunctions.net/btc?date=" + dateString);
@grant
grant / btc.js
Created Apr 12, 2019
BTC API – GCF
View btc.js
const rp = require('request-promise');
const DEFAULT_DATE = '2019-04-10';
exports.btc = async (req, res) => {
const date = req.query.date || DEFAULT_DATE;
async function getBTC(date) {
const res = await rp(`https://api.coinbase.com/v2/prices/BTC-USD/spot?date=${date}`, {
headers: {
'CB-VERSION': '2016-10-10',
Authorization: `Bearer ${process.env.COINBASE_TOKEN}`
View index.js
// server
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
// client
var b = fetch('https://us-central1-{project}.cloudfunctions.net/{method}').then((response) => {
const a = response.json().then(c => {console.log(c)});
})
View index.js
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
exports.helloWorld = (req, res) => {
let message = req.query.message || req.body.message || 'Hello World!';
res.status(200)
.set('Content-Type', 'text/html')
You can’t perform that action at this time.