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 / lambda_edge_hugo.js
Last active May 6, 2021 22:04
Optimizing request URI for CloudFront with Lambda@Edge that has HUGO site as origin.
'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 / copy_link_of_current_page_as_md
Last active December 21, 2020 17:11
Copy current web page title and url link to clipboard as markdown link format.
@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 / 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 / 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
@michimani
michimani / main.go
Created May 18, 2020 12:17
Sample script to scan DynamoDB table via AWS SDK for Go.
package main
import (
"bytes"
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
@michimani
michimani / generate_pv_summary.py
Last active April 13, 2020 23:12
This script calculate the PV of each page for the last week by using Google Analytics Reporting API v4 .
""" Get weekly page view summary. """
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
import json
import re
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'client_secrets.json'