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 / 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;
}
@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 / translate_by_deepl.js
Last active November 23, 2020 13:05
A bookmarklet for translating web pages using DeepL.
javascript: (function () {
var API_KEY = '<your_deel_api_key>';
var DEEPL_TRANSLATE_EP = 'https://api.deepl.com/v2/translate';
var TARGET_LANBG = 'JA';
var bodyHtml = document.getElementsByTagName('body')[0].innerHTML;
var params = {
'auth_key': API_KEY,
'text': bodyHtml,
'target_lang': TARGET_LANBG,
'tag_handling': 'xml'
@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 / detect_smash_bros_sp_power_v2.py
Last active November 23, 2020 14:59
Use Amazon Rekognition to detect world strength from captured images of Smash Bros SPECIAL. (part 2) DETAIL: https://michimani.net/post/aws-extract-value-of-smash-blos-sp-power-by-rekognition-2/
import boto3
import cv2
import datetime
import hashlib
import json
import os
import re
import sys
import time
@michimani
michimani / detect_smash_bros_sp_power.py
Last active August 29, 2020 04:03
Use Amazon Rekognition to detect world strength from captured images of Smash Bros SPECIAL. DETAIL: https://michimani.net/post/aws-extract-value-of-smash-blos-sp-power-by-rekognition/
import boto3
import sys
reko = boto3.client('rekognition')
target_area = {
'A': {'X': 0.785039062, 'Y': 0.639347222},
'B': {'X': 0.950203125, 'Y': 0.639347222},
'C': {'X': 0.950203125, 'Y': 0.737263889},
'D': {'X': 0.785039062, 'Y': 0.737263889},
@michimani
michimani / set_slack_status.js
Created June 12, 2020 12:09
Sample Google Apps Script that set Slack status emoji and message.
const slackUserId = 'XXXXXXXX'; // your user ID
const slackApiToken = 'xoxp-******-*******-******'; // your API token
const slackSetStatusUrl = 'https://slack.com/api/users.profile.set';
function changeSlackStatus(emoji, message) {
const headers = {
'Authorization': 'Bearer ' + slackApiToken,
'X-Slack-User': slackUserId,
'COntent-Type': 'application/json; charset=utf-8'
};
@michimani
michimani / display_cstimer_results
Created June 8, 2020 12:19
This is a bookmarklet displays the solve results measured by csTimer.
javascript:(function(){const statsSelector="#stats div.statc table.sumtable.table tr";var stats=document.querySelectorAll(statsSelector),statsTitle="",statsValue="";stats.forEach(t=>{let e=t.querySelector("th").innerText;if(""!=e){"time"==e&&(e="1"),""!=statsTitle&&(statsTitle+="/"),statsTitle+=e;let s=t.querySelectorAll("td")[1].innerText;""!=statsValue&&(statsValue+="/"),statsValue+=s}});alert(`${statsTitle} = ${statsValue}`);})();
@michimani
michimani / lambda_at_1st_day__main.go
Created June 3, 2020 22:52
Sample of AWS Lambda function that runs at the 1st day of month in Japanese time.
package main
import (
"context"
"time"
)
// IsFirstDay is function to check today is the 1st day of month in JST
func IsFirstDay() bool {
var isFirstDay bool = false