Useful commands, one-liners, etc.


I decided to record here useful bash fragments, commands, etc. I kept using and forgetting from time to time... I will enrich it as needed. There is no particular order nor specific explanation. Some might be useful to others. Maybe. Who knows.

Arbitrary file binary dump into C array

To include any file content directly into C arrays.

hexdump -v -e '/1 "0x%02x,"' input
Extract some pages from a PDF into a different PDF

Eg. save some articles from a magazine.

pdfjam -o pages_73-98.pdf original.pdf 73-98
Reduce (compress) the size of a PDF
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Add an empty audio track to a video

Useful to display video on "smart" TV w/o annoying "unsupported audio track" message.

ffmpeg -f lavfi -i anullsrc -i input -shortest -c:v copy -strict -2 -c:a aac output
Compress a video taken from your smartphone, striping the audio

To share over email.

ffmpeg -y -i input -c:v libx264 -preset slow -b:v 300k -vf scale=640:-1 -pass 1 -c:a copy -f mp4 /dev/null && ffmpeg -i input -c:v libx264 -preset slow -b:v 300k -vf scale=640:-1 -pass 2 -an output.mp4
Extract a RPM content into the local directory
rpm2cpio input.rpm | cpio -idmv
Prepare a patch serie from git to send
git format-patch --to=list@list --from --cover-letter -s --thread --subject-prefix="PREFIX" sha1
tar all files under git version control
(PREFIX="$(basename $(readlink -f .))-$(git describe --all --exclude '*' --always --dirty)"; git archive --format=tar.gz --prefix="$PREFIX/" -o "$PREFIX.tar.gz" HEAD)
Monitor consumed DDR bandwidth every seconds (Intel IMC HW counters)
LC_ALL=C perf stat $(perf list|awk '/uncore_imc.*(read|write)/{printf " -e %s", $1}') -a -B -I 1000 2>&1|stdbuf -oL awk '/#/{next}$1!=t{t=$1;if(s)print s;s=0}{s+=$2}'

Last posts

128-bits multiply with NumPy

128-bits multiply

For another on-going project, I needed to do 64-bits x 64-bits to 128-bits multiply, and I needed it in Python. When doing numerical work with Python, I always use NumPy which is a really awesome library. Unfortunately NumPy is heavily biased towards hardware native types, which makes sense …

Force NetworkManager to ignore an interface

Continuing my Bookmarks serie, here is how to tell NetworkManager to not manage an interface, thank you very much:

~# sudo cat >> /etc/NetworkManager/NetworkManager.conf << EOF
plugins+=keyfile
[keyfile]
unmanaged-devices=interface-name:IFNAME
EOF

Where IFNAME is the interface name. For example:

unmanaged-devices=interface-name:eth0

Will prevent NetworkManager to manage eth0 …

X11 forwarding request failed on channel 0

A quick post as a reminder to my future self: if ssh does not want to forward X11 despite using -X or -Y options, it might be because I am missing Xauth installed:

~local# ssh -YC remote
X11 forwarding request failed on channel 0
Last login: Tue Apr 26 09 …

Amazon Interview Coding Challenge

My Amazon interview

Quite some time ago, I was contacted by Amazon for a position in the AWS DNS team. I was curious to hear more about it and agreed to enter their recruitment process. The 1st step was a coding challenge.

In this post I will described the challenge …

Non-square matrix in-place transpose

Saving memory through in-place transpose

I recently came across an interesting problem at work: how to efficiently transpose a non-square matrix in-place?

One of my colleague is working on optimizing a six-steps FFT on our manycore processor, the MPPA-256. The six-steps FFT algorithm has a lot of nice properties, especially …