Skip to content

Instantly share code, notes, and snippets.

View 4piu's full-sized avatar
ROLLING BACK

4piu 4piu

ROLLING BACK
View GitHub Profile
@4piu
4piu / netns.sh
Last active November 1, 2021 09:58
Create A Network Namespace Using a Bypass Gateway
#!/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 November 1, 2021 08:00
Create A Network Namespace with the NATed Internet
#!/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 November 1, 2021 05:45
Invoke function in sh
#!/usr/bin/env sh
a () {
echo "invoke a"
}
b () {
echo "invoke b"
}
@4piu
4piu / check-perm.sh
Created November 1, 2021 05:43
Check root permission in 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 November 2, 2021 20:05
Uninstall all user installed python package
# 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 July 25, 2021 20:01
Turn off monitor
#!/bin/bash
sleep 1; xset dpms force off
@4piu
4piu / proxy-off
Created July 1, 2021 05:52
Shell script to temporarily disable the proxy
# 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 September 16, 2021 08:18
Shell script to temporarily enable proxy
# 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 10:34
Refactor all author name and email for the old commits
#!/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}"
@4piu
4piu / clone_all.sh
Last active May 12, 2021 10:34
Clone all user repositories
#!/usr/bin/env bash
# https://gist.github.com/milanboers/f34cdfc3e1ad9ba02ee8e44dae8e093f#gistcomment-3222031
curl -s -H "Authorization: token ghp_DY34*****************************KRQ" "https://api.github.com/user/repos?per_page=100" |
jq -r ".[].ssh_url" |
xargs -L1 git clone