Skip to content

Instantly share code, notes, and snippets.

View michimani's full-sized avatar
🍛
I love curry.

Yoshihiro Ito michimani

🍛
I love curry.
View GitHub Profile
@michimani
michimani / main.go
Created February 19, 2021 15:11
This is a script using the AWS SDK for Go V2 and Go 1.16. Measure the time it takes to launch AWS Fargate for ECS.
package main
import (
"context"
_ "embed"
"encoding/json"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
@michimani
michimani / issue-acm-certificate.sh
Last active November 15, 2023 09:15
This is a shell script for issuing SSL certificates with ACM (Amazon Certificate Manager).
#!/bin/bash
set -e
if [ $# != 3 ] || [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
echo -e "Three parameters are required
1st - string: Hosted Domain Name on Route 53 (e.g. example.com)
2nd - string: Domain Name for Certificate (e.g. sub.mexample.com)
3rd - string: Target Region (e.g. us-east-1)
example command
@michimani
michimani / organize_mac_screen_captures.py
Last active June 22, 2023 02:07
This script organizes screen captures taken by Mac into monthly or daily directories. It is assumed to be executed by Automator app.
import glob
import os
import re
from typing import Final
HOME_DIR: Final[str] = "/Users/hoge" # change to your home directory
FILE_TYPE: Final[str] = "jpg" # or "png"
NEW_FILE_PATTERN: Final = r".*(\d{4})-(\d{2})-(\d{2})_\d{5,6}([^\/]+)?\." + FILE_TYPE
SC_DIR: Final = f"{HOME_DIR}/Pictures/__ss_tmp"
SC_OUT_DIR: Final = f"{HOME_DIR}/Pictures/000_ScreenShot"
@michimani
michimani / CodeBuiildNotificationToSlack.py
Last active December 15, 2022 13:32
This is a sample of AWS Lambda function that notifies CodeBuild Notification (only state changes) to Slack via Amazon SNS.
import json
import traceback
from datetime import datetime, timezone, timedelta
from urllib.request import Request, urlopen
SLACK_WEBHOOK_URL = '<your-slack-incomming-webhook-url>'
SLACK_CHANNEL = '<your-slack-channel>'
TEST_EVENT_FILE = './sample__CodeBuild.json'
@michimani
michimani / generate_api_key.sh
Created February 17, 2020 12:35
Shell script that generate API key of Amazon API Gateway
#!/bin/bash
if [ $# != 2 ] || [ $1 = "" ] || [ $2 = "" ]; then
echo "Two parameters are required"
echo ""
echo "1st : string for API Key name (ex. user1)"
echo "2nd : string for Usage Plan ID (ex. abc123)"
echo ""
echo "example command"
echo "\t$ sh ./generate_api_key.sh user1 abc123"
@michimani
michimani / delete_messages.py
Last active April 18, 2022 07:56
Delete old slack messages at a specific channel.
"""Delete old Slack messages at specific channel."""
from datetime import datetime
from time import sleep
import json
import re
import sys
import urllib.parse
import urllib.request
DELETE_URL = "https://slack.com/api/chat.delete"
@michimani
michimani / count-github-stargazers.py
Last active January 2, 2022 13:33
Count GitHub stargazers. Execute `python3 count-github-stargazers.py github_user_name` . ⚠️tested with only Python 3.7.5
from time import sleep
from urllib.request import Request, urlopen
import argparse
import json
import traceback
GITHUB_REPOS_API = 'https://api.github.com/users/{user_name}/repos?per_page=100&page={page}'
PRINT_LINE = '{repo_name: <40}:{star_cnt: >6}'
p = argparse.ArgumentParser()
@michimani
michimani / api-usage-plan.yml
Created February 17, 2020 12:33
A CloudFormation template for creating API Gateway usage plan.
AWSTemplateFormatVersion: "2010-09-09"
Description: "API Gateway - usage plan template."
Parameters:
TargetApiId:
Type: String
Resources:
UsagePlan:
Type: "AWS::ApiGateway::UsagePlan"
@michimani
michimani / main.js
Last active July 16, 2021 13:41
This is a bookmarklet shows only images in a modelpress page, for example https://mdpr.jp/photo/detail/8869191.
function () {
const _d = document;
const imgElemList = _d.querySelectorAll('ol.pg-photo__webImageList a img');
if (imgElemList.length == 0) {
alert('Images not found.');
return;
}
imgElemList.forEach((e, i) => {
let imgSrc = e.getAttribute('src');
imgSrc = imgSrc.slice(0, imgSrc.indexOf('?'));
@michimani
michimani / cf2_for_hugo.js
Created May 6, 2021 22:10
Optimizing request URI for CloudFront with CloudFront Functions (CF2) that has HUGO site that deployed to a S3 bucket as origin.
function handler(event) {
var host = '<REPLARE_TO_YOUR_HOST>'; // e.g. https://michimani.net
var request = event.request;
var requestUri = request.uri;
// do not anything when requesting to top page
if (requestUri == '' || requestUri == '/') {
return request;
}