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 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 / 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 / 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'
@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 / 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 / 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 / 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 / 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 / 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 / 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'