Last active
September 18, 2018 13:08
-
-
Save seancheung/96dd7808aaaa64983823be4fb1c138b0 to your computer and use it in GitHub Desktop.
misc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
java -jar "%~dp0bfg-1.13.0.jar" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\Directory\shell\cmder] | |
@="Cmder Here" | |
"Extended"="" | |
"Icon"="C:\\cmder\\icons\\cmder.ico" | |
"NoWorkingDirectory"="" | |
"ShowBasedOnVelocityId"=dword:00639bc8 | |
[HKEY_CLASSES_ROOT\Directory\shell\cmder\command] | |
@="C:\\cmder\\Cmder.exe \"%V\"" | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\cmder] | |
@="Cmder Here" | |
"Extended"="" | |
"Icon"="C:\\cmder\\icons\\cmder.ico" | |
"NoWorkingDirectory"="" | |
"ShowBasedOnVelocityId"=dword:00639bc8 | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\cmder\command] | |
@="C:\\cmder\\Cmder.exe \"%V\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# phpmyadmin docker | |
docker run --network=$NETWORK -e PMA_ARBITRARY=1 --name=phpmyadmin -p $PORT:80 -d phpmyadmin/phpmyadmin | |
# install docker with socks5 | |
curl -fsSL get.docker.com | bash - && docker run --restart=always -d --name socks -p 8388:8388 seancheung/dsocks:latest -p 8388 -k 123456 -m aes-256-cfb | |
start | |
# set docker mirror | |
echo DOCKER_OPTS="--registry-mirror=http://~" > /etc/default/docker | |
# install docker via cn mirror | |
curl -sSL https://get.daocloud.io/docker | sh | |
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://~ | |
# docker change container timezone | |
apt-get update | |
apt-get install -y tzdata | |
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | |
echo "Asia/Shanghai" > /etc/timezone | |
dpkg-reconfigure -f noninteractive tzdata | |
# docker container link host timezone | |
-v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro | |
# save all images to one big tarball | |
docker save $(docker images -q) -o docker-images.tar.gz | |
# dump tag info | |
docker images | sed '1d' | awk '{docker tag $3 $1:$2}' > docker-images.list | |
# load all images from tarball | |
docker load -i docker-images.tar.gz | |
# tag loaded images | |
./docker-images.list | |
# get host ip insider container | |
apt-get install -y iproute2 | |
/sbin/ip route|awk '/default/ { print $3 }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for i in "$1/"*.{avi,mov}; do | |
if [ -f "$i" ]; then | |
ffmpeg -i "$i" -acodec aac -vcodec libx264 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -y "${i%.*}".mp4 | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ffmpeg | |
ffmpeg -i example.mov -f mp4 -vcodec libx264 -preset fast -profile:v main -acodec aac example.mp4 -hide_banner | |
ffmpeg -i example.mkv -codec copy example.mp4 | |
# remove all subtitle tracks | |
ffmpeg -i input.mkv -map 0 -map -0:s -codec copy output.mkv | |
# add subtitle track | |
ffmpeg -i input.mkv -i subtitle.srt -map 0:a -map 0:v -map 1:s -c copy -c:s srt output.mkv | |
ffmpeg -i input.mp4 -i subtitle.srt -map 0:a -map 0:v -map 1:s -c copy -c:s mov_text output.mp4 | |
# fix "Can't write packet with unknown timestamp" error | |
ffmpeg -fflags +genpts ... | |
# set subtitles metadata | |
ffmpeg -i input.mkv -map 0:a -map 0:v -map 0:s -c copy -metadata:s:s:0 language=chi -metadata:s:s:0 title="English" -disposition:s:0 default out.mkv | |
# batch convert | |
for f in *.mkv; do ffmpeg -i "$f" -c:v libx264 -c:a copy "${f%.mkv}.mp4"; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reset bare repo | |
git update-ref HEAD HEAD^ | |
git update-ref refs/heads/branch-name branch-name^ | |
git update-ref refs/heads/branch-name a12d48e2 | |
# git push to multiple remotes at once | |
git remote add origin git@gitlab.com:namespace/repo.git | |
git remote set-url --add --push origin git@gitlab.com:namespace/repo.git | |
git remote set-url --add --push origin git@bitbucket.org:namespace/repo.git | |
# git change file mode | |
git update-index --chmod=+x <file> | |
# git rename filename case | |
git mv file File | |
# git rename folder name case | |
git mv folder tmp | |
git mv tmp Folder | |
# git rebase root | |
git rebase [-i] --root $tip | |
# git skip lfs checking | |
GIT_LFS_SKIP_SMUDGE=1 git clone ... | |
# git config yto push current branch only | |
git config --global push.default current | |
# git push all branches from remote_a to remote_b | |
git push remote_b 'refs/remotes/remote_a/*:refs/heads/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# wget to background | |
wget -bqc http://source | |
# check queue | |
ps aux | grep wget | |
# convert line endings | |
apt-get install tofrodos dos2unix | |
fromdos $FILE | |
dos2unix $FILE | |
# fix host issue | |
echo $(hostname -I | cut -d\ -f1) $(hostname) | sudo tee -a /etc/hosts | |
# fix locale issue | |
# sudo locale-gen en_US.UTF-8 | |
# sudo echo "LC_ALL=en_US.UTF-8" >> /etc/environment | |
# sudo echo "LANG=en_US.UTF-8" >> /etc/environment | |
# --- | |
sudo apt-get install language-pack-UTF-8 | |
# or | |
sudo local-gen UTF-8 | |
# fix locale warning on osx, add these to ~/.bash_profile or ~/.zshrc | |
export LC_CTYPE=en_US.UTF-8 | |
export LC_ALL=en_US.UTF-8 | |
# list port usage | |
sudo lsof | grep LISTEN | |
# list target port usage | |
sudo lsof -n -i :9000 | grep LISTEN | |
# list target ports and print process ids only | |
sudo lsof -n -i :8080,8081 | grep LISTEN | awk '{ print $2; }' | |
# kill by port usage(e.g. 9000) | |
kill -9 $(lsof -t -i:9000 -sTCP:LISTEN) | |
# list files only | |
find . -type f -print0 | xargs -0r ls | tee filelist.txt | |
# find files with matching content | |
find . -type f -print0 | xargs -0 grep -l "some string" | |
# grab lines after match | |
ls ./ | sed -n -e '/Untracked files/,$p' | |
# rsync | |
rsync -avhrz --del /path/to/src remote:/path/to/dest | |
# dry-run | |
rsync -avhrzn --del /path/to/src remote:/path/to/dest | |
# directory md5 list | |
find folder1 folder2 -type f -exec md5sum "{}" + > checklist.chk | |
# compare checklist diff | |
awk 'FNR==NR{hashes[$1]=$NF; next;}!($1 in hashes){printf("%s\n", $NF)}' old.chk new.chk | |
# compare checklist new | |
awk 'FNR==NR{names[$NF]=$NF; next;}!($NF in names){printf("%s\n", $NF)}' old.chk new.chk | |
# trim begin/end whitespaces | |
awk '{$1=$1;print}' | |
# in short | |
awk '{$1=$1};1' | |
# bash array unique | |
array=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) | |
# bash check directory empty | |
if [ -z "$(ls -A /path/to/dir)" ]; then | |
echo "Empty" | |
else | |
echo "Not Empty" | |
fi | |
# rename with suffix | |
for f in *.ext; do mv "$f" "${f%.ext}-suffix.ext"; done | |
# safer with echo | |
for f in *.ext; do echo mv "$f" "${f%.ext}-suffix.ext"; done | |
# clear bash history | |
cat /dev/null > ~/.bash_history && history -c && exit | |
# make sudo no password prompt | |
sudo visudo | |
username ALL=(ALL) NOPASSWD: ALL | |
# redirect script stdout/stderr to file | |
exec > "$LOGFILE" 2>&1 | |
echo "*****$(date +\%Y-\%m-\%d-\%H:\%M:\%S)*****" | |
# also to stdout | |
exec &> >(tee -a "$LOGFILE") | |
# add sshkey to remote server | |
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys' | |
# ssh over proxy | |
ssh -tt ProxyServer -tt RemoteServer | |
ssh -i ~/.ssh/remote.pem -o ProxyCommand='ssh -i ~/.ssh/proxy.pem -o StrictHostKeyChecking=no proxyuser@proxy nc %h %p %r' -o StrictHostKeyChecking=no user@remote | |
# ssh config for default key | |
Host RemoteServer | |
HostName remote-server.tld | |
User username | |
IdentityFile ~/.ssh/remoteserver_key | |
# ssh config for ssh over proxy | |
Host RemoteServer | |
User username | |
IdentityFile ~/.ssh/remoteserver_key | |
ProxyCommand ssh proxyuser@ProxyServer nc %h %p %r | |
ServerAliveInterval 20 | |
# ssh config no knownhost check | |
Host RemoteServer | |
StrictHostKeyChecking no | |
UserKnownHostsFile=/dev/null | |
# create apache password | |
sudo htpasswd -c /etc/apache2/.htpasswd username | |
sudo htpasswd /etc/apache2/.htpasswd another_user | |
# install mongodb | |
# see https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ | |
# generate self-signed ssl certs | |
# see https://devcenter.heroku.com/articles/ssl-certificate-self | |
mkdir certs | |
cd certs | |
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048 | |
openssl rsa -passin pass:x -in server.pass.key -out server.key | |
rm server.pass.key | |
openssl req -new -key server.key -out server.csr | |
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt | |
# install php | |
sudo add-apt-repository ppa:ondrej/php | |
sudo apt-get update | |
sudo apt-get install -y php5.6 libapache2-mod-php5.6 php5.6-curl php5.6-gd php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-xmlrpc | |
# android net test fix | |
adb shell settings put global captive_portal_https_url https://google.cn/generate_204 | |
# fix npm permission issue on OSX | |
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} | |
# set npm cn mirror | |
npm config set registry https://registry.npm.taobao.org | |
# set compoer cn mirror | |
composer config -g repo.packagist composer https://packagist.phpcomposer.com | |
# linux - create dummy file | |
fallocate -l <size> filename | |
# windows - create dummy file | |
fsutil file createnew <filename> <length> | |
# windows cmd - replace with dummy file | |
for /R %f in (*.psd,*.jpg) do del "%~f" && call fsutil file createnew "%~f" "%~zf" | |
# windows powershell - replace with dummy file | |
foreach ($f in (Get-ChildItem -Recurse -Include *.psd,*.jpg)){$p=$f.FullName;$s=$f.Length;Remove-Item $f;fsutil file createnew $p $s} | |
# macOS, linux(GNU, BSD) - replace with dummy file | |
find . -type f -name '*.psd' -o -name '*.jpg' | while read f;do s=$(stat -c %s "$f");fallocate -l $(if [ "$s" -gt 4 ];then echo $s;else echo 4;fi) "$f"; done | |
# install gnu style utils on macOS | |
brew install md5sha1sum findutils gnu-sed | |
# elasticsearch list indices | |
curl -XGET localhost:9200/_cat/indices?v | |
# delete all matching indices | |
curl -XDELETE localhost:9200/logstash-* | |
# ubuntu check distribution version | |
lsb_release -a | |
# check kernel version | |
uname -a | |
# list linux disks | |
sudo lsblk | |
# check disk usage | |
df -h | |
# partition disk | |
sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb | |
# mount disk | |
sudo mount -o discard,defaults /dev/sdb /mnt/data | |
sudo chmod a+w /mnt/data | |
# check disk uuid | |
sudo blkid /dev/sdb | |
# auto mount disk on boot | |
sudo cp /etc/fstab /etc/fstab.backup | |
echo UUID=`sudo blkid -s UUID -o value /dev/sdb` /mnt/data ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab | |
# start minikube | |
minikube start --vm-driver=hyperv --hyperv-virtual-switch=minikube --bootstrapper=localkube | |
# gitlab https behind reversed proxy | |
externel_url 'https://...' | |
nginx['listen_port'] = 80 | |
nginx['listen_https'] = false | |
-- | |
sudo gitlab-ctl stop unicorn | |
sudo gitlab-ctl stop sidekiq | |
sudo gitlab-ctl reconfigure | |
sudo gitlab-ctl restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mysql change charset | |
show variables like '%time_zone%'; | |
show variables like '%character%'; | |
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci; | |
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; | |
# mysql add user and grant privileges | |
CREATE USER 'username'@'hostname' IDENTIFIED BY 'password'; | |
GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'hostname' WITH GRANT OPTION; | |
FLUSH PRIVILEGES; | |
# or | |
GRANT ALL PRIVILEGES ON databasename.* To 'user'@'hostname' IDENTIFIED BY 'password' WITH GRANT OPTION; | |
FLUSH PRIVILEGES; | |
# mysql get timezone | |
SELECT @@global.time_zone, @@session.time_zone, @@system_time_zone; | |
# set timezone | |
SET GLOBAL time_zone = timezone; | |
SET time_zone = timezone; | |
# fix mysql sql_mode | |
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); | |
SELECT @@sql_mode; | |
# enable trigger create/delete from non-root user | |
SET GLOBAL log_bin_trust_function_creators=1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MUSER="$1" | |
MPASS="$2" | |
MDB="$3" | |
# Detect paths | |
MYSQL=$(which mysql) | |
AWK=$(which awk) | |
GREP=$(which grep) | |
if [ $# -ne 3 ] | |
then | |
echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}" | |
echo "Drops all tables from a MySQL" | |
exit 1 | |
fi | |
TABLES=$($MYSQL -u $MUSER -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' ) | |
for t in $TABLES | |
do | |
echo "Deleting $t table from $MDB database..." | |
$MYSQL -u $MUSER -p$MPASS $MDB -e "drop table $t" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET FOREIGN_KEY_CHECKS = 0; | |
SET @tables = NULL; | |
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables | |
FROM information_schema.tables | |
WHERE table_schema = 'database_name'; -- specify DB name here. | |
SET @tables = CONCAT('DROP TABLE ', @tables); | |
PREPARE stmt FROM @tables; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; | |
SET FOREIGN_KEY_CHECKS = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER ;; | |
DROP PROCEDURE IF EXISTS insert_contacts_bulk ;; | |
CREATE PROCEDURE insert_contacts_bulk(IN _uid INT UNSIGNED,IN _status INT(1) UNSIGNED) | |
BEGIN | |
INSERT INTO `contacts` (`userId`, `friendId`, `status`, `createdAt`) SELECT _uid AS `userId`, `id` AS `friendId`, IFNULL(_status, 1) AS `status`, NOW() as `createdAt` FROM `users` AS u WHERE `id` != 1 AND NOT EXISTS (SELECT 1 FROM `contacts` as c WHERE (c.`friendId` = _uid AND u.`id` = c.`userId`) OR (c.`userId` = _uid AND u.`id` = c.`friendId`)); | |
END;; | |
DELIMITER ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
listen [::]:80; | |
server_name domain_name; | |
server_tokens off; | |
add_header Cache-Control public; | |
location / { | |
proxy_pass http://service_host:service_port; | |
proxy_buffering on; | |
proxy_buffers 12 12k; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header Host $host; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reset = "\x1b[0m" | |
Bright = "\x1b[1m" | |
Dim = "\x1b[2m" | |
Underscore = "\x1b[4m" | |
Blink = "\x1b[5m" | |
Reverse = "\x1b[7m" | |
Hidden = "\x1b[8m" | |
FgBlack = "\x1b[30m" | |
FgRed = "\x1b[31m" | |
FgGreen = "\x1b[32m" | |
FgYellow = "\x1b[33m" | |
FgBlue = "\x1b[34m" | |
FgMagenta = "\x1b[35m" | |
FgCyan = "\x1b[36m" | |
FgWhite = "\x1b[37m" | |
BgBlack = "\x1b[40m" | |
BgRed = "\x1b[41m" | |
BgGreen = "\x1b[42m" | |
BgYellow = "\x1b[43m" | |
BgBlue = "\x1b[44m" | |
BgMagenta = "\x1b[45m" | |
BgCyan = "\x1b[46m" | |
BgWhite = "\x1b[47m" | |
console.log('\x1b[36m%s\x1b[0m', info); //cyan | |
console.log('\x1b[33m%s\x1b[0m', path); //yellow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# windows execute powershell script file | |
powershell -nologo -noexit -executionpolicy bypass -File <filepath> | |
# windows execute powershell script over http | |
iex ((New-Object System.Net.WebClient).DownloadString('https://script.ps1')) | |
# windows execute powershell script bypass restrictions | |
Set-ExecutionPolicy Bypass -Scope Process -Force; | |
# windows powershell get net adapters | |
Get-NetAdapter | |
# windows powershell create vm-switch | |
New-VMSwitch -name minikube -NetAdapterName <AdapterName> -AllowManagementOS $true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\\cmder\\vscode.bat | |
-------> | |
@echo off | |
SET CMDER_ROOT=C:\cmder (your path to cmder) | |
"%CMDER_ROOT%\vendor\init.bat" | |
<------- | |
vscode.settings | |
-------> | |
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe", | |
"terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vscode.bat"] | |
<------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment