Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const request = require("request"); | |
| // Main function called by Cloud Functions trigger. | |
| module.exports.updateCloudRunServices = (event, callback) => { | |
| const build = eventToBuild(event.data); | |
| // Check if push is to Dashboard source Code repo and if Cloud Build is successful | |
| if (build.hasOwnProperty("source")) { | |
| if ( | |
| build.source.repoSource.repoName === "dashboard" && |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def manipulate(obj_arr): | |
| all_locations = [] | |
| result = [] | |
| for obj in obj_arr: | |
| all_locations += obj['locations'] | |
| for location in all_locations: | |
| location_products = {'location': location, 'associated_products': []} | |
| for obj in obj_arr: | |
| if location in obj['locations']: | |
| location_products['associated_products'].append(obj['product']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const IncomingWebhook = require('@slack/webhook').IncomingWebhook; | |
| const url = "https://hooks.slack.com/services/XYZ"; | |
| const webhook = new IncomingWebhook(url); | |
| // Send the notification - Gets callled by Cloud Scheduler | |
| module.exports.sendToSlack = () => { | |
| (async () => { | |
| await webhook.send({ | |
| icon_emoji: ':male-police-officer:', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime, timezone | |
| datetime.now(timezone.utc).isoformat()[:-9] + 'Z' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| steps: | |
| # build the container image | |
| - name: 'gcr.io/cloud-builders/docker' | |
| args: ['build', '-t', 'gcr.io/projectz-239507/app', '.'] | |
| # push the container image to Container Registry | |
| - name: 'gcr.io/cloud-builders/docker' | |
| args: ['push', 'gcr.io/projectz-239507/app'] | |
| # create database | |
| - name: 'gcr.io/cloud-builders/gcloud' | |
| args: ['sql', 'databases', 'create', 'mydb', '--instance', 'ddd'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| steps: | |
| # build the container image | |
| - name: 'gcr.io/cloud-builders/docker' | |
| args: ['build', '-t', 'gcr.io/projectz-239507/app', '.'] | |
| # push the container image to Container Registry | |
| - name: 'gcr.io/cloud-builders/docker' | |
| args: ['push', 'gcr.io/projectz-239507/app'] | |
| # Deploy container image to Cloud Run | |
| - name: 'gcr.io/cloud-builders/gcloud' | |
| args: ['beta', 'run', 'deploy', 'app', '--image', 'gcr.io/projectz-239507/app', '--region', 'us-central1'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use the official Node.js 10 image. | |
| # https://hub.docker.com/_/node | |
| FROM node:10 | |
| # 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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.