Tuesday, August 26, 2014

KDE Dolphin integrated konsole

Just by accident I hit the "f4" key while in Dolphin and by that discovered a very useful feature:
A konsole window (size adjustable) will appear at the bottom part of the Dolphin window with $PWD set to the directory currently visited by Dolphin.


Friday, August 8, 2014

Developing Java using Emacs

As you might know, I recently started writing code in Java. For the time being, I ditched Emacs (only for Java!) and used Eclipse instead. However, I just came across this blog post, which gives detailed instructions on how to use emacs-eclim for obtaining Eclipse functionality in Emacs. Thanks to that, I can now switch back to Emacs for good!

Monday, July 21, 2014

git: permanently purge file/folder from git repo including history

My config repo suffered from being too large after I had dumped my ~/.config directory into it. At some time I decided, that storing my ~/.config directory in a non-selective manner is pointless and and removed the .config directory from my config repo. However, the repo remained rather large (.git directory was 107MB, total repo size, including .git, 110MB), as both adding and removing the .config directory made fat commits.

Following this blog post, I was able to shrink my repo size from 110MB to 3.8MB, .git directory went from 107MB to 1.3MB. In addition to instructions on how to cleanup your repo history, the blog post also provides a script for finding big files in your repository, which was not necessary for me as I knew the location of the files/directory to be deleted.

A short summary of what I did, so you do not need to go through the complete blog post (Following these instructions will lead to irreversible changes in your commit history and potentially to unwanted loss of data. Only apply when you are 100% sure that you know what you are doing):

$ git filter-branch --tree-filter 'git rm -rf .config --ignore-unmatch' HEAD
$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --aggressive --prune=now
$ git push origin master --force

Saturday, July 19, 2014

Bios Update Lenovo X1 Carbon

I finally fixed the closing lid issue of my Lenovo X1 Carbon (2nd gen). I had known the solution to it for a while, which is a BIOS update. While they offer an update utility for Windows, they also offer an iso image of the BIOS update. Supposedly, if you burn the iso image on a CD or DVD, they should be auto-bootable. However, the X1 Carbon does not have an optical drive, thus i tried to generate a bootable USB drive

beethoven:~:% dd if=gruj11us.iso of=/dev/sdX

which turned out to be not bootable and thus I let the issue rest for a while.

A couple of days ago I came across this blog post that suggests updating the BIOS using Windows while it's still on the Laptop (didn't work for me apparently) and also mentioned that you could extract the eltorito image from the ISO and create a bootable USB drive from that. Some more googling led to two forum posts that contained a link to a perl script that is exactly doing that.

So all you need to do is

beethoven:Downloads:% wget http://www.uni-koblenz.de/~krienke/ftp/noarch/geteltorito/geteltorito.pl
beethoven:Downloads:% perl geteltorito.pl bios-udpate.iso > bios-update.img
beethoven:Downloads:% dd if=bios-update.img of=/dev/sdX

and then reboot your machine, boot form your USB drive and follow the instructions. Keep in mind that you should not turn off the machine or remove the USB drive during the update!

Wednesday, July 16, 2014

gcc show filename of library

gcc provides the option

 -print-file-name=<library-name>

which is very helpful for debugging linking problems. When invoked with this flag, gcc does not compile/link, but prints the full path that it uses for that library, e.g:

 beethoven:~:% gcc -print-file-name=libvigraimpex.so
 /home/phil/local/lib/../lib/libvigraimpex.so

That way you can easily determine whether or not gcc sees the correct libraries.

Saturday, June 28, 2014

Grouping -exec commands using the find command in shell

I just found out how to group commands that are executed on filenames found by the command line tool find.
The common syntax is:

find <path>[options] -exec command1 \; -exec command2 \;

where command2 is only executed if command1 exits with a zero return value.
While I was using this quite a lot, the actual syntax was not clear to me up to just a couple of minutes ago:

-exec is a find expression and expressions are separated by operators, where a missing operator is interpreted as -a (AND). Furthermore, expressions can be grouped by parentheses, which is especially useful when you want to perform some actions only on some files, but more actions on all of them afterwards.

As an example, take a directory tree with the following structure:
$ find .
.
./arch
./arch/install.log

Then, the following command
$ find . \( \( -exec test -d {} \; -a -exec sh -c 'echo {}; exit 1' \; \) , -exec echo {} \; \)
.
.
./arch
./arch
./arch/install.log

prints every path found by find, and prints it a second time if it is a directory, hence './arch' and '.' are printed twice, respectively, while './arch/install.log' is printed only once.

Step by step, if
-exec test -d {} \;
returns false,
-exec sh -c 'echo {}; exit 1' \;
will not be executed, as both are seperated by the AND (-a) operator. The grouped expression, indicated by parentheses, always returns false, as the second command contains 'exit 1'. Nevertheless,
 -exec echo {} \;
