My 404s Don't code and drive


How to clear the terminal buffer

Sometimes you wan to start over in the terminal. On OSX on your Mac there is a convenient shortcut: cmd+k. This will clear your scroll buffer. In Ubuntu there is no such shortcut. What you can do clear and reset the scroll-back is to write

clear && printf '\e[3J'

Of course we can add an alias to our .bashrc so that we can just write, for example, ccc

alias ccc="clear && printf '\e[3J'"

When Debugging With LLDB and CMake Make Sure to Turn of Optimization

When debugging C++ using LLDB from the command line. It seems you have to put


Just removing optimization flags and writing


in the CMakeLists.txt does not seem to do the trick when there are underlying CMakeLists.txt hierarchies or some other parameters. Nevertheless, by using the DCMAKE_BUILD_TYPE parameter you get access to the otherwise, by optimization, hidden variables.

Ubuntu Terminal Open Command

On OSX one can use the open command in the terminal to open a document using its associated program. Running open on a pdf file will open it using Preview. On Ubuntu the corresponding command is xgd-open. It is cumbersome to write that over and over again but we can add an alias in the .bashrc file

alias o="xdg-open"

If we, for example, want to open a pdf file we can write

o mydocument.pdf

Concatenating Numpy Vectors Stored In Files

Sometimes you have vectors or matrices stored in files, and you need to read them and concatenate them. One way of doing this is reading them into a list and then using Numpy’s hstack or vstack to create the vector or matrix. Like this for concatenating rows

result = np.hstack([np.genfromtxt(fName,delimiter=";") for fName in fList])

where the read matrix or vector all are of size MxNf, that is the rows, M, are the same across all read matrices while Nf can vary. The same goes for vertical stacking but then the sizes are reversed, that is, NfxM, and we have,

result = np.vstack([np.genfromtxt(fName,delimiter=";") for fName in fList])

Batch Resize Images With Padding

ImageMagick comes with a tool to perform batch image transforms, it is called mogrify. To perform a resize of a set of images keeping the aspect ratio and padding with a white background we can use the following command,

mogrify -resize 100x100 -background white -gravity center -extent 100x100 -path ./resize_directory *.png

This command resizes all png images in the directory to a 100x100 and pads with white to keep the aspect ratio.