Skip to content

Instantly share code, notes, and snippets.

View schnell18's full-sized avatar

Justin Zhang schnell18

View GitHub Profile
@schnell18
schnell18 / burn-boot-drive-usb.sh
Created January 27, 2024 01:51
make bootable usb drive
sudo dd if=xxx.iso of=/dev/sdX bs=4M conv=fsync oflag=direct status=progress
@schnell18
schnell18 / pip_mirror.sh
Last active January 19, 2024 10:53
setup pip mirror in China
mkdir ~/.pip
cat <<EOF > ~/.pip/pip.conf
[global]
trusted-host = mirrors.aliyun.com
index-url = http://mirrors.aliyun.com/pypi/simple
EOF
@schnell18
schnell18 / install-pyenv-python-deps.sh
Last active January 9, 2024 13:28
install pyenv on ubuntu 20 and dependencies
curl https://pyenv.run | bash
sudo apt install -y \
wget \
build-essential \
libreadline-dev \
libncursesw5-dev \
libssl-dev \
libsqlite3-dev \
tk-dev \
libgdbm-dev \
@schnell18
schnell18 / check_cert.sh
Created January 2, 2024 02:29
Examine SSL certificate
openssl s_client -connect www.example.com:443 </dev/null 2>/dev/null | openssl x509 -inform pem -text
@schnell18
schnell18 / consistent_harshing.md
Last active December 26, 2023 04:23
consistent hashing

gist of consistent hashing

Resolve rebalance problem of dynamic cluster. Key techniques:

  • determine hash space, eg 2 * PI or 16K like redis
  • map keys and nodes to the same hash space using hash function(s)
  • keys are placed on the first node with hash value greater than the key, or on the first node
  • use binary search tree to speed up locating the node for a paticular key
  • when new node joins, move keys with hash value smaller than the new node from its successor to the node
  • when existing node leaves, move keys on this node to its successor
@schnell18
schnell18 / create_chrootjail.sh
Created November 3, 2013 05:23
Script to automate the creation of chroot jail w/ minimal executables to run git.
#!/bin/sh
# script to automate the creation of chroot jail
# w/ minimal executables to run git
export CHROOT=/var/chroot
function copy_binary() {
for i in $(ldd $*|grep -v dynamic|cut -d " " -f 3|sed 's/://'|sort|uniq)
do
cp --parents $i $CHROOT
@schnell18
schnell18 / remove_original.sh
Created August 27, 2014 14:19
Remove backup branches created by git filter-branch
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
@schnell18
schnell18 / script_visudo.sh
Created March 12, 2015 02:26
Sample for run visudo from script. It grants user "xxx" and "yyy" full sudo privilege by append two lines to end of /etc/sudoers
cat <<EOF | (EDITOR="tee -a" visudo)
xxx ALL=(ALL) NOPASSWD: ALL
yyy ALL=(ALL) NOPASSWD: ALL
EOF
@schnell18
schnell18 / make_crt_test.sh
Last active April 1, 2023 06:03
Generate a 2048-bit RSA key, create certificate sign request and self-sign the certificate for testing purpose
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
@schnell18
schnell18 / get_scriptpath.sh
Created February 26, 2014 03:26
Get absolute script path regardless how it is called in bash. Reference: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SCRIPTPATH=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)