Skip to content

Instantly share code, notes, and snippets.

View nownabe's full-sized avatar
💪
Yeah!!

Shogo Watanabe nownabe

💪
Yeah!!
View GitHub Profile
@nownabe
nownabe / result.sh
Created October 30, 2023 00:52
Which is faster
$ go test -bench .
goos: darwin
goarch: arm64
pkg: example.com/m
BenchmarkMiddleware-10 6388045 189.8 ns/op
BenchmarkList-10 5904484 205.4 ns/op
PASS
ok example.com/m 2.830s
@nownabe
nownabe / create_instance_and_database.rb
Created May 18, 2023 00:56
Setup Spanner Emulator
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "google-cloud-spanner"
end
require "google/cloud/spanner"
@nownabe
nownabe / main.py
Created May 15, 2023 07:51
SQL Generation by PaLM API
import io
import sys
from google.cloud import bigquery
from vertexai.preview.language_models import TextGenerationModel
client = bigquery.Client()
def render_prompt(full_table_id: str, user_prompt: str) -> str:
@nownabe
nownabe / database_cleaner.rb
Created November 4, 2022 07:43
DatabaseCleaner for Spanner
class MyDeletionStrategy < DatabaseCleaner::ActiveRecord::Deletion
def delete_tables(connection, table_names)
# TODO
end
def delete_table(connection, table_name)
connection.execute("DELETE FROM #{connection.quote_table_name(table_name)} WHERE true")
end
end
@nownabe
nownabe / index.js
Last active October 22, 2022 09:42
Tiny Hiragana encoding
/*
* Snippet to encode strings of Hiragana (Japanese alphabet) into a number value.
*
* This is written as an example for a Solidity application.
*/
const maxLength = 5;
/*
* 7 bit for each character.
@nownabe
nownabe / README.md
Created August 9, 2022 07:43
Quickstart: Pub/Sub BigQuery Subscription

Pub/Sub BigQuery Subscription の作り方

Pub/Sub BigQuery Subscription を利用する最小限の手順です。

Project 準備

利用するプロジェクトを設定してください。

gcloud config set project YOUR-PROJECT
@nownabe
nownabe / dlp_template.py
Last active July 12, 2022 05:35
Sample for DLP using templates
from os import environ
from google.cloud import dlp_v2 as dlp
client = dlp.DlpServiceClient()
def create_inspect_template(template_id: str):
"""
@nownabe
nownabe / hello-pod.yaml
Last active June 12, 2022 14:05
Sample Kubernetes Pod YAML for GKE Autopilot
apiVersion: v1
kind: Pod
metadata:
name: hello-gke
spec:
containers:
- name: hello
image: ghcr.io/shawnlabo/fun
resources:
requests:
@nownabe
nownabe / .bashrc
Last active May 30, 2022 01:28
Prettify Cloud Shell Prompt
PS1='\n'
PS1=$PS1'\[\e[1;33m\]$([[ -n $DEVSHELL_PROJECT_ID ]] && printf "\[\e[1;33m\]$DEVSHELL_PROJECT_ID" || printf "\[\e[1;37m\]cloudshell")\[\e[m\]'
PS1=$PS1':'
PS1=$PS1'\[\e[1;34m\]\w\n\[\e[1;35m\]❯\[\e[m\] '
PS1=$PS1'\[\033k$([[ -n $DEVSHELL_PROJECT_ID ]] && printf "($DEVSHELL_PROJECT_ID)" || printf "cloudshell")\033\\\]'
@nownabe
nownabe / execute_workflow.pyt
Last active September 5, 2024 22:15
Python Sample for executing Cloud Workflow
import json
from google.cloud.workflows_v1 import WorkflowsClient
from google.cloud.workflows.executions_v1 import ExecutionsClient
from google.cloud.workflows.executions_v1.types.executions import Execution
project = 'PROJECT ID'
location = 'REGION'
workflow = 'WORKFLOW NAME'