Skip to content

Instantly share code, notes, and snippets.

Avatar

Grant Timmerman grant

View GitHub Profile
@grant
grant / index.js
Created Nov 12, 2020
Critterwatch Vision
View index.js
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 Aug 1, 2020
Sheets as a Service – Basic Script
View index.js
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 Aug 5, 2020
Sheets as a Service – Basic Package
View package.json
{
"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 Jul 26, 2020
R Functions Framework Local Install
View install_locally.sh
# 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 Jul 26, 2020
R Functions Framework Deploy
View deploy.sh
# 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 Jul 27, 2020
R Functions Framework Dockerfile
View 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 Aug 1, 2020
Create a Service Account
View sa.sh
# 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 \
View swift_version.sh
> 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 Jun 29, 2020
Vapor Cloud Run
View run.sh
# 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
View routes.swift
import Vapor
func routes(_ app: Application) throws {
app.get { req in
return "It works!"
}
app.get("hello") { req -> String in
return "Hello, world!"
}
You can’t perform that action at this time.