Skip to content

Instantly share code, notes, and snippets.

@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);
@saggie
saggie / run_python_via_docker.sh
Last active April 6, 2022 05:11
Run Python via Docker
docker run -itd --rm --name my-python --volume $PWD:/opt/work python:3 /bin/sh
docker exec -it my-python bash
cd /opt/work
python your_script.py
@saggie
saggie / Verify_Cognito_JWT_in_Ktor.md
Created August 22, 2021 06:18
Verify Amazon Cognito JWT in Ktor

(In Ktor: 1.6.2)

  • application.conf

    ...
    jwt {
        issuer = "https://cognito-idp.ap-northeast-1.amazonaws.com/__SPECIFY_POOL_ID_HERE__"
        audience = "__SPECIFY_CLIENT_ID_HERE__"
        realm = "ktor sample app"
    
@saggie
saggie / Dockerfile
Created June 8, 2021 12:02
Install AWS CLI v2 in Dockerfile
FROM ubuntu:20.04
# Installing dependent libraries...
RUN apt-get update && \
apt-get install -y \
curl \
unzip
# Installing AWS CLI v2...
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
@saggie
saggie / Run pgAdmin 4 via Docker.sh
Last active April 19, 2021 06:30
Run pgAdmin 4 via Docker
docker run --rm -p 10080:80 -e [email protected] -e PGADMIN_DEFAULT_PASSWORD=pgadmin dpage/pgadmin4
@saggie
saggie / cURL via Docker.sh
Last active April 10, 2021 09:26
cURL via Docker
docker run --rm alpine ash -c "apk add curl && curl https://example.com"
@saggie
saggie / ListSplitter.kt
Created January 25, 2021 04:58
Kotlin: Split `List<T>` into `List<List<T>>` by `size`
class ListSplitter {
companion object {
fun <T> split(list: List<T>, size: Int): List<List<T>> {
val result: MutableList<List<T>> = mutableListOf()
var i = 0
while (i < list.size) {
result.add(list.subList(i, (i + size).coerceAtMost(list.size)))
i += size
}
return result
@saggie
saggie / index.js
Created December 17, 2020 07:05
特定の EC2 Instance を起動あるいは停止させる Lambda 関数 (Node.js 12.x)
/*
* 特定の EC2 Instance を起動あるいは停止させる関数
*/
const params = {
// 対象のEC2インスタンスIDのリスト
InstanceIds: [
'i-00000000000000000',
]
};
@saggie
saggie / notify_codecommit_events_to_teams.py
Last active May 17, 2020 06:00
Notify all generic events on CodeCommit to Teams Webhook
import json
import urllib.request
teams_endpoint = "https://outlook.office.com/webhook/.../IncomingWebhook/..."
def build_text(message, detail):
body = json.dumps(detail, indent=2)
text = []
@saggie
saggie / notify_codecommit_comment_to_teams.py
Created May 17, 2020 04:53
Notify a comment on AWS CodeCommit to Teams Webhook
import json
import urllib.request
teams_endpoint = "https://outlook.office.com/webhook/.../IncomingWebhook/..."
def build_text(detail, attr):
def get_username_from_arn(arn):
return arn.split(":")[-1]