Skip to content

Instantly share code, notes, and snippets.

Avatar
ROLLING BACK

4piu 4piu

ROLLING BACK
View GitHub Profile
@4piu
4piu / sync.sh
Last active Nov 10, 2021
Sync large project using rsync with respect to gitignore
View sync.sh
#!/usr/bin/env bash
# https://stackoverflow.com/questions/13713101/rsync-exclude-according-to-gitignore-hgignore-svnignore-like-filter-c
SOURCE="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
TARGET=user@remote:/path/to/my/blog
rsync --delete-after --filter=":e- .gitignore" --filter "- .git/" -a --progress $SOURCE/ $TARGET
@4piu
4piu / netns.sh
Last active Nov 1, 2021
Create A Network Namespace Using a Bypass Gateway
View netns.sh
#!/usr/bin/env sh
NAMESPACE=proxy
GATEWAY=172.16.1.15
STATIC_IP= #172.16.1.97/24
DNS_SERVER=172.16.1.1
# check root permission
if [ "$(id -u)" != "0" ]; then
echo "Please run as root"
@4piu
4piu / netns.sh
Created Nov 1, 2021
Create A Network Namespace with the NATed Internet
View netns.sh
#!/usr/bin/env sh
NAMESPACE=nat
VETH_IP_HOST=10.0.0.1/24
VETH_IP_NS=10.0.0.2/24
# check root permission
if [ "$(id -u)" != "0" ]; then
echo "Please run as root"
exit 1
@4piu
4piu / invoke.sh
Created Nov 1, 2021
Invoke function in sh
View invoke.sh
#!/usr/bin/env sh
a () {
echo "invoke a"
}
b () {
echo "invoke b"
}
@4piu
4piu / check-perm.sh
Created Nov 1, 2021
Check root permission in sh
View check-perm.sh
#!/usr/bin/env sh
if [ "$(id -u)" != "0" ]; then
echo "Please run as root"
exit 1
fi
@4piu
4piu / clear_user_python_package.sh
Last active Nov 2, 2021
Uninstall all user installed python package
View clear_user_python_package.sh
# list pkgs | filter by dir | get first column | batch uninstallation
pip list --user | tail +3 | awk '{print $1}' | xargs pip uninstall -y
@4piu
4piu / scroff.sh
Created Jul 25, 2021
Turn off monitor
View scroff.sh
#!/bin/bash
sleep 1; xset dpms force off
@4piu
4piu / proxy-off
Created Jul 1, 2021
Shell script to temporarily disable the proxy
View proxy-off
# source this file in shell
unset http_proxy https_proxy ftp_proxy rsync_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY ALL_PROXY
echo "Proxy disabled"
@4piu
4piu / proxy-on
Last active Sep 16, 2021
Shell script to temporarily enable proxy
View proxy-on
# source this file in shell or put in /etc/profile.d/
#export http_proxy=socks5h://127.0.0.1:1080
export http_proxy=http://127.0.0.1:8080
export no_proxy="127.0.0.1,localhost,.localdomain.com"
export https_proxy=$http_proxy \
ftp_proxy=$http_proxy \
rsync_proxy=$http_proxy \
all_proxy=$http_proxy \
@4piu
4piu / rename_all.sh
Last active May 12, 2021
Refactor all author name and email for the old commits
View rename_all.sh
#!/usr/bin/env bash
git filter-branch -f --env-filter '
OLD_EMAIL=("stupid_name@gmail.com" "private@gmail.com" "temp@gmail.com")
NEW_NAME="foo"
NEW_EMAIL="foo@newdomain.com"
if [[ "${OLD_EMAIL[@]}" =~ "${GIT_COMMITTER_EMAIL}" || "${OLD_EMAIL[@]}" =~ "${GIT_AUTHOR_EMAIL}" ]]
then
export GIT_COMMITTER_NAME="${NEW_NAME}"
export GIT_COMMITTER_EMAIL="${NEW_EMAIL}"