Skip to content

Instantly share code, notes, and snippets.

Grant Timmerman grant

Block or report user

Report or block grant

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@grant
grant / test.sh
Last active Feb 3, 2020
Hello Cloud Pub/Sub Test
View test.sh
curl -d "@mockPubsub.json" \
-X POST \
-H "Content-Type: application/json" \
http://localhost:8080
@grant
grant / output.json
Last active Jan 28, 2020
Hello Cloud Pub/Sub Output
View output.json
{
"message": {
"attributes": { "greeting": "Hello from the Cloud Pub/Sub Emulator!" },
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
@grant
grant / mockPubsub.json
Created Jan 27, 2020
Hello Cloud Pub/Sub JSON
View mockPubsub.json
{
"message": {
"attributes": {
"greeting": "Hello from the Cloud Pub/Sub Emulator!"
},
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
@grant
grant / helloPubSub.js
Created Jan 27, 2020
Hello Cloud Pub/Sub
View helloPubSub.js
/**
* 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 = data;
@grant
grant / Dockerfile
Last active Jan 15, 2020
PHP Dockerfile
View 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 / index.php
Last active Jan 15, 2020
PHP HTTP Function
View index.php
<?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 / composer.json
Created Jan 15, 2020
PHP HTTP Function Composer
View composer.json
{
"require": {
"google/cloud-functions-framework": "^0.1.0"
}
}
@grant
grant / index.js
Created Jan 9, 2020
Cloud Run Storage – Cloud SQL
View index.js
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 Jan 9, 2020
Cloud Run Storage – Firestore
View index.js
// 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 Jan 9, 2020
Cloud Run Storage – Cloud Storage
View index.js
// 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`
You can’t perform that action at this time.