Archiv für die Kategorie „Crap“

Tim’s Guide to JVM Languages.

Donnerstag, 1. Dezember 2011

JRuby: for people who realize the Ruby interpreter isn’t that hot performancewise or –more likely– whose sysadmins refuse to deploy anything but jar files. Vaguely useful in case you absolutely require a Java library for a script that involves opening a file, parsing xml, printing to the screen, adding two `byte`s or something similarly impossible to do in Java without becoming so enraged that you end up twisting some cute little animal’s head off.

Jython: see JRuby

Groovy: for hardcore Java nerds who don’t want to admit to themselves that Java isn’t the be-all end-all of programming by resorting to JRuby or Jython. Because for unknown reasons, groovy is somehow „more“ Java.

Scala: for people who feel Java isn’t special enough for them, because they’re very special. Yet they’re too limp dicked to use haskell or erlang. In all honesty, they would prefer to use ocaml, but the JVM handles cache line optimization in Intel’s upcoming Larabee architecture better and they need to squeeze every last bit of performance out of their „boxen“. They also enjoy using important words like „contravariant“ that noone including themselves understands. This makes them feel even more special.

Fantom: see Scala, add: for who Scala is too mainstream because Twitter and one other company allegedly used it a some point.

Clojure: see Scala, but switch „scheme or lisp“ in for „haskell or erlang“, feeks slightly less absurd than Scala to me.

JavaScript: oh-my-god just go ahead and scratch my eyes out, why in hell would anyone … oh yeah, it ships with the JVM (no joke). The „embedded language“ of choice in case you need to embed some language into your Java desktop software.

JavaFX: sadomasochists with a serious Sun Microsystems fetish who have wet dreams of Duke™ (the little java dude) gnawing their balls off. They also really hate Flash and want to stick it to Adobe. But they haven’t heard that Adobe discontinued it or that you can do „mouseover“ effects in HTML5 thus enabling Rich Internet Applications™ without Applets™.

All of the other JVM languages are either someone’s uni dissertation or total bullshit. Except for Frink which is pretty awesome but not really a general purpose programming language.

That said, Java is a really annoying language, but so are all other computer languages that don’t live in the JVM to some degree. It’s perfectly possible to write solid and useful code with it.

(this rant originally posted by me here. I updated it with a link to cute animals and frink)

Determining memory usage in process on OSX

Freitag, 30. Januar 2009

My strenuous journey started with a seemingly simple task: I wanted to obtain a rough and tumble estimate of the amount of memory instantiating a rather opaque data structure from a third party library would consume.

Naively, I started writing a loop that created a new instance sleeping and then … I poked around Single Unix for a system call that could help and ended up coming up with `getrusage`. OSX man pages stated it fills in this:

struct rusage {
  struct timeval ru_utime; /* user time used */
  struct timeval ru_stime; /* system time used */
  long ru_maxrss;          /* integral max resident set size */
  long ru_ixrss;           /* integral shared text memory size */
  long ru_idrss;           /* integral unshared data size */
  long ru_isrss;           /* integral unshared stack size */
  long ru_minflt;          /* page reclaims */
  long ru_majflt;          /* page faults */
  long ru_nswap;           /* swaps */
  long ru_inblock;         /* block input operations */
  long ru_oublock;         /* block output operations */
  long ru_msgsnd;          /* messages sent */
  long ru_msgrcv;          /* messages received */
  long ru_nsignals;        /* signals received */
  long ru_nvcsw;           /* voluntary context switches */
  long ru_nivcsw;          /* involuntary context switches */

Unfortunately, all the fields apart from user and system time remain zeroed. `grepping` through the xnu (Darwin kernel, apparently the only available information about what does and doesn’t work under OSX) sources, I ended up finding this comment in the declaration of `struct rusage` which finally convinced me that I’m not too stupid to make a simple call:

struct    rusage {
    struct timeval ru_utime;    /* user time used (PL) */
    struct timeval ru_stime;    /* system time used (PL) */
#if defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)
    long    ru_opaque[14];        /* implementation defined */
#else    /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
     * Informational aliases for source compatibility with programs
     * that need more information than that provided by standards,
     * and which do not mind being OS-dependent.
    long    ru_maxrss;        /* max resident set size (PL) */
#define    ru_first    ru_ixrss    /* internal: ruadd() range start */
    long    ru_ixrss;        /* integral shared memory size (NU) */

At least the good folks over at SUN are kind enough to mention the fact all the fields are dummies in their man pages.

Then I found Michael Knight’s (not that one) blog, which used the underlying mach function `task_info`. Unfortunately, Apple doesn’t document the mach API at all and the sole reference they supply points directly to nowhere.

Well, if `ps` can determine memory usage, surely it should be able to tell me how. Finding the source of OSX `ps` was another story. Hint: it’s not located in the `basic_cmds`, `misc_cmds`, `shell_cmds`, or `system_cmds` package. It’s in the `adv_cmds` (advice?, advanced?, adventure?).

`ps` ended up using a bunch of equally undocumented (non-mach) kernel functions. At this point I remembered that `macfuse` contains a `procfs` for OSX. To me, using `proc` seems to be the obvious way to get memory usage under Linux, so I dug through that and saw macfuse uses `task_info` as well.

I finally found documentation for the mach API within the xnu sources under the `osfmk/man` directory or online here and was able to write a simplified version of Michael’s original.


#include <mach/task.h>

int getmem (unsigned int *rss, unsigned int *vs)
    task_t task = MACH_PORT_NULL;
    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;

    if (KERN_SUCCESS != task_info(mach_task_self(),
       TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count))
        return -1;
    *rss = t_info.resident_size;
    *vs  = t_info.virtual_size;
    return 0;

In case anyone knows of an even remotely portable way obtain similar information, please let me know.

No loopback interface on Windows (XP)

Mittwoch, 22. Oktober 2008

Learned today that Windows doesn’t support a loopback interface for localhost. In consequence, network packets destined for the local machine are never passed to any interface and therefore can’t be captured by a packet sniffer. Unfortunately, looking at the network is my preferred way of diagnosing network problems, so this behavior gets in the way. An easy workaround is to route packets to a local address to the standard gateway instead. The gateway then sends the packets back to the local machine. This is a bit of a detour, but at least the traffic shows up. This dramatically changes how the packets are being moved around, so it might not help… But just in case:

  1. grab your IP address and Gateway using ipconfig in a DOS box.
  2. route add $LOCAL_IP mask $GATEWAY_IP metric 1
  3. when you’re done, use route delete $LOCAL_IP to get things back to normal

Backslashes in C includes…

Samstag, 27. September 2008

Who’d have thought:

  1. that DOS backslashes in C include paths aren’t only ugly and a pain, but also not legal* C:

    If the characters ‚, \, „, //, or/* occur in the sequence between the < and > delimiters, the behavior is undefined. Similarly, if the characters ‚, \, //, or /* occur in the sequence between the “ delimiters, the behavior is undefined. A header name preprocessing token is recognized only within a #include preprocessing directive.


  2. … the C99 Standard is available for free online This links directly to the pdf containing the current standard, which lives here.
  3. It’s easy to fix:

