Skip to content

Instantly share code, notes, and snippets.

View grant's full-sized avatar
Coding daily!

Grant Timmerman grant

Coding daily!
View GitHub Profile
@grant
grant / output.json
Last active January 28, 2020 06:39
Hello Cloud Pub/Sub Output
{
"message": {
"attributes": { "greeting": "Hello from the Cloud Pub/Sub Emulator!" },
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
@grant
grant / test.sh
Last active February 3, 2020 05:40
Hello Cloud Pub/Sub Test
curl -d "@mockPubsub.json" \
-X POST \
-H "Content-Type: application/json" \
http://localhost:8080
@grant
grant / mockPubsub.json
Created January 27, 2020 11:03
Hello Cloud Pub/Sub JSON
{
"message": {
"attributes": {
"greeting": "Hello from the Cloud Pub/Sub Emulator!"
},
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
@grant
grant / helloPubSub.js
Last active December 8, 2022 12:56
Hello Cloud Pub/Sub
/**
* Background Cloud Function to be triggered by Pub/Sub.
* This function is exported by index.js, and executed when
* the trigger topic receives a message.
*
* @param {object} data The event payload.
* @param {object} context The event metadata.
*/
exports.helloPubSub = (data, context) => {
const pubSubMessage = context;
@grant
grant / Dockerfile
Last active January 15, 2020 09:59
PHP Dockerfile
FROM gcr.io/gae-runtimes/php73:php73_20191020_7_3_10_RC00
WORKDIR /srv/
# NOTE: The entrypoint "/start", which starts up NGINX and PHP-FPM,
# is configured by creating a `.googleconfig/app_start.json` file with the
# contents:
#
# {"entrypointContents": "CUSTOM_ENTRYPOINT"}
#
@grant
grant / composer.json
Created January 15, 2020 02:36
PHP HTTP Function Composer
{
"require": {
"google/cloud-functions-framework": "^0.1.0"
}
}
@grant
grant / index.php
Last active January 15, 2020 03:29
PHP HTTP Function
<?php
use Symfony\Component\HttpFoundation\Request;
function helloHttp(Request $request)
{
return sprintf("Hello %s from PHP HTTP function!" . PHP_EOL,
$request->query->get('name') ?: 'World'
);
}
@grant
grant / index.js
Created January 9, 2020 15:37
Cloud Run Storage – Cloud SQL
const mysql = require('promise-mysql');
// Create a pooled connection to MySQL
let pool;
const createPool = async () => {
pool = await mysql.createPool({
user: process.env.DB_USER, // e.g. 'my-db-user'
password: process.env.DB_PASS, // e.g. 'my-db-password'
database: process.env.DB_NAME, // e.g. 'my-database'
// If connecting via unix domain socket, specify the path
@grant
grant / index.js
Last active January 9, 2020 15:23
Cloud Run Storage – Firestore
// Create a Firebase client
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault()
});
const db = admin.firestore();
async function uploadDoc(req, res) {
// Create a reference to the shoes doc.
let shoesDoc = db.collection('products').doc('shoes');
@grant
grant / index.js
Created January 9, 2020 15:09
Cloud Run Storage – Cloud Storage
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
async function uploadFile(req, res) {
// Uploads a local file to the bucket
await storage.bucket(res.query.bucket).upload(req.query.filename, {
// Support for HTTP requests made with `Accept-Encoding: gzip`