Skip to content

Instantly share code, notes, and snippets.

View doi-t's full-sized avatar
🧗‍♂️
Be open-minded

Toshiya Doi doi-t

🧗‍♂️
Be open-minded
View GitHub Profile
@doi-t
doi-t / recursive_word_replacement.sh
Created October 11, 2020 07:15
Recursive search and replace in text files on Mac
find internal \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i'.original' -e 's/foo/bar/g'
@doi-t
doi-t / gh_issue_view.yml
Last active July 17, 2020 09:40
Run gh command on Github Actions as a manual trigger
name: gh issue view
on:
workflow_dispatch: # Manual trigger: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
inputs:
issueNumber:
description: 'Issue number'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@doi-t
doi-t / manage_milestones_with_gh.md
Last active December 8, 2023 18:13
Manage milestones with gh

Use gh v0.11.0 or later for the "shell" aliases.

Run the following gh alias set commands for each operation. You can confirm the created aliases with gh alias list.

gh listMilestones

gh alias set listMilestones "api graphql -F owner=':owner' -F name=':repo' -f query='
    query ListMilestones(\$name: String\!, \$owner: String\!) {
        repository(owner: \$owner, name: \$name) {
            milestones(first: 100) {
SCHEMA_FILE=path/to/schema/file.sql \
REPO=$(git rev-parse --show-toplevel); \
GIT_HASH=$(git rev-parse HEAD); \
schemalex "local-git://${REPO}?file=${SCHEMA_FILE}&commitish=${GIT_HASH}" ${REPO}/${SCHEMA_FILE}
@doi-t
doi-t / login_to_opsworks_instance_with_session_manager.sh
Last active March 17, 2020 09:18
Login to an opsworks instance from local with AWS session manager
# Install the plugin first
# https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
TARGET_HOSTNAME="<your target hostname>"; \
OPSWORKS_STACK_ID="<your target OpsWorks Stack ID>"; \
REGION="us-east-1"; \
EC2_INSTANCE_ID=$(aws opsworks describe-instances --stack-id ${OPSWORKS_STACK_ID} --region ${REGION} \
| jq --arg TARGET_HOSTNAME "$TARGET_HOSTNAME" \
'.[][] | select(.Hostname | contains($TARGET_HOSTNAME)) | .Ec2InstanceId' --raw-output); \
echo "Connecting to ${EC2_INSTANCE_ID}"; \
aws ssm start-session --target ${EC2_INSTANCE_ID}
@doi-t
doi-t / my_vs_code_settings.md
Last active January 10, 2021 04:08
wip: My VS Code Settings

Update settings.json

{
  "editor.formatOnSave": true,
  "editor.wordWrap": "on",
  "editor.insertSpaces": true,
  "editor.detectIndentation": false,
@doi-t
doi-t / give_me_linux_env_with_current_dir_now.sh
Last active July 13, 2019 06:07
Give me a linux environment with the current working directory right now!
#!/bin/bash
set -ex
IMAGE=${1:-ubuntu}
if [ ${IMAGE} = 'golang' ]; then
TARGET=/go
else
TARGET=/app
fi
#!/bin/bash
[ $# -ne 1 ] && echo "Usage: $0 <security group id>" && exit 1
SG_ID=$1
MY_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
aws ec2 authorize-security-group-ingress --group-id ${SG_ID} \
--ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges="[{CidrIp=${MY_IP}/32,Description='Open 22 port with awscli'}]"
@doi-t
doi-t / aws_route53_upsert_a_record.sh
Last active June 6, 2019 21:59
Change an A record of a domain managed by AWS Route53.
#!/bin/bash
set -ex
[ $# -ne 3 ] && echo "Usage $0 <your zone id> <your domain> <your ip>" && exit 1
MY_ZONE_ID=$1
MY_DOMAIN=$2
MY_IP=$3
TMPFILE=$(mktemp /tmp/${MY_DOMAIN}_upsert_${MY_IP}.XXXXXX)
@doi-t
doi-t / protocol_buffers_and_grpc_tutorial.md
Last active July 27, 2023 11:12
Protocol Buffers & gRPC Tutorial: Python & Go