Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
UNIX tips

git

diff between 2 commits

git diff -w <commitA>..<commitB> path/to/*.html
  • NB1: git log to grab <commitN>
  • NB2: -w for ignoring whitespaces changes

chmod

find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;

rsync 2 folders

rsync -av --delete --exclude .git --exclude .DS_Store folderA/ folderB/

or

rsync -av --delete --exclude .git --exclude .DS_Store ~/Sites/quick-front/dist/ dev@5emeg.com:/home/projects/www/quick-front/web/

.bash_profile

# Path
PATH=${HOME}/bin:${PATH}

# Editor
export EDITOR='subl -w'

git tag

<increment package.json.version>
git add package.json
git commit -m "bump version"
git tag v0.1.4
git push --tags

npm private dependency

...
"dependencies": {
  "myprivaterepo": "git+ssh://git@github.com/abernier/myprivaterepo.git#v0.1.4"
}

convert a multi-pages PDF to images

first install imagemagick:

brew install imagemagick
brew install ghostscript
brew link --overwrite ghostscript
brew reinstall imagemagick --build-from-source

then:

convert -alpha off -density 300 -depth 8 pages.pdf -resize 25% -background white -quality 95 pages_%02d.jpg
montage -mode concatenate -tile 2x pages_*.jpg pages.jpg

install rbenv

brew install rbenv ruby-build

Then add eval "$(rbenv init -)" line to your ~/.bash_profile

Then :

source ~/.bash_profile

rbenv install -l
rbenv install 2.1.1
rbenv global 2.1.1
rbenv version
2.1.1 (set by /Users/antoinebernier/.rbenv/version)

create a file

cat <<EOF > hi.txt
hi,
there!
EOF

Test gzip compression (outputs bytes)

gzip -c filename.min.js | wc -c

Exec amélioré (le nom du fichier est transmis à xargs et dispo sous $0 dans la commande sh)

find . -name "*.txt" -print0 | xargs -0 -I '{}' sh -c 'echo $0' '{}'

ffmpeg

On mac : brew install ffmpeg --devel --with-libvpx b--with-fdk-aac

WebM (2 passes)

ffmpeg -i input_file.avi -codec:v libvpx -vf scale=1280:-1 -quality good -cpu-used 0 -b:v 1000k -qmin 10 -qmax 40 -maxrate 1000k -bufsize 2000k -threads 0 -an -pass 1 -f webm
 /dev/null

ffmpeg -i input_file.avi -codec:v libvpx -vf scale=1280:-1 -quality good -cpu-used 0 -b:v 1000k -qmin 10 -qmax 40 -maxrate 1000k -bufsize 2000k -threads 0 -codec:a libvorbis -b:a 128k -movflags faststart -pass 2 -f webm output.webm

h.264 (2 passes)

ffmpeg -i input_file.avi -codec:v libx264 -vf scale=1280:-1 -quality good -cpu-used 0 -b:v 1000k -qmin 10 -qmax 40 -maxrate 1000k -bufsize 2000k -threads 0 -an -pass 1 -f mp4 /dev/null

ffmpeg -i input_file.avi -codec:v libx264 -vf scale=1280:-1 -quality good -cpu-used 0 -b:v 1000k -qmin 10 -qmax 40 -maxrate 1000k -bufsize 2000k -threads 0 -codec:a libfdk_aac -b:a 128k -movflags faststart -pass 2 -f mp4 output.mp4

rotate

ffmpeg -i in.mov -vf "transpose=1" out.mov

with:

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

see: http://stackoverflow.com/a/9570992/133327

crop

ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4

with:

  • out_w -- width of the output rectangle
  • out_h height of the output rectangle
  • x, y -- top left corner of the output rectangle

see: http://video.stackexchange.com/a/4571

scale

ffmpeg -i in.avi -vf scale=320:-1 out.avi

see: https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg

trim

without re-encoding

ffmpeg -i in.mp4 -vcodec copy -acodec copy -ss 00:01:00.000 -t 00:00:10.000 out.mp4

with:

  • -ss -- start time
  • -t -- duration

see: https://vollnixx.wordpress.com/2012/06/01/howto-cut-a-video-directly-with-ffmpeg-without-transcoding/

screenshot

ffmpeg -i in.mp4 -ss 00:00:05.000 -vframes 1 out.png

or in JPG

ffmpeg -i in.mp4 -ss 00:00:05.000 -vframes 1 -q:v 1 out.jpg

q:v between 1 and 31 (1 being the highest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment