Skip to content

Instantly share code, notes, and snippets.

View browny's full-sized avatar
👨‍💻

Browny Lin browny

👨‍💻
View GitHub Profile
# install parallel first (sudo apt-get install -y parallel)
JOB_NUM=10
NAME_FILTER='*'
# stop instances
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/RUNNING/ {printf "gcloud -q compute instances stop %s --zone %s;\n", $1, $2 > "stop-instances.txt" }'
parallel --jobs $JOB_NUM < stop-instances.txt
# remove delete protection
@browny
browny / PubSub101.md
Created February 12, 2020 20:14
Labs of PubSub101

Lab1. Publish Streaming Data into Pub/Sub

  1. Preparation
gcloud compute instances create training-vm \
  --zone=asia-east1-b --machine-type=n1-standard-1 \
  --metadata=startup-script-url=gs://cloud-training/initscripts/init-script-sdp-1.sh \
  --scopes=https://www.googleapis.com/auth/cloud-platform \
 --image-family=debian-9 --image-project=debian-cloud
@browny
browny / web-server.py
Created December 9, 2019 03:35
web-server.py
import tornado.ioloop
import tornado.web
import socket
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hostname: " + socket.gethostname())
def make_app():
return tornado.web.Application([
@browny
browny / GKE101-Lab.md
Last active August 12, 2019 06:40
Labs of GKE101

Lab1

Introduction to Containers and Docker

Run the web server manually

# Provision a ubuntu VM
gcloud compute --project=infra101 instances create vm-based \
# Configuration for Alacritty, the GPU enhanced terminal emulator.
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty itself.
#env:
# TERM variable
#
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
#!/bin/bash
# Usage:
# sh etcd-cluster.sh <instance_name>
INSTANCE_NAME=$1
REGISTRY=quay.io/coreos/etcd
# available from v3.2.5
REGISTRY=gcr.io/etcd-development/etcd
@browny
browny / main.go
Created October 28, 2018 11:25
Dialogflow webhook sample code
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
owm "github.com/briandowns/openweathermap"
@browny
browny / vegeta.sh
Last active October 3, 2021 16:29
Run distributed load testing based on GCP and vegeta
#!/bin/bash
# Usage: bash vegeta.sh <rate> <duration>
ACTION="GET http://google.com"
DURATION=${2:-5s}
RATE=${1:-10}
SLAVE_INSTANCES=$(gcloud compute instances list | grep vegeta- | awk '{print $1}')
SSH_ARGS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
# --- run cmd on all slave instances in parallel ---
type MyLogger struct{}
func (m *MyLogger) Log(format string, v ...interface{}) {
log.Printf(format, v...)
}
type Master struct {
Logger `inject:"logger"`
Food `inject:"example.Master.Food"`
Transport `inject:"example.Master.Transport"`
func (s *InjectTestSuite) TestWeave() {
driver := example.Driver{}
farmer := example.Farmer{}
master := example.Master{}
myLogger := example.MyLogger{}
tillageMachine := example.TillageMachine{}
depMap := map[interface{}][]string{
&myLogger: []string{
"logger",