Skip to content

Instantly share code, notes, and snippets.

@zzhuolun
Last active December 16, 2024 11:33
Show Gist options
  • Select an option

  • Save zzhuolun/7d4dd84b74a583b167352d375cc76393 to your computer and use it in GitHub Desktop.

Select an option

Save zzhuolun/7d4dd84b74a583b167352d375cc76393 to your computer and use it in GitHub Desktop.
Bash Script Collections

set brightness of a selected display

#!/bin/bash
# --- set your monitor below
if [ $1 -eq 0 ]
then 
  monitor=DP-3
elif [ $1 -eq 1 ]
then
  monitor=HDMI-0
else
  echo "Display selection should be either 0 or 1"
fi
xrandr --output $monitor --brightness $2
echo "$monitor brightness set to $2"
# ---

set monitor positions

xrandr

xrandr --output DP-4 --left-of DP-2

xrandr --output DP-4 --below DP-2

Copy all the images from X/[a-z]{8}/image/[0-9]{4}.png to Y/[a-z]{8}_[0-9]{4}.png

e.g From X/abcdefgh/0001.png to Y/abcdefgb_0001.png, [a-z]{8} are in a list selected.lst

for i in $(seq -f "%04g" 0 23)
do
  cat selected.lst | xargs -n1 -i cp X/{}/image/$i.png Y/{}_$i.png
done

Use tmux to start multiple tasks in parallel

#!/bin/bash
for i in {1..5};do
    tmux new-session -d -s "session_$i" "python XXX"
done  
tmux detach-client

Pdf editing

crop pdf pages:

krop

merge pdfs:

pdfunite input1.pdf input2.pdf output.pdf

or

pdftk intput1.pdf input2.pdf output output.pdf

manipulating pages:

pdftk A=intput1.pdf B=intput2.pdf C=input3.pdf cat A1-6 B A7-10 C A11 output output.pdf

Remove page 4: pdftk input.pdf cat 1-3 5-end output output.pdf

convert images to pdf

convert -page a4 -rotate -90 intput.jpg output.pdf

Image and video processing

cut video snippet

ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 -c copy output.mp4

resize video

ffmpeg -i intput.MP4 -vf "scale=iw/2:ih/2" -c:a copy downsampled.mp4

resize image

convert input.jpg -resize 25% output.jpg

stack image

horizontally: convert +append input1.jpg input2.jpg joined.jpg

vertically: convert -append input1.jpg input2.jpg joined.jpg

Others

grep -nr --include '*.py' PATTERN

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