Skip to content

Instantly share code, notes, and snippets.

View ohsawa0515's full-sized avatar

Shuichi Ohsawa ohsawa0515

View GitHub Profile
@ohsawa0515
ohsawa0515 / GoogleGroup.js
Last active December 4, 2022 07:57
Cloud Identity APIでGoogleグループのメンバーリストの取得、メンバー追加・削除をするGoogle Apps Script
/**
* ユーザーリストを返す
* @param {string} groupEmail - グループのEmail
* @return {string[]} - ユーザーEmailのリスト
*/
function listMembers(groupEmail) {
let memberships = listMemberships(groupEmail);
var members = [];
for (const membership of memberships) {
// ロールがオブジェクトかつ配列になっているので「,」でジョインした文字列にする
import boto3
from botocore.exceptions import ClientError
import datetime
import time
import os
from dateutil.relativedelta import relativedelta
athena_query_wait_time = 3
@ohsawa0515
ohsawa0515 / setup.sh
Last active February 7, 2020 06:34
Setup scirpt for Redash with Docker on Mac OS
#!/usr/bin/env bash
# This script setups dockerized Redash on Mac OS.
set -eu
REDASH_BASE_PATH=/opt/redash
create_directories() {
sudo mkdir -p $REDASH_BASE_PATH/postgres-data
sudo chown -R $USER $REDASH_BASE_PATH
}
@ohsawa0515
ohsawa0515 / calc_aurora_backup_storage_cost.sh
Last active November 29, 2019 02:05
Calculate Aurora backup storage cost
#!/bin/bash -eu
# Tokyo region
price=0.023
region='ap-northeast-1'
aws_accound_id=$(aws sts get-caller-identity --query 'Account' --output text)
echo "aws_accound_id,aurora_cluster,total_bk_storage,days,avg_bk_storage_per_month,avg_bk_storage_per_month_gb,cost_bk_storage"
@ohsawa0515
ohsawa0515 / gce_preemptible_safety_shutdown_script.ps1
Last active October 28, 2019 10:31
Safely shutdown a preemptible GCE instance (Powershell)
$instanceName = Invoke-RestMethod -Headers @{ 'Metadata-Flavor' = 'Google' } -Uri "http://metadata.google.internal/computeMetadata/v1/instance/name"
$zoneInfo = Invoke-RestMethod -Headers @{ 'Metadata-Flavor' = 'Google' } -Uri "http://metadata.google.internal/computeMetadata/v1/instance/zone"
$zone = $zoneInfo.Split("/")[-1]
$region = $zone.Substring(0, $zone.Length-2)
$createdBy = gcloud compute instances describe $instanceName --zone $zone --format "value[](metadata.items.created-by)"
$instanceGroup = $createdBy.Split("/")[-1]
$preempted = Invoke-RestMethod -Headers @{ 'Metadata-Flavor' = 'Google' } -Uri "http://metadata.google.internal/computeMetadata/v1/instance/preempted"
try {
if ($preempted -eq "TRUE") {
@ohsawa0515
ohsawa0515 / gce_preemptible_safety_shutdown_script.sh
Last active October 28, 2019 10:27
Safely shutdown a preemptible GCE instance (Bash)
#!/bin/bash
set -u
export PATH="/usr/local/bin:/sbin:/usr/sbin:$PATH"
instance_name=$(curl -sSfL -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/name)
zone_info=$(curl -sSfL -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/zone)
zone=${zone_info##*/}
region=${zone:0:-2}
@ohsawa0515
ohsawa0515 / list_all_host_google_repositories.sh
Created July 5, 2019 07:50
List container images that exist on all hosts.
#!/bin/bash
project=$1
hosts=("gcr.io" "us.gcr.io" "eu.gcr.io" "asia.gcr.io")
for host in ${hosts[@]}; do
gcloud container images list --repository=$host/$project --format json | jq -r ".[].name"
done
@ohsawa0515
ohsawa0515 / logging_athena_history.py
Last active December 30, 2021 10:55
Lambda function to upload Amazon Athena's history to S3.
# coding:utf-8
from __future__ import print_function
import os, boto3, datetime, csv
s3 = boto3.resource('s3')
athena_client = boto3.client('athena')
today = datetime.datetime.today().strftime("%Y%m%d")
s3_bucket = os.environ.get('S3_BUCKET')
max_items = 50
@ohsawa0515
ohsawa0515 / Gemfile
Last active May 24, 2018 02:47 — forked from mirakui/Gemfile
AWS S3 read/write Benchmark
source :gemcutter
gem 'aws-sdk', '~> 2'
START RequestId: 5ee997c9-e338-11e7-bc6e-832244fddbfd Version: $LATEST
time="Dec 17 14:41:32" level=info msg="Validating config..."
time="Dec 17 14:41:32" level=info msg="Detecting Server/Container OS... "
time="Dec 17 14:41:32" level=info msg="Detecting OS of servers... "
time="Dec 17 14:41:32" level=info msg="(1/1) Detected: web001: amazon 2015.09"
time="Dec 17 14:41:32" level=info msg="Detecting OS of containers... "
time="Dec 17 14:41:32" level=info msg="Checking dependencies..."
time="Dec 17 14:41:32" level=info msg="Dependencies ... Pass"
time="Dec 17 14:41:32" level=info msg="Checking sudo settings..."