Skip to content

Instantly share code, notes, and snippets.

@DmitryKorlas
Last active June 30, 2021 11:30
Show Gist options
  • Select an option

  • Save DmitryKorlas/f5c224d2b72129cd4fde to your computer and use it in GitHub Desktop.

Select an option

Save DmitryKorlas/f5c224d2b72129cd4fde to your computer and use it in GitHub Desktop.
Few commands for regular work (^.^) (`-`) (*.*)

Find legacy chains in code

This oneliner solve the following task. Say we know the list of methods which usages was modified in code.
OldLib.packageFoo.bar.methodBuz(); or AnotherLib.foo.methodBar(); was replaced to new call NEW.static.methodBuz() and NEW.static.methodBar(). We have a long list of methods in targets.sorted.txt and we would like to check if there are no old calls left on our large codebase.

$ cat /tmp/targets.sorted.txt
methodBuz
methodBar
$ cat /tmp/targets.sorted.txt | xargs -I {} sh -c "grep --include=\*.js -Ri -E 'NEW[a-zA-Z0-9.]+[^c]\.{}\(' ./"

Find all files which contains at least 2 words "class"

$ for file in `find ./src/my/dir -type f | grep -E "\.ts|js"`; do if [ "$(grep -c "class " "${file}")" -gt 1 ]; then echo "${file}"; fi; done

Check if port is open on remote machine

$ nc -zvw3 192.168.1.5 8080

Backup remote folder to the local tar.gz

$ ssh myuser@192.168.0.10 "tar --exclude='cache*' --exclude='temp*' -cz  ~/some/folder" > folder.tar.gz

in case of you don't want to have /home/myuser as part of path in unpacked folder, consider use this one:

$ ssh myuser@192.168.0.10 "cd ~/some/ && tar --exclude='cache*' --exclude='temp*' -cz  ./folder" > folder.tar.gz

Python shebang line

including # character

#! /usr/bin/env python

Activate/Deactivate virtualenv

$ mkdir my-project
$ cd my-project
$ virtualenv py3 -p $(which python3)
$ source ./py3/bin/activate
$ python --version
$ deactivate
$ python --version

Re-format js via prettier

$ find ./src -type f | grep .js | xargs -I {} sh -c "./node_modules/.bin/prettier-eslint --no-bracket-spacing --print-width=120 --tab-width=4 --single-quote --write {}"

Copy/Paste (clipboard) in terminal

$ cat myfile.txt | xclip -selection clipboard
$ xclip -o

Monitor website response time

$ for i in {1..10} ; do sleep 5; echo -ne "`date`\t: "; { time wget -U "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" -O /dev/null google.com;} 2>&1 | grep real ; done

Output a count of SQL queries for the last connection

$ cat /var/log/mysql/mysql.log | grep -o "`tail /var/log/mysql/mysql.log -n 1 | grep -oP "\d+"` " | wc -l

Remove babel autogenerated files (.js, .js.map)

$ find . -type f -name *.es6 | grep -o -P ".+(?=.es6)" | xargs -I {} sh -c "rm {}\.js*"

Run local script on remote machine via ssh

$ ssh dk@hostname "sh" < ./task.sh

Run local script on remote machine via ssh (use script arguments)

$ ssh dk@hostname "sh -s 'hey, this is first argument for task.sh' 'second arg'" < ./task.sh

Renew .bashrc variables in active terminal session

$ source ~/.bashrc

Generate sequence of formatted numbers

$ for i in $(seq 100); do printf "+1 800 1%07d\r\n" $i ;done > /tmp/numbers-100.txt

create public key from private

$ ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub

generate a fixed-size file

# contains binary
$ dd if=/dev/zero of=file-19mb.dat bs=19M count=1

# contains random numbers
$ tr -c "[:digit:]" " " < /dev/urandom |head -c 10m > test.10m.txt

rotate video (ffmpeg)

$ ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4

rotate video (handbrake)

$ HandBrakeCLI -i rotated.mp4 -o re-rotated.mp4 --rotate="angle=90:hflip=0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment