Friday, January 28, 2011

Merge two directories on Linux using Tar

From linuxquestions.org:
tar cf - . |(cd /targetdir; tar xvf -)


or
alias merge=pushd $1 | tar cf - . |(cd $2; tar xvf -); popd
(untested)

Add all unversioned files with SVN

from stackoverflow:
svn status | grep '?' | sed 's/^.* /svn add /' | bash

Tuesday, January 25, 2011

Python unicode

Python doesn't strip the byte order marker when reading an UTF-8 file. Using unicode.strip() won't remove it from the first line either.

From the link:

if u[0] == unicode( codecs.BOM_UTF8, "utf8" ):
 u = u[1:]

Monday, January 24, 2011

CKEditor

Wow, events in CKEditor are sometimes hard to decipher. For example: why does the dialog not close when the 'Ok' event is fired on a dialog?

Well, the ok event is not responsible for hiding the editor. That is something the ok-button.onClick() does. So, if you want to simulate hide the dialog as if the ok button was clicked, do the following:



if(dialog.fire('ok', {hide:true}).hide !== false) {
  dialog.hide();
}

Tuesday, January 11, 2011

Python's Matplotlib and markeredgecolor

When plotting something in matplotlib using the scatter() function, it took me a while to find out that the "markeredgecolor" setting from the plot() function is available, but has a different name: "edgecolor".

In a normal plot(), the main actors are the lines between the data points. In a scatterplot, the main actors are the markers so that does not need be repeated in the name.

An example:
    lines = plt.scatter(x, y, c=colors, marker='o')
    plt.setp(lines, edgecolors='None') #or 'face'. rgba tuples like ((0,0,0,0),) do not seem to work.
    plt.show()

I wanted lines between each of my markers. Instead of trying to coerce scatter() to draw lines or plot() to draw coloured faces (it will not), just call them both.

    plt.plot(x, y, marker='None')
    faces = plt.scatter(x, y, c=color, marker='o')
    plt.setp(faces, edgecolors='face')
    plt.show()