Skip to content

Instantly share code, notes, and snippets.



Last active Jan 6, 2020
What would you like to do?


  • Revert commit (not pushed):
git commit -m "Something terribly misguided"
git reset HEAD~
<< edit files as necessary >>
git add .
git commit -c ORIG_HEAD
  • Revert commit (pushed): git revert COMMIT_NUM
  • Checkout file from master to reset (not commited!):
git reset HEAD filename // if added to index already
git checkout -- filename
  • Add tag (to existing commit):
git tag v1.0 ec32d32
git push origin --tags
  • Cherry-pick:
# checkout target to branch
git cherry-pick <hash0> [<hash1>, <hash2>, ...]
# if its a merge request
git cherry-pick -m 1 <hash>
# after resolving conflicts
git cherry-pick --continue
# or
git cherry-pick --abort
  • remove file from added git reset path/to/file or all git reset


  • get hdd free space df -h
  • get folders size du -h --max-depth=1 | sort -hr
  • check ports in use sudo netstat -plnt
  • check specific port in use and kill process:
lsof -i:8080
kill $(lsof -t -i:8080) # or kill -9 $(lsof -t -i:8080)
  • tar / untar:
# z=gzip, c=create, x=extract, v=verbose, f=next arg is filename
tar zcvf myfiles.tar.gz mydirectory/
tar zxvf myfiles.tar.gz
  • Infinite curl:
while true; do curl -I -H Host:whoami.docker.localhost localhost:80; sleep 0.5; done
# to output just specific data add %{} params (params may vary, google it)
while true; do curl -s -o /dev/null -w "%{http_code} %{time_total}\n" -H Host:whoami.docker.localhost localhost:80; sleep 0.5; done
  • Check if remote port is open:
