[2013-11-17] git commandline completion

The git repo on github has a nice helper function for better tab completion for git. In case you type: git add TAB TAB you get a list of files that changed, or a new in your repo. If there is only one it will auto complete it. To install it copy the git-completion.bash to home folder, or use this code:

wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash \
-O ~/.git-completions.bash

To activate it and test if the completion works now as expected.

. ~/.git-completion.bash

To activate it automatically when you open a terminal.

echo ". ~/.git-completion.bash" >> "~/.bashrc"

[2013-11-17] remove transparent background from pngs with image magick

I created some business cards with inkscape and exported high resolution pngs. But every white spot on the card is transparent. Here is image magick command if you want to get rid of it without adding a white background layer or edit the file by hand with gimp.

convert card.png -flatten card-white.png

If you want to change multiple files in place, just use mogrify:

mogrify -flatten *.png

You can even chose the background color as text -background black or hex value -background "#333" or -background "#fefefe". You have to set the background before you flatten the image.

convert card.png -background "#aaa" -flatten card-gray.png

I found the solution to this problem on stackoverflow.

[2013-11-16] strip color codes with sed

sed -r "s:\x1B\[[0-9;]*[mK]::g" file

I found this solution on commandlinefu

[2013-10-31] Cisco and H.264

I had a bad feeling when i first read that cisco found a loop hole in the licensing of H.264 and will provide binary blobs to firefox so it can be used for webrtc and pay for the fees. There is maximum amount a company have to pay so it seems to be good deal.

Now we should trust cisco that they will not install any back door in the binary blobs for the nsa. Even if there is no back door and the people start to use the patent infected algorithm and cisco decides to stop to pay for the fees, what will happen.

As fefe mention in his blog post it will also destroy the competion for the best/fastest h.264 implementation.

You might also read the blog post of monty the guy behind ogg vorbis and daala.

[2013-10-30] Twitter interview, puddle volume

I stumbled upon this blog post about a programming question for during a twitter interview.

Given this picture of walls with different height:

                 _ _
                |7 7|_
       _        |    6|
      |5|      _|     |
      | |    _|4      |
     _| |  _|3        |
    |2  |_|2          |
    |_ _ 1 _ _ _ _ _ _|
     0 1 2 3 4 5 6 7 8

The representation of this walls is the array [2, 5, 1, 2, 3, 4, 7, 7, 6]. Imagine it will start to rain. How much water would be collected by this walls?

                 _ _
                |7 7|_
       _        |    6|
      |5|~ ~ ~ ~|     |
      | |~ ~ ~|4      |
     _| |~ ~|3        |
    |2  |~|2          |
    |_ _ 1 _ _ _ _ _ _|
     0 1 2 3 4 5 6 7 8

In this case the correct value would be 10. Micheal had a solution that will iterate over each number 2 times. When I read this, I thought it must be possible to do this in just one round trip. And I did.

If you want to try it for yourself, here are some nice test cases that could help you: the tuple has two elements first the array of levels, and then the number of the expected amount of water. In case you find a better/shorter/more elegant solution please comment on my gist or send me an email.

#!/usr/bin/env python
def water(levels):
    # enter your code here
    pass

testcases = [
    ([1,0,1], 1),
    ([5,0,5], 5),
    ([5,0,4], 4),
    ([4,0,5], 4),
    ([4,0,5,0,2], 6),
    ([0,1,0,1,0], 1),
    ([0,1,0,0,1,0], 2),
    ([4,2,2,1,1,1,3], 8),
    ([0,3,2,1,4], 3),
    ([1,0,1,0], 1),
    ([1,0,1,2,0,2], 3),
    ([2,5,1,2,3,4,7,7,6], 10),
    ([5,1,0,1],1),                 # thanks https://news.ycombinator.com/item?id=6640085
    ([2,5,1,2,3,4,7,7,6,3,5], 12), # thanks https://news.ycombinator.com/item?id=6640105
    ([3,0,1,0,2], 5),
]

if __name__ == "__main__":
   for case in testcases:
      w = water(case[0])
      if w == case[1]:
         print "TRUE: %s holds %s" % (case[0], w)
      else:
         print "MISMATCH: %s holds %s (got %s)" % (case[0], case[1], w)

[2013-10-29] Phoneblocks, Motorola Ara

Motorola has now a concept for a modular cell phone. I saw a few months ago the concept of phoneblocks. Their motivation is to build a phone that can be upgraded partially, so you don't have to throw away your phone just because the cpu is too slow now, so you can just exchange the block for the cpu.

If you like the idea and have constructive input, you can give your input to motorola via dscout.

[2013-10-27] Multidesktop tip: Move window to new screen

First you need to install the compizconfig-settings-manager the extra plugins.

sudo apt-get install compizconfig-settings-manager compiz-plugins-extra

Now you can open the settings manager

ccsm

Select Put from the category Window Management. You can also type put in the filter input box to make it easier to find. Enable the plugin. If you click on the name you can also configure it and change the keyboard shortcuts. I use Alt+Super+Right for Put To Next Output.

Now you have to log out and log in again to be able to use the new settings. At least when you installed the extra plugins.

[2013-10-25] use tcpdump on an android phone

I needed to intercept packets that where send by an app to verify that those packets where not malformed. On linux i used wireshark and tcpdump. Since android is a kind of linux i hoped that i might find tcpdump.

You need a rooted device, a terminal emulator and the binary of tcpdump. I am using Cyanogenmod 10.1.3 and therefore the device is allready rooted and they a good terminal emulator preinstalled.

The first step is to get the binary. I took it from this blogpost. Just download this file from your android device. I didn't compile it, so I cannot guarantee you that there are no backdoors or other harmfull stuff added to the source code before. And since you have to run it as root, you should think twice if you want to compile it.

Move the downloaded file to /storage/sdcard0/tcpdump. Then open your terminal and copy paste the following instructions to install the binary. You have to install it again after you update your device. At least after the cyanogenmod update.

su
mount -o remount,rw /system
cp /storage/sdcard0/tcpdump system/bin
cd system/bin
chmod 777 tcpdump
mount -o remount,ro /system

To capture the packets just type the following. But make sure your terminal emulator can send CTRL + C.

tcpdump -s 1514 -w /storage/sdcard0/out.pcap

[2013-10-17] Nestle tries to patent the fennel flower

Even though fennel is used for over a thousand years to cure many things, Nestlé thinks it is the owner of every plant and tries to patent it. Please help to stop this and show your unpleasentness by clicking this link and sign the petition.

This incident shows again, there should be no patents for plants, animals or DNA, EVER!

[2013-10-16] script to create index pages for each category

Here is a small python script that achive this. First i need to know what categories are possible.

```python

!/usr/bin/env python

import os

template = """--- layout: none