Skip to content

Instantly share code, notes, and snippets.

@saggie
saggie / get_a_list_of_pull_request_comments.js
Created July 19, 2023 20:07
Get a list of pull request comments
import { Octokit } from "@octokit/rest"; // Required: `npm install @octokit/rest --save`
const octokit = new Octokit({
auth: "github_pat_xxxxx", // Specify your personal access token here
});
const response = await octokit.request(
"GET /repos/__OWNER__/__REPO__/pulls/comments",
{
owner: "__OWNER__",
@saggie
saggie / get_monthly_gcp_costs_for_fy2023_by_project_in_bigquery.py
Created July 2, 2023 14:29
Get monthly GCP costs for FY2023 by project in BigQuery
import pandas as pd
# Query of BigQuery
bq_query = """
SELECT
project.id
, SUM(COALESCE((SELECT SUM(x.amount) FROM UNNEST(credits) x), 0) + cost) as cost
, SUM(cost) as raw_cost
, SUM(COALESCE((SELECT SUM(x.amount) FROM UNNEST(credits) x), 0)) AS credits_amount
FROM
@saggie
saggie / put_a_csv_file_to_s3_with_python.py
Last active July 2, 2023 14:30
Put a CSV file to S3 with Python
import boto3
# 定数
s3_bucket_name = "__BUCKET_NAME__"
s3_object_key = "__FILE_NAME__.csv"
aws_access_key_id = "XXXXXXXXXXXXXXXXXXXX"
aws_secret_access_key = "XXXXXXXXXXXXXXXXXXXX"
# AWS/S3準備
aws_session = boto3.session.Session(
@saggie
saggie / sending_an_email_with_python.py
Last active December 7, 2022 02:08
Sending an email with Python
import smtplib
from email.message import EmailMessage
textfile = 'textfile'
with open(textfile) as fp:
msg = EmailMessage()
msg.set_content(fp.read())
msg['Subject'] = f'The contents of {textfile}'
@saggie
saggie / Running_a_NFS_Server_using_Docker.md
Last active November 12, 2022 01:14
Running a NFS Server using Docker

Running a NFS Server using Docker

Dockerで検証用のNFSサーバをさくっと起動する方法

Server side

Preparation

$ mkdir -p /opt/nfs
$ echo 'Hello!' > /opt/nfs/hello.txt
@saggie
saggie / installing_goenv_on_macos.md
Created November 8, 2022 10:08
Installing goenv on macOS

Install goenv via brew

$ brew install goenv
...
$ goenv --version
goenv 2.0.2

Edit .bashrc

@saggie
saggie / pass_by_value_vs_pass_by_reference.go
Created October 21, 2022 02:51
Go言語の値渡しと参照渡し
func main() {
someValue := 1111
// 値渡し
passAsValue(someValue)
fmt.Println(someValue) // 1111 (変わらない)
// 参照渡し
passAsReference(&someValue)
fmt.Println(someValue) // 2222 (変わった!)
@saggie
saggie / Run_AWS_CLI_via_Docker.md
Created September 21, 2022 04:48
Run AWS CLI via Docker
$ docker pull amazon/aws-cli:2.7.33

$ alias aws_2.7='docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli:2.7.33'

$ aws_2.7 --version
@saggie
saggie / run_and_login_to_an_ubuntu_container.sh
Last active November 12, 2022 01:12
Run and Login to an Ubuntu Container
# For Linux/macOS
docker run -it --rm --volume $PWD:/opt/pwd ubuntu:latest /bin/bash
# For Windows (PowerShell)
docker run -it --rm --volume ${PWD}:/opt/pwd ubuntu:latest /bin/bash
# To be anable to cURL
apt-get update && apt-get install -y curl
# To be anable to ssh
apt-get update && apt-get install -y openssh-server
@saggie
saggie / index.js
Created April 18, 2022 13:01
Posting a budget alert of Google Cloud Platform to Slack using Cloud Functions
const axios = require('axios');
const slackUrl = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX';
exports.notifyBudgetAlert = (event, context) => {
if (event.data) {
const data = JSON.parse(Buffer.from(event.data, 'base64').toString());
if (data.costAmount === 0) {
console.log('Skipped the process because the cost amount is zero. Budget name: ' + data.budgetDisplayName);