Skip to content

Instantly share code, notes, and snippets.

View sinmetal's full-sized avatar

sinmetal sinmetal

View GitHub Profile
@sinmetal
sinmetal / naturalLanguageAPIResponseSchema.json
Last active July 29, 2016 01:59
Cloud Natural Language APIのResponseをBigQueryに入れるためのschema
[{
"name": "entities",
"mode": "repeated",
"type": "record",
"fields": [{
"name": "mentions",
"mode": "repeated",
"type": "record",
"fields": [{
"name": "text",
package main
import (
"fmt"
"log"
"github.com/zabawaba99/firego"
)
func main() {
[
{
"name": "documentSentiment",
"type": "RECORD",
"fields": [
{
"name": "magnitude",
"type": "FLOAT",
"mode": "NULLABLE"
},
package cpt
import (
"google.golang.org/appengine"
"golang.org/x/net/context"
)
// IsProduction is Production環境で動いていればtrueを返す
func IsProduction(c context.Context) bool {
@sinmetal
sinmetal / ephemeral.sh
Last active May 21, 2018 03:42
適当にコマンドを実行し、自ら死ぬインスタンスを生成するstartup-script
#!/bin/bash
# Install google-fluentd
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sha256sum install-logging-agent.sh
sudo bash install-logging-agent.sh
# Restart google-fluentd
service google-fluentd restart
# Your Task
@sinmetal
sinmetal / dns-ch.sh
Created April 18, 2017 10:04
Cloud DNSのRecordを、動作しているCompute EngineのGlobal IP Addrに変更する。元ネタは http://stackoverflow.com/questions/34726498/how-to-update-google-cloud-dns-with-ephemeral-ip-for-an-instance
#!/bin/bash
ttlify() {
local i
for i in "$@"; do
[[ "${i}" =~ ^([0-9]+)([a-z]*)$ ]] || continue
local num="${BASH_REMATCH[1]}"
local unit="${BASH_REMATCH[2]}"
case "${unit}" in
weeks|week|wee|we|w) unit=''; num=$[num*60*60*24*7];;
@sinmetal
sinmetal / cron.yaml
Created July 12, 2017 01:43
DatastoreBackup Sample
cron:
- description: Daily Backup
url: /_ah/datastore_admin/backup.create?name=BackupToCloud&kind=Billing&kind=Project&filesystem=gs&gs_bucket_name=datastore-backup&queue=backup
schedule: every day 02:00
timezone: Asia/Tokyo
target: ah-builtin-python-bundle
- description: Billing Report to Slack
url: /cron/1/billing/ratio
schedule: every day 10:00
timezone: Asia/Tokyo
package main
import (
"fmt"
"log"
"net/http"
"cloud.google.com/go/compute/metadata"
)
@sinmetal
sinmetal / pubsub.request.md
Created September 13, 2017 10:41
Cloud PubSub Push Request Memo

App Engine StandardでCloud Pub/SubのPush Requestを受けた時のRequestの内容。 Headerに認証のTokenを入れるみたいなのはないっぽいので、やりたいなら、BodyのAttributesに適当にToken入れる感じだろうか。

Request Header

  • Content-Length = [284]
  • Accept-Charset = [UTF-8]
  • X-Appengine-Country = [ZZ]
  • X-Cloud-Trace-Context = [b637a4a25755adafd922090e3c844cee/379846021913007296]
  • Host = [sinmetal-pubsub.appspot.com]
{
"kind": "bigquery#job",
"etag": "\"Nffj8WcBg8Vy0jj5i2Ow4j6Mrcs/Z3XdJy-3ci8it9bJqScatGFAerI\"",
"id": "metal-tile-dev0:bquijob_57d01daf_15e853bceec",
"selfLink": "https://www.googleapis.com/bigquery/v2/projects/metal-tile-dev0/jobs/bquijob_57d01daf_15e853bceec",
"jobReference": {
"projectId": "metal-tile-dev0",
"jobId": "bquijob_57d01daf_15e853bceec"
},
"configuration": {