# outputs 1 = closed, 0 = open
nc -z -w 1 pg-svc-master 5432 &> /dev/null; echo $?
  • Install / uninstall JDK on linux

    • install
      sudo add-apt-repository ppa:webupd8team/java
      sudo apt-get update
      sudo apt-get install oracle-java8-installer // or java7, or java9
    • remove
      sudo apt-get remove oracle-java8-installer
      sudo apt-get purge oracle-java8-installer
      sudo apt-get autoremove
  • Postman

    • install
      # If upgrading, remove first
      # sudo rm -rf /opt/Postman
      wget -O postman.tar.gz
      sudo tar -xzf postman.tar.gz -C /opt
      rm postman.tar.gz
      sudo ln -s /opt/Postman/Postman /usr/bin/postman
    • desktop entity
      cat > ~/.local/share/applications/postman.desktop <<EOL
      [Desktop Entry]
  • convert image files format: mogrify -format jpg /path/*.png

  • Chrome

    • check repo list: cat /etc/apt/sources.list.d/google-chrome.list
    • update to latest: sudo apt-get --only-upgrade install google-chrome-stable
  • base64 encoding without new line character:

    echo -n "client:secret" | base64
  • generate self-signed cert for localhost:

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
  • install nfs
sudo apt install nfs-kernel-server
sudo mkdir -p /srv/nfs
sudo chown nobody:nogroup /srv/nfs
sudo chmod 777 /srv/nfs
sudo vi /etc/exports -> add:
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
sudo ufw allow from [clientIP or clientSubnetIP] to any port nfs
  • connect to nfs
sudo apt-get update && sudo apt-get install nfs-common -y
sudo mkdir -p /mnt/nfs_porky
sudo mount /mnt/nfs_porky/
  • generate random password: date | md5sum
  • run as user:
su -l www-data -s /bin/bash
# or
sudo su -l www-data -s /bin/bash
  • CPU load:
# load (run as many time as needed or for each core):
yes > /dev/null &
# stop:
killall yes

Linux SSH and friends

generate new key: ssh-keygen -t rsa -b 4096 -C ""

copy key to server ssh-copy-id -i ~/.ssh/ USER@SERVER

scp using pub key

# -P is optional (if using non-standard 22 port)

ssh without adding to known_host file:

ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@host
ssh -o UserKnownHostsFile=/dev/null user@host

ssh master check: ssh -O check

ssh master stop: ssh -O exit

run command without evaluating variables (use \$): ssh user@host echo \$var

tunnel to url from remote host: ssh -L 10000: sshHost then open in browser https://localhost:10000

Postman uninstall:

sudo rm -rf /opt/Postman
sudo rm -rf ~/.config/Postman
sudo rm ~/.local/share/applications/postman.desktop


generate .pem from .p12:

# create request to CA (from keychain)
# import received x501 cert to keychain
# export cert from keychain (not private key), this will generate p.12 file
openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts

brew uninstall / install

/usr/bin/ruby -e "$(curl -fsSL"
/usr/bin/ruby -e "$(curl -fsSL"

Mouse speed:

defaults write -g -float 10.0 # LOGOUT after!
defaults read -g

Postman Uninstall:

sudo rm -rf ~/Applications/
sudo rm -rf ~/Library/Application\ Support/Postman
sudo rm ~/Library/Preferences/com.electron.postman.helper.plist
sudo rm ~/Library/Preferences/com.postmanlabs.mac.plist


headless setup:

# SSH:
touch /media/alexey/boot/ssh
# wifi
vi /media/alexey/boot/wpa_supplicant.conf
# add to file:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


#static ip
sudo nano /etc/dhcpcd.conf
# add:
interface wlan0
static ip_address=
static routers=
static domain_name_servers=

disable swap file:

sudo swapon --summary

sudo dphys-swapfile swapoff && \
  sudo dphys-swapfile uninstall && \
  sudo update-rc.d dphys-swapfile remove

docker install:

sudo apt update && \
sudo apt-get install apt-transport-https ca-certificates software-properties-common -y && \
curl -sSL | sh && \
sudo usermod pi -aG docker


get list of tags for image: wget -q -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'

to use in terminal like: dgt node add to .bashrc:

dgt() {
  wget -q$1/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'

stop all containers:
docker kill $(docker ps -q)

stop and remove container by name
docker rm $(docker stop $(docker ps -a -q --filter "name=NAME_HERE" --format="{{.ID}}"))

remove all containers
docker rm $(docker ps -a -q)

remove all unused (<none>) images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

quick aliases for 2 above

### Aliases
alias dic="docker rmi $(docker images --filter "dangling=true" -q --no-trunc)"
alias dcc="docker rm $(docker ps -a -q)"

remove all docker images
docker rmi $(docker images -q)

remove all docker volumes
docker volume rm $(docker volume ls -qf dangling=true)

delete all images with "engage-yag" in name
docker images | awk '$1 ~ /engage-yag/ { print $3 }' | xargs docker rmi**

update docker
> dpkg -l | grep docker

ii lxc-docker 1.3.2 amd64 Linux container runtime
ii lxc-docker-1.3.2 1.3.2 amd64

Then: apt-get remove --purge lxc-docker lxc-docker-1.3.2 Then install as ususal: sudo apt-get install docker-engine sudo service docker start


Update CLI: pip install awscli --upgrade --user

Get availability zones: aws ec2 describe-availability-zones --region us-west-2


create jacoco coverage report: mvn jacoco:report then go to target/site/jacoco/index.html

force to update deps: mvn clean install -U


list global packages: npm ls -g --depth 0

nvm intall latest lts: nvm install --lts

nvm set default by version: nvm alias default 8.12.0

nvm set default lts: nvm alias default lts/*

express.js enable cors:

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', '*');
  // OR 
  // res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');

get package version in bash: $(node -p "require('./package.json').version")


ternary command && echo "OK" || echo "NOK" or assign value [ $valid ] && x=1 || x=0


copy secret kubectl get secret gitlab-registry -n=zeta --export -o yaml | kubectl apply -n=alpha -f -


center content in div vertically:

    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;

body, html{

<div class="container">
    <div>Div to be aligned vertically</div>

VS code

launch.json for chrome debugging with webpack:

// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit:
  "version": "0.2.0",
  "configurations": [
      "type": "chrome",
      "request": "attach",
      "name": "Attach to Chrome",
      "port": 9222,
      "webRoot": "${workspaceRoot}",
      "sourceMapPathOverrides": {
          "webpack:///./*":   "${webRoot}/*"
      "disableNetworkCache": true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment