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 / API_Gateway_set-up-custom-domain.yml
Created February 21, 2020 01:06
CloudFormation template for setting up custom domain name for an API in API Gateway.
AWSTemplateFormatVersion: "2010-09-09"
Description: "Setup API Gateway custom domain name"
Parameters:
AcmArn:
Type: String
CustomDomainName:
Type: String
ApiID:
Type: String
DomainHostZoneId:
@michimani
michimani / fetch_hatebu_count.py
Last active December 10, 2019 13:46
Get share count in Hatena Bookmark of each of posts in Hugo site, and save it as json files on S3.
from time import sleep
import boto3
import json
import logging
import re
import traceback
import urllib.parse
import urllib.request
import xml.etree.ElementTree as ET
@michimani
michimani / open_hatebu
Last active October 28, 2019 03:13
This is a bookmarklet opens Hatena Bookmark page of current page.
javascript:(function(){ if (location.href.match(/^https/)) { htb = 'https://b.hatena.ne.jp/entry/s/' + location.href.replace(/https?:\/\//g, ''); } else { htb = 'https://b.hatena.ne.jp/entry/' + location.href.replace(/https?:\/\//g, ''); } window.open(htb, '_blank');})();
@michimani
michimani / sns_to_slack_smiply.py
Created October 28, 2019 02:23
Base of Lambda function that notifies SNS message to Slack.
import json
from urllib.request import Request, urlopen
SLACK_WEBHOOK_URL = '<YOUR-SLACK-WEBHOOK-URL>'
def lambda_handler(event, context):
try:
if 'debug' in event:
event_message = event['debug']
else:
@michimani
michimani / amazon_now_playing
Last active September 9, 2019 06:29
This is a bookmarklet that generates "#NowPlaying" text when playing music with Amazon Music in a web browser.
javascript:(function(){tit=document.querySelector('.trackInfoContainer .trackTitle a span').innerText;artO=document.querySelector('.trackInfoContainer .trackArtist span');if(typeof artO == 'undefined') {artO=document.querySelector('.trackInfoContainer .trackArtist span.artist');}art=artO.innerText;window.prompt('NowPlaying!', `${tit}/${art} #NowPlaying`);})();
@michimani
michimani / amazon-music-as-nowplay.py
Last active July 9, 2019 06:57
Convert share string that generated by Amazon Music share button to NoyPlaying string with hashtag #nowplaying .
from bs4 import BeautifulSoup
from urllib import request
import re
import sys
import traceback
if __name__ == "__main__":
args = sys.argv
if len(args) < 2:
print('At least one argument is required.')
@michimani
michimani / show-old-entry-message.js
Last active July 8, 2019 02:40
Show message in an entry generated by Hugo that notifier that entry is old.
function showInfoNotifiesOldPost() {
const nowDate = new Date();
const oldTs = 60 * 60 * 24 * 365 * 1000; // 1 year (millisecond)
const nowTs = nowDate.getTime();
const postDateElem = document.querySelector('p.post-date > time.dt-published');
if (postDateElem !== null) {
try {
const postDateStr = postDateElem.getAttribute('datetime');
const postDate = new Date(postDateStr);
const postTs = postDate.getTime();
@michimani
michimani / save_image_to_s3.py
Created June 13, 2019 08:21
Save image file from image url to S3 backet.
import boto3
from urllib import request
from urllib.request import Request, urlopen
def save_image(img_url):
"""
Save images from image url to S3 backet.
@param string img_url
"""
try:
@michimani
michimani / draggable_block_sample.html
Created June 11, 2019 05:49
Example of placing a draggable block.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Draggable Block Test</title>
<style>
.outer-block {
position: relative;
@michimani
michimani / put-process-status.sh
Created May 23, 2018 01:34
Put linux process status to Amazon CloudWatch.
###################################################################################
# check process aliving (count process number)
# return integer 1 (process is running) or 0 (process is dead) or 9 (some error)
###################################################################################
function is_process_alive() {
count=`ps awux | grep -v grep | grep -v "$0" | grep -w "$1" | wc -l`
if [[ $count =~ ^[0-9]+$ ]]; then
if [ $count != 0 ]; then
echo 1
else