Skip to content

Instantly share code, notes, and snippets.

View karancode's full-sized avatar
:octocat:
day 1

Karan Thanvi karancode

:octocat:
day 1
View GitHub Profile
@karancode
karancode / _README.md
Created August 23, 2021 03:38
Bash General-Purpose Yes/No Prompt Function ("ask")

This is a general-purpose function to ask Yes/No questions in Bash, either with or without a default answer. It keeps repeating the question until it gets a valid answer.

@karancode
karancode / github-private_repo_action.yaml
Last active July 27, 2020 09:58
Example workflow for using github action's residing in a private repo!
# To use github actions from a private repo, you can clone the action's private repo locally in the workflow and execute it.
# Below is an example workflow for reference! :)
name: Private Action X
on:
pull_request:
branches:
- master
- release
@karancode
karancode / merge-github-pull-requests.sh
Created July 26, 2020 08:34
Merge Github PRs using bash
#!/bin/bash
set -u -o pipefail
WORKSPACE_DIR=".github-workspace-for-merging-pr"
# export file with list of PRs
LIST_OF_PR_FILE=${LIST_OF_PR_FILE:-"list-of-prs"}
mkdir -p ${WORKSPACE_DIR}
@karancode
karancode / git-update-user-info-after-commit
Created May 1, 2020 06:00
force update your git username and email after commits have been pushed with undesired user info.
$ git filter-branch -f --env-filter "GIT_AUTHOR_NAME='<new_username>'; GIT_AUTHOR_EMAIL='<new_email>'; GIT_COMMITTER_NAME='<new_username>'; GIT_COMMITTER_EMAIL='<new_email>';" HEAD
$ git push -f
@karancode
karancode / duplicate_all.sh
Created March 3, 2020 22:29
Duplicate all the files in a directory with different name (appended string, etc.)
# Let's say you've .yaml.j2 files in a directory and
# you want to make copy for each file, for ex:
# files you have : config1.yml.j2 config2.yml.j2 porperties1.yml.j2 setup.yml.j2
# files you want : config1.yml.j2 config1_new.yml.j2 config2.yml.j2 config2_new.yml.j2 porperties1.yml.j2 porperties1_new.yml.j2 setup.yml.j2 setup_new.yml.j2
for filename in *.yml.j2; do mv $filename ${filename%.yaml.j2}_new.yml.j2; done
@karancode
karancode / k8s_pods_status_count.sh
Created February 6, 2020 12:43
kubernetes pod's status's count.
$ kubectl get po -owide | grep -v Running | awk '{print $3}' | awk '{num[$1]+=1}END{for(i in num){print i, num[i]}}'
@karancode
karancode / k8s_rollout_restart.sh
Created January 16, 2020 07:09
Rollout restart all the deployments in k8s cluster - supporting multiple environments.
#!/bin/sh
###
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# https://gist.github.com/davejamesmiller/1965569
local prompt default reply
@karancode
karancode / _etc_environment
Created January 3, 2020 18:11
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
# Add these below lines to /etc/environment file
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
@karancode
karancode / create-pr-in-multiple-repos.sh
Last active May 1, 2020 06:13
To create PRs in multiple repositories for similar code.
#!/bin/bash
git_owner="karancode"
git_repo=${1}
if [ -d "${git_repo}" ]; then
cd ${git_repo}
git checkout .
git checkout master
else