will always be executed, as two expressions separated by the ',' operator will always be executed, returning the outcome of the second expression.

For more information, read the find man pages, in particular sections EXPRESSIONS, ACTIONS and OPERATORS.

Saturday, May 24, 2014

zsh enhanced autocomplete

Just another cool and helpful little zsh thing, I call it "enhanced autocomplete".
This works for any command with positional arguments (just type command [tab]) or with command switches (both - and --, just type command - [tab] / command -- [tab]). You will see the possible options displayed in your terminal. Bash is capable of doing that as well, but you will not see a description for each option and it does not work for short options (single dash). Furthermore, alt + h will route you to the man pages of command, without changing what you typed in the prompt so far (very useful!).

Completion for arguments is especially useful for zsh's cd -n (go back n entries in directory history), where you will see the directory for each an and can choose n appropriately.

Another thing, also related to tab complete, that I found out recently is [shift] + [tab]. This will give you a list of all commands that you can type in your current shell.

Monday, May 19, 2014

Trackpad Lenovo Thinkpad X1 Carbon w/Linux

I just got a new Thinkpad X1 Carbon and wiped Windows in order to install Arch Linux. The trackpad did not work at all out of the box. The only thing that worked was left click (I was not even able to move the mouse with the trackpad; mouse pointer worked, though).

With the help of http://who-t.blogspot.com.au/2014/03/xorg-synaptics-support-for-lenovo-t440.html and http://major.io/2012/12/28/handy-settings-for-the-touchpadclickpad-in-the-lenovo-x1-carbon/ I was able to generate an appropriate config file that allows for two-finger scrolling, as well as left and right click and mouse pointer navigation using the trackpad. The middle button (necessary for mouse pointer scrolling) is still not working. With two-finger scrolling, I do not need any middle button scrolling, though.

config file (90-synaptics-clickpad.conf):
Section "InputClass"
        # from http://who-t.blogspot.com.au/2014/03/xorg-synaptics-sup...
        Identifier                        "ClickPad"
        MatchDriver                       "synaptics"
        Option "HasSecondarySoftButtons"  "on"
        # SoftButtonAreas: right-lrtb middle-lrtb; 0 0 0 0 ...
        Option "SoftButtonAreas"          "50% 0 80% 0 0 0 0 0"
        Option "SecondarySoftButtonAreas" "60% 0 0 10% 40% 60% 0 10%"
        Option "AreaTopEdge"              "10%"
        Option "AreaBottomEdge"           "80%"

        # from http://major.io/2012/12/28/handy-settings-for-the-t...
        Option "TapButton1" "1"
        Option "TapButton2" "3"
        Option "TapButton3" "2"
 Option "VertTwoFingerScroll" "on"
 Option "HorizTwoFingerScroll" "on"
 Option "HorizHysteresis" "50"
 Option "VertHysteresis" "50"
EndSection

In order to install my 90-synaptics-clickpad.conf, just replace root_files (cf github repository direcotry structure) with the root directory "/".

Saturday, April 12, 2014

TikZ: Putting it all together

I have been working on TikZ a bit and finally got a result, which can be used for displaying time series:

Scaling one scope to another scope was key to succeeding with this. In the above image, the circles would be replaced by images of a timeseries, whereas the smaller squares show a more detailed view on the selected region of interest within this image. The only remaining challenge is a way of making the bounding box ignore the fake scope.

The code for above image can be found on github.

Thursday, April 10, 2014

Scale one TikZ scope to the width of another scope

I came across the problem that I needed to have two TikZ scopes scaled to the same width. Apparently, there is no option to scale a scope to an absolute width (or even better to another scope). In general, one could use two separate tikzpictures and use resizebox to get these tikzpictures to the same width. This works well as long as one does not refer to coordinates of one of these two tikzpictures, e.g. in order to draw a line from a node in one of the tikzpictures (or originally scope) to a node in the other one, as resizebox obviously cannot change the coordinates within a tikzpicture.

This problem frustrated me quite a while, but I came up with a somewhat hacky solution today, which includes "manually" determining the ratio of the two scopes in question and scaling one of the scopes accordingly. tex code is included on the corresponding tex.stackexchange post.

In the following image, the original scopes had a ratio as shown in the image and are scaled to the same width. There is no problem with drawing a line from circle1.east to circle2.east, as all scopes are within the same tikzpicture and there cannot be any confusion about the coordinates.

Wednesday, February 12, 2014

C++11: Initialize non-static data members

As I just found out, C++11 allows you to initialize non-static data members. This comes in handy for defining default values for member variables, which can be overridden by specific constructors.
Check out https://blogs.oracle.com/pcarlini/entry/c_11_tidbits_non_static for more details.