Skip to content

Instantly share code, notes, and snippets.

View grant's full-sized avatar

Grant Timmerman grant

View GitHub Profile
export const MY_CONST = 'ESM';
@grant
grant / deploy-cloud-workflow.yaml
Last active May 18, 2021 16:27
A GitHub Workflow that deploys a Cloud Workflow
name: Deploy Cloud Workflow
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy Cloud Workflow
runs-on: ubuntu-18.04
steps:
@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"
@grant
grant / myFirstWorkflow.workflows.yaml
Created May 15, 2021 19:02
Cloud Workflow – myFirstWorkflow
- getCurrentTime:
call: http.get
args:
url: https://us-central1-workflowsample.cloudfunctions.net/datetime
result: currentTime
- readWikipedia:
call: http.get
args:
url: https://en.wikipedia.org/w/api.php
query:
@grant
grant / script.js
Last active May 11, 2021 02:26
gapi script
// 1. Load the JavaScript client library.
gapi.load('client', init);
async function init() {
// 2. Initialize the JavaScript client library.
await gapi.client.init({
discoveryDocs: ['https://discovery.googleapis.com/$discovery/rest']
});
start();
}
@grant
grant / index.html
Created September 2, 2019 21:37
gapi HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello, GAPI</title>
</head>
<body>
Hello, GAPI!
<script src="https://apis.google.com/js/api.js"></script>
</body>
</html>
@grant
grant / deploy.sh
Created May 4, 2021 17:19
Deploy gRPC to Cloud Run
# Get Cloud Run URL
ENDPOINT=$(\
gcloud run services list \
--project=${PROJECT} \
--region=${REGION} \
--platform=managed \
--format="value(status.address.url)" \
--filter="metadata.name=grpc-calculator")
ENDPOINT=${ENDPOINT#https://} && echo ${ENDPOINT}
@grant
grant / server.js
Created May 4, 2021 17:17
gRPC Server
function calculate(call, callback) {
const request = call.request;
let result;
if (request.operation === 'ADD') {
result = request.first_operand + request.second_operand;
} else {
result = request.first_operand - request.second_operand;
}
callback(null, {result});
}
@grant
grant / index.js
Created May 4, 2021 15:34
Listen to gRPC requests
function main() {
const server = new grpc.Server();
server.addService(calculatorProto.Calculator.service, {calculate});
server.bindAsync(`0.0.0.0:${PORT}`, grpc.ServerCredentials.createInsecure(), (error, port) => {
if (error) {
throw error;
}
server.start();
});
}
@grant
grant / calculator.proto
Created May 4, 2021 15:28
calculator.proto
enum Operation {
ADD = 0;
SUBTRACT = 1;
}
message BinaryOperation {
float first_operand = 1;
float second_operand = 2;
Operation operation = 3;
};
message CalculationResult {