Skip to content

Instantly share code, notes, and snippets.

View grant's full-sized avatar

Grant Timmerman grant

View GitHub Profile
@grant
grant / package.json
Last active January 28, 2021 06:32
run-workflow-function package.json
{
"name": "run-workflow-function",
"main": "index.js",
"scripts": {
"start": "functions-framework --target=runWorkflow"
},
"dependencies": {
"@google-cloud/functions-framework": "^1.7.1",
"@google-cloud/workflows": "^1.1.0"
}
@grant
grant / index.js
Created November 12, 2020 04:29
Critterwatch Vision
const vision = require('@google-cloud/vision');
const visionClient = new vision.ImageAnnotatorClient();
const {Firestore} = require('@google-cloud/firestore');
const firestore = new Firestore();
const trackedAnimals = ['raccoon', 'alpaca', 'peacock', 'dog', 'gecko', 'squirrel', 'red panda'];
/**
* Triggered from a change to a Cloud Storage bucket.
@grant
grant / index.js
Last active August 1, 2020 02:45
Sheets as a Service – Basic Script
const path = require('path');
const {google} = require('googleapis');
const sheets = google.sheets('v4');
// TODO: Add your Sheet ID
// https://docs.google.com/spreadsheets/d/2L2LpYPyxJQTf14OLM6mVuiou88MsEi4Q-IUUxswNlfe/edit
const SPREADSHEET_ID = '2L2LpYPyxJQTf14OLM6mVuiou88MsEi4Q-IUUxswNlfe';
/**
* Appends row data to the Google Sheet
@grant
grant / package.json
Last active August 5, 2020 18:03
Sheets as a Service – Basic Package
{
"name": "sheets-on-run",
"main": "index.js",
"scripts": {
"start": "functions-framework --target=addRow"
},
"dependencies": {
"@google-cloud/functions-framework": "^1.6.0",
"googleapis": "^58.0.0"
}
@grant
grant / install_locally.sh
Created July 26, 2020 23:42
R Functions Framework Local Install
# Install devtools, specifying a CRAN mirror
install.packages("devtools", repos='http://cran.us.r-project.org')
# Import devtools
library(devtools)
# Install GitHub project
install_github("averikitsch/functions-framework-r/src/functionsframework")
@grant
grant / deploy.sh
Created July 26, 2020 23:36
R Functions Framework Deploy
# Set env var "GCP_PROJECT" to our project name
GCP_PROJECT=$(gcloud config list --format 'value(core.project)' 2>/dev/null)
# Build and upload your image in Google Container Registry
gcloud builds submit \
--tag gcr.io/$GCP_PROJECT/hellor \
--timeout="20m"
# Deploy your container to Cloud Run
gcloud run deploy hellor \
@grant
grant / Dockerfile
Last active July 27, 2020 00:43
R Functions Framework Dockerfile
# Use an R image.
# https://hub.docker.com/r/rocker/r-ver/
FROM rocker/r-ver:3.6.1
# Copy R package binary
COPY functionsframework_*.tgz /
# Install functions framework dependencies.
RUN R -e "install.packages('functionsframework_0.0.0.9000.tgz', repos = NULL, type = 'source')"
RUN R -e "install.packages(c('optparse', 'plumber'))"
@grant
grant / sa.sh
Last active August 1, 2020 02:01
Create a Service Account
# Get the current project
PROJECT=$(gcloud config get-value core/project 2> /dev/null)
# Create a service account (aka robot account)
gcloud iam service-accounts create sa-name \
--description="sa-description" \
--display-name="sa-display-name"
# Create and download credentials for the service account
gcloud iam service-accounts keys create creds.json \
@grant
grant / swift_version.sh
Created June 30, 2020 00:43
Swift Version
> swift --version
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.5.0
@grant
grant / run.sh
Created June 29, 2020 18:32
Vapor Cloud Run
# Set project to current project in gcloud
PROJECT=$(gcloud config list --format 'value(core.project)' 2>/dev/null)
# Build the container using Cloud Build, giving plenty of time for the `swift build` step
gcloud builds submit --tag gcr.io/$PROJECT/vapor --timeout="20m"
# Run the container
gcloud run deploy vapor --image gcr.io/$GCP_PROJECT/vapor --platform managed --allow-unauthenticated