Skip to content

Instantly share code, notes, and snippets.

Avatar
🎱
Be open-minded

Toshiya Doi doi-t

🎱
Be open-minded
View GitHub Profile
@doi-t
doi-t / recursive_word_replacement.sh
Created Oct 11, 2020
Recursive search and replace in text files on Mac
View recursive_word_replacement.sh
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 Jul 17, 2020
Run gh command on Github Actions as a manual trigger
View gh_issue_view.yml
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 Oct 29, 2020
Manage milestones with gh
View manage_milestones_with_gh.md

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) {
View schemalex_git_hash_comparison.sh
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 Mar 17, 2020
Login to an opsworks instance from local with AWS session manager
View login_to_opsworks_instance_with_session_manager.sh
# 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 Jan 10, 2021
wip: My VS Code Settings
View my_vs_code_settings.md

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 Jul 13, 2019
Give me a linux environment with the current working directory right now!
View give_me_linux_env_with_current_dir_now.sh
#!/bin/bash
set -ex
IMAGE=${1:-ubuntu}
if [ ${IMAGE} = 'golang' ]; then
TARGET=/go
else
TARGET=/app
fi
View open_22_port_with_awscli.sh
#!/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 Jun 6, 2019
Change an A record of a domain managed by AWS Route53.
View aws_route53_upsert_a_record.sh
#!/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 Dec 4, 2020
Protocol Buffers & gRPC Tutorial: Python & Go
View protocol_buffers_and_grpc_tutorial.md
You can’t perform that action at this time.