Skip to content

Instantly share code, notes, and snippets.

Avatar
🍛
I love curry.

Yoshihiro Ito michimani

🍛
I love curry.
View GitHub Profile
@michimani
michimani / generate_api_key.sh
Created Feb 17, 2020
Shell script that generate API key of Amazon API Gateway
View generate_api_key.sh
#!/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 Apr 18, 2022
Delete old slack messages at a specific channel.
View delete_messages.py
"""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 / CodeBuiildNotificationToSlack.py
Last active Mar 11, 2022
This is a sample of AWS Lambda function that notifies CodeBuild Notification (only state changes) to Slack via Amazon SNS.
View CodeBuiildNotificationToSlack.py
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 / count-github-stargazers.py
Last active Jan 2, 2022
Count GitHub stargazers. Execute `python3 count-github-stargazers.py github_user_name` . ⚠️tested with only Python 3.7.5
View count-github-stargazers.py
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 Feb 17, 2020
A CloudFormation template for creating API Gateway usage plan.
View api-usage-plan.yml
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 Jul 16, 2021
This is a bookmarklet shows only images in a modelpress page, for example https://mdpr.jp/photo/detail/8869191.
View main.js
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
Optimizing request URI for CloudFront with CloudFront Functions (CF2) that has HUGO site that deployed to a S3 bucket as origin.
View cf2_for_hugo.js
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;
}
@michimani
michimani / lambda_edge_hugo.js
Last active May 6, 2021
Optimizing request URI for CloudFront with Lambda@Edge that has HUGO site as origin.
View lambda_edge_hugo.js
'use strict';
exports.handler = (event, context, callback) => {
const host = '<REPLARE_TO_YOUR_HOST>'; // e.g. https://michimani.net
// Extract the request from the CloudFront event that is sent to Lambda@Edge
var request = event.Records[0].cf.request;
// Extract the URI from the request
var requestUri = request.uri;
@michimani
michimani / organize_mac_screen_captures.py
Last active Apr 2, 2021
This script organizes screen captures taken by Mac into monthly or daily directories. It is assumed to be executed by Automator app.
View organize_mac_screen_captures.py
import glob
import os
import re
FILE_TYPE = 'png'
NEW_FILE_PATTERN = r'.*(\d{4})-(\d{2})-(\d{2})_\d{5,6}([^\/]+)?\.' + FILE_TYPE
SC_DIR = '/Users/hoge/Pictures/_ScreenCaptureTmp'
SC_OUT_DIR = '/Users/hoge/Pictures/ScreenCaptures'
DIR_TYPE = 'MONTH' # "DAY" or "MONTH"
@michimani
michimani / main.go
Created Feb 19, 2021
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.
View main.go
package main
import (
"context"
_ "embed"
"encoding/json"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/aws"