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 / 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 / composer.json
Created Jan 15, 2020
PHP HTTP Function Composer
View composer.json
{
"require": {
"google/cloud-functions-framework": "^0.1.0"
}
}
@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 / 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`
@grant
grant / Dockerfile
Created Nov 19, 2019
YouTube API on Cloud Run Dockerfile
View Dockerfile
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
@grant
grant / deploy.sh
Created Nov 19, 2019
YouTube API on Cloud Run – Deploy Script
View deploy.sh
# !/bin/bash
# Set env var "GCP_PROJECT" to our project name
GCP_PROJECT=$(gcloud config list --format 'value(core.project)' 2>/dev/null)
# Set our Cloud Run region (so we aren't prompted)
gcloud config set run/region us-central1
# Build and upload your image in Google Container Registry
gcloud builds submit --tag gcr.io/$GCP_PROJECT/yt
# Deploy your container to Cloud Run
ENV=$(cat .env)
@grant
grant / app.py
Created Nov 19, 2019
YouTube API on Cloud Run
View app.py
import os
import argparse
from dotenv import load_dotenv
from flask import Flask, request
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
# Setup YouTube API
KEY = os.environ.get('KEY')
YOUTUBE_API_SERVICE_NAME = 'youtube'
@grant
grant / main.go
Last active Nov 6, 2019
Go Functions Framework – main
View main.go
package main
import (
"log"
"os"
"example.com/hello"
"github.com/GoogleCloudPlatform/functions-framework-go/framework"
)
You can’t perform that action at this time.