Shiny new tricks

This commit is contained in:
lhark 2020-11-11 04:00:49 +01:00
parent 24db58420f
commit 921d9c6c97

78
how_to
View file

@ -218,6 +218,8 @@ PDF :
Extract pages : Extract pages :
pdftk input.pdf cat <range> output out.pdf pdftk input.pdf cat <range> output out.pdf
# range can be <start>-<end>, more info at pdftk --help # range can be <start>-<end>, more info at pdftk --help
Uncompress pdf file content :
pdftk input.pdf output output.pdf uncompress
Add images and other files in a single pdf: Add images and other files in a single pdf:
convert [jpg|png|txt|pdf|...] output.pdf convert [jpg|png|txt|pdf|...] output.pdf
# Might need to tweak /etc/ImageMagick-7/policy.xml # Might need to tweak /etc/ImageMagick-7/policy.xml
@ -225,6 +227,8 @@ PDF :
Fill form & annotate: Fill form & annotate:
For well formatted interactive forms: For well formatted interactive forms:
evince evince
For Adobe type forms (AcroForm / XFA):
pdfjs # (supports forms since 2.6.347 / firefox 81)
For non-interactive PDF: For non-interactive PDF:
xournal xournal
libreoffice Draw libreoffice Draw
@ -370,6 +374,16 @@ Video and audio editing:
xdotool selectwindow getwindowgeometry | awk '/Position/{printf $2" "$4" "} /Geometry/{printf $2" "}' | sed 's/)//' | read OFFSET SCREEN SIZE; ffmpeg -video_size $SIZE -framerate 30 -f x11grab -i "$DISPLAY.$SCREEN+$OFFSET" -vf "scale=2*trunc(iw/2):-2,setsar=1" -pix_fmt yuv420p out.mp4 xdotool selectwindow getwindowgeometry | awk '/Position/{printf $2" "$4" "} /Geometry/{printf $2" "}' | sed 's/)//' | read OFFSET SCREEN SIZE; ffmpeg -video_size $SIZE -framerate 30 -f x11grab -i "$DISPLAY.$SCREEN+$OFFSET" -vf "scale=2*trunc(iw/2):-2,setsar=1" -pix_fmt yuv420p out.mp4
Filter doc: Filter doc:
# https://trac.ffmpeg.org/wiki/FilteringGuide # https://trac.ffmpeg.org/wiki/FilteringGuide
Create captioned gif from mp4:
# https://nickcanzoneri.com/ffmpeg/gif/2018/11/20/captioned-gifs-with-ffmpeg.html
# https://stackoverflow.com/a/14283648 // recale
# https://video.stackexchange.com/a/20106 // font style
text.srt:
1 # Sequence number
00:00:00,000 --> 00:00:01,900 # Start and end timestamps
Your text here # Actual text
# Mandatory empty line
ffmpeg -i in.mp4 -vf "scale=512:-2:flags=lanczos,split[x][z];[z]palettegen[y];[x][y]paletteuse,subtitles=text.srt:force_style='FontName=Oswald,Fontsize=80,FontWeight=Bold'" -r 10 out.gif
ImageMagick: ImageMagick:
crop to aspect ratio crop to aspect ratio
@ -402,13 +416,23 @@ Mount as user:
sudo chown <user> /mnt sudo chown <user> /mnt
Borg backup: Borg backup:
borg init --encryption=repokey-blake2 </repo> # Example repo: /mnt/<machine>/home
borg create -v --stats --progress --compression zlib "/mnt/<machine>/home/::{now}" /home/<user> # Dry run: -n
# Avoid mixing users in single repo (don't create archives from different users in a single repo)
[sudo] borg init --encryption=repokey-blake2 </repo>
borg create -v --stats --progress --compression zlib --exclude ~/.local/share/Steam "</repo>::{now}" /home/<user>
sudo borg create -v --stats --progress --compression zlib "</repo>::etc-{now}" /etc
sudo borg create -v --stats --progress --compression zlib --exclude /var/cache --exclude /var/tmp "</repo>::var-{now}" /var
borg list </repo> borg list </repo>
borg check --verify-data --progress </repo> borg check --verify-data --progress </repo>
borg mount </repo> </mount> borg mount </repo> </mount>
borg prune -v --list --keep-daily=7 --keep-weekly=4 --keep-monthly=6 </repo> borg prune -v --list --keep-daily=7 --keep-weekly=4 --keep-monthly=6 </repo>
# Restoring
borg list </repo>
borg mount </repo>::"<name>" /mnt/borg
borg umount /mnt/borg
Serial terminal Serial terminal
st -l /dev/ttyUSB0 <baud> st -l /dev/ttyUSB0 <baud>
@ -564,6 +588,8 @@ Maildir tweaking:
for f in new/*; do mv "$f" "cur/${f##*/}:2,S"; done for f in new/*; do mv "$f" "cur/${f##*/}:2,S"; done
# ${f##*/} removes path prefix. # ${f##*/} removes path prefix.
# ":2,S" is a maildir suffix (S=seen) # ":2,S" is a maildir suffix (S=seen)
Cleanup maildir folder after messing around (requires mblaze):
mlist <folder> | mrefile <folder>
Install 64 bits kernel on 32 bits system (and 64 bits hardware) (bad idea) Install 64 bits kernel on 32 bits system (and 64 bits hardware) (bad idea)
wiki.archlinux.org/index.php/Migrating_between_architectures wiki.archlinux.org/index.php/Migrating_between_architectures
@ -892,3 +918,51 @@ MacOS survival guide (Because the "user friendly" OS has worse affordances than
Release <Alt> Release <Alt>
Maximizing window WITHOUT fullscreen Maximizing window WITHOUT fullscreen
Double click window title bar Double click window title bar
Mounting .bin/.cue image files:
$ sudo pacman -S bchunk
$ bchunk file.bin file.cue output
$ sudo mount output01.iso /mnt -o loop,ro
Manual IMAP connection:
# https://www.atmail.com/blog/imap-101-manual-imap-sessions/
# https://stackoverflow.com/questions/14959461/how-to-talk-to-imap-server-in-shell-via-openssl
$ openssl s_client -connect <imap server>:993 -crlf [-quiet]
$ openssl s_client -connect <imap server>:143 -crlf -starttls imap [-quiet]
# IMAP needs an incrementing prefix before each command
A1 login <login> "<password>"
# list everything
A2 list "" "*"
# list everything under a particular prefix
A3 list "INBOX" "*"
A99 logout
gdb tricks:
Easily print attributes of array elements:
# https://agateau.com/2008/gdb-trick-the-poor-man-loop
(gdb) set $pos = 0
(gdb) print foo[$pos++].attribute
(gdb) <enter>
(gdb) <enter>
...
Or use a real loop:
(gdb) set $i = 0
(gdb) while ($i < <length>)
> print foo[$i++].attribute
> end
Non-standard zsh cd trick:
# https://dataswamp.org/~solene/2020-09-04-cd-command.html
$ pwd
/tmp/pobj/foobar-1.2.0/work
$ cd 1.2.0 2.4.0
/tmp/pobj/foobar-2.4.0/work
Check for available package updates with Arch/Artix:
sudo pacman -S pacman-contrib
checkupdates
Git push and pull using different URL/protocols:
# https://www.scivision.dev/git-pull-https-push-ssh/
git config url."git@example.org:user/".pushInsteadOf "https://example.org/user/"