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}'
Extract an ADB (Android) backup
dd if=<backup.adb> bs=1M skip=24 iflag=skip_bytes| pigz -dz | tar xv

Last posts

Updating Thinkpad X61 BIOS


WARNING 1: the update is done at your own risk and may brick your computer.

WARNING 2: this will wipe all data on the target USB device.

WARNING 3: do not use SYSLINUX MEMDISK driver to boot it directly with eg. Grub. The Lenovo BIOS updater use the …

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

Where IFNAME is the interface name. For example:


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 …