Skip to content

Instantly share code, notes, and snippets.

😪
sleepy...

Yoshihiro Ito michimani

😪
sleepy...
View GitHub Profile
@michimani
michimani / set_slack_status.js
Created Jun 12, 2020
Sample Google Apps Script that set Slack status emoji and message.
View set_slack_status.js
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 Jun 8, 2020
This is a bookmarklet displays the solve results measured by csTimer.
View display_cstimer_results
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 Jun 3, 2020
Sample of AWS Lambda function that runs at the 1st day of month in Japanese time.
View lambda_at_1st_day__main.go
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
Sample script to scan DynamoDB table via AWS SDK for Go.
View main.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 Apr 16, 2020
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 / generate_pv_summary.py
Last active Apr 13, 2020
This script calculate the PV of each page for the last week by using Google Analytics Reporting API v4 .
View generate_pv_summary.py
""" 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 Mar 10, 2020
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_PARREN = 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 / API_Gateway_set-up-custom-domain.yml
Created Feb 21, 2020
CloudFormation template for setting up custom domain name for an API in API Gateway.
View API_Gateway_set-up-custom-domain.yml
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 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 / 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"
You can’t perform that action at this time.