Skip to content

Instantly share code, notes, and snippets.

View sonodar's full-sized avatar

Sonoda Ryohei sonodar

View GitHub Profile
@sonodar
sonodar / createRestClient.ts
Created November 30, 2022 06:27
Rest Client with Bearer token authorization
type Method = 'get' | 'post' | 'patch' | 'put' | 'delete' | 'head'
type IdempotentMethod = 'get' | 'head' | 'delete'
type MutationMethod = Exclude<Method, IdempotentMethod>
type IdempotentClient = (path: string, query?: URLSearchParams, headers?: HeadersInit) => Promise<Response>
type MutationClient = (path: string, body: any, headers?: HeadersInit) => Promise<Response>
type IdempotentClients = Record<IdempotentMethod, IdempotentClient>
type MutationClients = Record<MutationMethod, MutationClient>
type _RequestClient = IdempotentClients & MutationClients
@sonodar
sonodar / wait_for_codebuild_job_complete.sh
Last active March 31, 2022 08:32
Wait for AWS CodeBuild jobs to complete while also outputting logs
#!/bin/bash
# aws-cli, jq, GNU-sed are required
set -euC -o pipefail
# Shortcut for get-log-events command.
get_log_events() {
local cmdArgs="--start-from-head --limit 100 --log-group-name ${1} --log-stream-name ${2}"
[[ -n ${3:-} ]] && cmdArgs="${cmdArgs} --next-token ${3}"
aws logs get-log-events ${cmdArgs}
}
@sonodar
sonodar / GoogleBotStrictVerifier.php
Last active April 2, 2019 06:28
Googlebot からのアクセスかどうかを厳密にチェックする
<?php
/**
* Googlebot からのアクセスかどうかを厳密にチェックするクラス。
* 使い方: GoogleBotStrictVerifier::isGoogleBot()
*/
class GoogleBotStrictVerifier
{
/**
* User-Agent および IP の逆引きから Googlebot かどうかを判定する。
* @return boolean
@sonodar
sonodar / get_ssm_parameters.js
Last active April 3, 2024 06:24
Get secret parameters from Amazon EC2 Parameter Store
if (process.argv.length < 3) {
throw `Usage: ${process.argv[1]} path_prefix`
}
const PATH_PREFIX = process.argv[2]
const path = require('path')
const AWS = require('aws-sdk')
const ssm = new AWS.SSM()
function getParametersByPath(nextToken, callback) {
@sonodar
sonodar / file0.js
Created June 23, 2014 12:36
[JavaScript] コナミコマンドのスニペット ref: http://qiita.com/sonodar/items/b1da050e4cc2806bba9d
(function(cmd, fire) {
var keys = [];
var l = cmd.length, CMD = cmd.join(',');
$(document).on('keydown', function(event) {
keys.push(event.which);
if (keys.length < l) return true;
if (keys.join(',') === CMD) fire();
keys = [];
});