    find . -name '*.[c|h]' -print0 | xargs -0 \
       ruby -i.bak -pe 'scan(/^\s*#include.*/){ gsub(/\\/, "/") }'
  4. * yeah, I know, it’s legal just undefined.
    ** this post inspired by this.

Removing PDF Restrictions.

Montag, 19. Mai 2008

Adobe’s PDF file format comes with the possibility to restrict the things you’re allowed to do with a PDF document. This has nothing do do with encrypting the document to keep unauthorized people from reading it. Instead, authors may want to disallow printing, modifying or copy&pasting parts of a document. It’s still possible to view the documents on the screen.

Apparently, on older versions of Mac OSX’s Preview, it was possible to just „Save as …“ a restricted PDF, the resulting saved file would be a PDF without restrictions. This was fixed, but the ColoySync utility still had the possibility to use the „Save as …“ trick. Apparently at some point, they fixed ColorSync as well.

As far as I can tell, the easiest way to print a restricted document nowadays is to use ColorSync to „Export …“ the PDF to a TIFF file, open the TIFF (it will be huge) in Preview and either print it directly, or print to a PDF. Of course, the resulting PDF won’t be searchable, but as far as I know, Adobe hasn’t come up with a „disallow search“ restriction (which no doubt, a lot of publishers would use) so you can search in the original, restricted PDF.

Erste Fahndungserfolge bei Soko „Brücke“

Donnerstag, 3. April 2008

Nach der Ausstrahlung des Phantombildes der mutmaßlichen Brückenmörder im ZDF Dauerbrenner „Aktenzeichen XZ: ungelöst“ konnte sich die Oldenbürger SOKO „Brücke“ kaum noch vor Anrufen aufgereger Tokio Hotel Fans retten:

Bereits eine Stunde nach Ende der ZDF-Sendung „Aktenzeichen XY … ungelöst“ konnten rund 200 Anrufe verbucht werden, bis heute stieg die Zahl auf 350.

Quelle: Spiegel Online


Werbung, furchtbar im Arsch.

Montag, 31. März 2008

Es gibt normale Werbefachleute und es gibt die Vollprofis von Werbetechnik Dick in Köln:


Nein, da hat nicht irgendein obzöner Betrunkener einen Aufkleber zwischen die Arschbacken geklebt, „das soll so sein“.

„Bongiorno“ heisst „Ich liebe Dich“…

Samstag, 30. Juni 2007

Rudolf, der Schlawiner.… wäre ein super Titel für so eine ZDF Eigenproduktion, finden Sie nicht? Ich habe das Drehbuch im Kopf schon fast fertig: Auf Elba trifft der verwitwete Kardiologe Rudolph von Stattelhoffer die smarte Tierpflegerin Hanne, die dort auf der Insel das gebrochene Bein des Schimpansen Rudolf kuriert. Eine unheilvolle Verwechselung, durch lustigen Schabernack des Schimpansen und dessen Namensvetterschaft zum Kardiologen verursacht, lässt den Verdacht entstehen, dass Dr. Rudolph seine Frau ermordet hat. Zwischen Rudolph und Hanne knistert es zwar, aber sie weiß nicht, ob sie dem Kardiologen vertrauen kann.

„Ich würde mich so gerne in Deinen starken Armen fallen lassen, aber ich weiß nicht, ob ich Dir vertrauen kann.“ könnte sie ihm z.B. in einem intimen Moment zuflüstern.

Wird es Dr. van Stattelhoffer gelingen, seine Unschuld zu beweisen? Oder zumindest Hanne davon überzeugen, dass seine Frau wirklich bei einem tragischen Tennisunglück auf dem von Stattelhoff’schen Anwesen umgekommen ist?

Ich denke, man muss zielgruppenorientiert denken, wenn man Erfolg als Drehbuchautor haben will, und das 75-95jaehrige Kernpublikum beim ZDF mag sowohl schmucke Ärzte und Schimpansen.

Displaying Source Code in WordPress

Dienstag, 7. November 2006

I needed to post some source code on WordPress. I had no idea how painful this would be. There’s a number of plugins that are supposed to handle this, but that canonical source code plugin doesn’t seem to exist. The one that seemed to fit my needs best was Code Viewer because of the following features:

  • lets you maintain source code in a external files, only maintaining references to the files in the editor
  • automatically includes download link to the external files
  • line numbering

A guy called AJ added scrollable text areas and the capability to select which lines to display like this: 1,3-7,15 in updated versions. Both versions have at least two disadvantages I’ve stumbled across:

  • they can’t be used with the WYSISWIG Editor, because the built-in tinyMCE editor really goes out of it’s way to make sure it screws up anything remotely resembling source code.
  • they require their own CSS styles that can either be included from the header template or appended to the end of the default.css stylesheet. Both options require editing „default“ files, which I think is bad style.

A third guy called Håkan Carlström tries to address these issues, but unfortunately, I wasn’t able to get his version of the plugin code to work at all.

I looked at the different versions and but together my own melange. Caveat: I have no idea what license any of the three release the code under, but I’ll get back to you on that…

The reason why the first two versions don’t work in the WYSIWYG editor, is because they rely on xml tags like this:


and the WYSIWYG editor just can’t cope with unfamiliar tags. The editor will also consistantly screw up the string:


but that’s another story. Håkan version of the plugin tries to avoid the angled brackets by using square brackets like this:

a tad too verbose for my taste. A nice feature of his plugin is the capability to dynamically link in the necessary style sheet. Too bad I can’t get it to work…

So here’s my version. It can be used from within the WYSIWYG editor because it uses source as the attribute name instead of src and square brackets like this:


So anyway, this is what you end up getting:

[viewcode source=“arg.src“ scroll=“yes“]

Yes, it’s true, I spent the larger part of the afternoon sifting through *argh* php code. And now this. So: DO NOT USE THIS PLUGIN WITH PHP CODE!

What else didn’t I get working? Glad you asked: including a link to the Coder Viewer stylesheet doesn’t work, because of an unseen entity from deep within WordPress that filters out link tags.

That being said, you can download the semi-functional plugin here.

So here’s the css with some modifications I’ve made, you’ll need to botch these styles into some other stylesheet you’re already including or include it seperately in the header:

[viewcode source=“code-viewer.css“ link=“yes“ scroll=“yes“]

Included on this page using the actual Code-View plugin!!

So if there’s anything I learned from this experience is that while I already disliked php for having $variables and unecessary semicolons, I had no idea how bad it really sucks: