Skip to content

Instantly share code, notes, and snippets.

@y16ra
y16ra / .zshrc
Created July 31, 2024 01:32
enable cdr command
if [[ -n $(echo ${^fpath}/chpwd_recent_dirs(N)) && -n $(echo ${^fpath}/cdr(N)) ]]; then
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-max 1000
zstyle ':chpwd:*' recent-dirs-file "$HOME/.cache/chpwd-recent-dirs"
fi
@y16ra
y16ra / .zshrc
Created July 31, 2024 01:08
navigates to the directory of a repository listed by the `ghq` command using `fzf`.
function fzf-src(){
local src=$(ghq list --full-path | fzf --query "$LBUFFER" --layout=reverse)
if [ -n "$src" ]; then
BUFFER="cd $src"
zle accept-line
fi
zle -R -c
}
zle -N fzf-src
bindkey '^]' fzf-src
@y16ra
y16ra / .zshrc
Last active July 31, 2024 00:31
Interactive History Search
HIST_STAMPS="yyyy-mm-dd"
# fzf history
function fzf-select-history() {
local selected=$(history -n -r 1 | fzf --query "$LBUFFER" --reverse)
if [ -n "$selected" ]; then
BUFFER=$(echo "$selected" | awk '{$1=""; $2=""; print $0}' | sed 's/^[ \t]*//')
CURSOR=$#BUFFER
zle reset-prompt
fi
@y16ra
y16ra / run-ecs-task.sh
Created July 30, 2024 00:35
This script provides to run a new task using the configuration of an existing ECS service and wait for its completion.
CLUSTER_NAME=$YOUR_CLUSTER_NAME
TASK_DEF_NAME=$YOUR_TASK_NAME
SERVICE_NAME=$YOUR_SERVICE_NAME
task_arn=$(aws ecs list-task-definitions --family-prefix "$TASK_DEF_NAME" --query "reverse(taskDefinitionArns)[0]" --output text)
# Describe the ECS service to get network configuration details
network_config=$(aws ecs describe-services --cluster $CLUSTER_NAME --services $SERVICE_NAME --query 'services[0].networkConfiguration.awsvpcConfiguration' --output json)
# Extract subnets and security groups
@y16ra
y16ra / .gitconfig
Created April 5, 2023 02:30
Delete all branches that do not exist in the remote branch
[alias]
clean-branch = !git fetch -p | git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
@y16ra
y16ra / git_config_default_branch.sh
Created March 28, 2022 01:20
Configure default git branch name
git config --global init.defaultBranch main
@y16ra
y16ra / two-sum-brute-force.py
Created December 23, 2019 03:18
Awful python code for Two Sum problem
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i1, num1 in enumerate(nums):
for i2, num2 in enumerate(nums[i1+1:]):
if target == (num1 + num2):
return [i1, i2 + i1 + 1]
@y16ra
y16ra / AwsLambdaClient.kt
Created July 6, 2018 03:46
Call AWS Lambda Function by Kotlin
class AwsLambdaClient {
val aws_access_key_id = "<YOUR_ACCESS_KEY_PASTE_HERE>"
val aws_secret_access_key = "<YOUR_SECRET_KEY_PASTE_HERE>"
val region = "ap-northeast-1"
val function_name = "test_func"
fun invoke() {
val payload = """
{
"token": "TOKEN",
@y16ra
y16ra / context.py
Created March 29, 2017 01:45
pythonでファイル位置から1つ上のディレクトリをsys.pathに追加する
import sys
sys.path.append(path.normpath(path.join(path.dirname(path.abspath( __file__ )), '..')))
@y16ra
y16ra / deleteOldMail.gs
Created January 30, 2017 08:21
ラベルと保管日数をスプレッドシートで指定して保管日数を超えているメールを削除するGAS
function deleteOldMail() {
var sheet = SpreadsheetApp.getActive().getSheetByName('label');
for(var row=2; row<=sheet.getLastRow(); row++){
var labelName = sheet.getRange(row, 1).getValue();
var days = sheet.getRange(row, 2).getValue();
var deleteThreads = GmailApp.search('older_than:'+days+'d -is:starred label:'+ labelName);
for (var i = 0; i < deleteThreads.length; i++) {
deleteThreads[i].moveToTrash();
}