Skip to content

Instantly share code, notes, and snippets.

View apstndb's full-sized avatar

apstndb

View GitHub Profile
CREATE TEMP FUNCTION typeof_literal(input STRING)
AS (
CASE
-- Process NUMERIC, DATE, DATETIME, TIME, TIMESTAMP,
WHEN REGEXP_CONTAINS(input, r'^[A-Z]+ "') THEN REGEXP_EXTRACT(input, r'^([A-Z]+) "')
WHEN REGEXP_CONTAINS(input, r'^-?[0-9]*$') THEN 'INT64'
WHEN REGEXP_CONTAINS(input, r'^(-?[0-9]+[.e].*|CAST\("([^"]*)" AS FLOAT64\))$') THEN 'FLOAT64'
WHEN input IN ('true', 'false') THEN 'BOOL'
WHEN input LIKE '"%' THEN 'STRING'
WHEN input LIKE 'b"%' THEN 'BYTES'

Start Cloud Spanner Emulator

gcloud beta emulators spanner start

Setup database(not idempotent and error prone)

SPANNER_EMULATOR_HOST_REST=localhost:9020
@apstndb
apstndb / SpannerFKBackingIndex.md
Last active February 13, 2023 13:58
Backing indexes of Cloud Spanner Foreign Keys
@apstndb
apstndb / git-deb.sh
Last active March 2, 2020 02:13
Create google-cloud-sdk repo from apt
curl -s https://packages.cloud.google.com/apt/dists/cloud-sdk/main/binary-amd64/Packages |
gojq -srR 'def ver: split("-")[0];
split("\n\n") |
map(gsub("\n "; " ") |
split("\n") |
map(capture("^(?<key>[A-Z][a-zA-Z-]*): (?<value>.*)$"; "")) |
from_entries) |
group_by(.Package) |
map({key: .[0].Package, value: (sort_by(.Version))}) |
from_entries |
package main
import (
"context"
"flag"
"cloud.google.com/go/datastore"
"github.com/k0kubun/pp"
"log"

Follow official gRPC example https://knative.dev/docs/serving/samples/grpc-ping-go/

GCP_PROJECT="your-own-project"

git clone -b "release-0.9" https://github.com/knative/docs knative-docs
cd knative-docs/docs/serving/samples/grpc-ping-go
gcloud builds submit --tag "gcr.io/${GCP_PROJECT}/grpc-ping-go"
gcloud beta run deploy --image=gcr.io/${GCP_PROJECT}/grpc-ping-go --allow-unauthenticated --platform=managed --region=asia-northeast1 grpc-ping
@apstndb
apstndb / 0service-to-service-auth.md
Last active June 17, 2019 04:37
Cloud Run service-to-service auth example

setting

$ gcloud iam service-accounts create callee
$ gcloud iam service-accounts create caller
$ gcloud builds submit -t gcr.io/${PROJECT_ID}/oidctest .
$ gcloud beta run deploy --image=gcr.io/${PROJECT_ID}/oidctest --allow-unauthenticated \
    --service-account=caller@${PROJECT_ID}.iam.gserviceaccount.com caller 
$ gcloud beta run deploy --image=gcr.io/${PROJECT_ID}/oidctest --no-allow-unauthenticated \
    --service-account=callee@{PROJECT_ID}.iam.gserviceaccount.com callee
@apstndb
apstndb / Copy with hl=en.js
Last active June 6, 2019 17:02
Copy URL with hl=en for Google Cloud docs
javascript:
var global = window;
global.COPY_TO_CLIPBOARD = global.COPY_TO_CLIPBOARD || {};
global.COPY_TO_CLIPBOARD.getUrl = function () {
let url = new URL(location.href);
url.searchParams.set("hl", "en");
return url.href;
};