Here are the slides for my talk at Jax. I’ve not written anything up yet, so here’s a link to the interview the JAX team did with me before the conference: interview (German). The slides probably don’t make much sense without me clowning around in front of them, sorry.
Everbody hates Java. Jax 2012.
Mai 2nd, 2012Tim’s Guide to JVM Languages.
Dezember 1st, 2011JRuby: 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)
Ubuntu Fonts
Februar 18th, 2009I just installed Ubuntu 8.10 and, as always, I’m impressed at how easy to set up every thing is and how effortless everything works. I was all the more surprised that I couldn’t find a font dialog in the `System->Preferences` or `System->Administration` dialogues. As far as I can tell, no such thing exists.
Installing new fonts is still pretty easy once you know how: either create a `.fonts` directory under your home directory and copy the font files there, or install them centrally by `sudo cp`ing the font files to the respective directories under `/usr/share/fonts`.
Determining memory usage in process on OSX
Januar 30th, 2009My 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.
Voila:
#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)
Oktober 22nd, 2008Learned 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:
- grab your IP address and Gateway using
ipconfig
in a DOS box. route add $LOCAL_IP mask 255.255.255.255 $GATEWAY_IP metric 1
- when you’re done, use
route delete $LOCAL_IP
to get things back to normal
Visualizing Ant Redux.
Oktober 14th, 2008I’ve written a small update to my ant-file visualization tool. The only visible change is that the default task is now marked in the output.
You can either download the jar containing everything you need, or build it yourself from the source available via:
svn co http://a2800276.googlecode.com/svn/branches/antvis
If Antvis is run from the command line like so:
$ java -jar antvis.jar usage: [jre] antvis.AntVis -f inputFile [-t format] [-o outfile] format: format supported by dot. Default: `dot` outfile: Default stdout call [jre] antvis.AntVis -l for a list of supported formats
It prints out the available options. If it’s called correctly:
$ java -jar antvis.jar -f build.xml -t png -o self.png
It will produce graphical representations of the provided build.xml
file like this one
for Antviz’s own build.xml
or this one
The above is an example of a more complicated build.xml
script, it ships with jpos.
Backslashes in C includes…
September 27th, 2008Who’d have thought:
- 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 undeï¬ned. Similarly, if the characters ‚, \, //, or /* occur in the sequence between the “ delimiters, the behavior is undeï¬ned. A header name preprocessing token is recognized only within a #include preprocessing directive.
(C99 6.4.7.3)
- … the C99 Standard is available for free online This links directly to the pdf containing the current standard, which lives here.
-
It’s easy to fix:
find . -name '*.[c|h]' -print0 | xargs -0 \ ruby -i.bak -pe 'scan(/^\s*#include.*/){ gsub(/\\/, "/") }'
* yeah, I know, it’s legal just undefined.
** this post inspired by this.
Backing up MacOSX Address Book without MaxOSX Address Book
September 9th, 2008I recently installed a new harddrive on my Macbook. Before proceeding, I made a backup of my entire drive using SuperDuper. I wanted a fresh install, so instead of just dumping the old disk image on the new drive, I installed Leopard and started selectively copying what I needed.
Everything went well until I wanted my Address Book back. Unfortunately, all advice concerning backing up Address Book is along the lines of „Start Address Book and select ‚Back up‘ from the ‚File‘ menu“, but no one tells you where Address Book actually saves the addresses. The easiest way to find out turned out to be using Instruments to monitor what files Address Book opened on startup.
To make a long story short: to transfer entries from one computer to another, just copy the Folder:
/Users/.../Library/Application Support/AddressBook
You may not be able to overwrite some files, because they are in use by other programmes (in my case the culprit was Safari). You can figure out which programme currently has files open using fuser
in the Terminal.
„Ruby Cryptography: TINFM“
Juli 22nd, 2008TINFM meaning „there is no fine manual“, of course. Just as with digest
, Ruby’s openssl documentation is missing just the bits you’ll need to get started. In order to encrypt or decrypt something, you’ll first need to instantiate the approriate cipher:
require 'openssl' cipher = OpenSSL::Cipher::Cipher.new NAME_OF_CIPHER
So how do I know the name of the cipher if it’s not documented? You’ll need to refer to the OpenSSL documentation, or refer to this handy list:
base64 | Base 64 |
bf-cbc | Blowfish in CBC mode |
bf | Alias for bf-cbc |
bf-cfb | Blowfish in CFB mode |
bf-ecb | Blowfish in ECB mode |
bf-ofb | Blowfish in OFB mode |
cast-cbc | CAST in CBC mode |
cast | Alias for cast-cbc |
cast5-cbc | CAST5 in CBC mode |
cast5-cfb | CAST5 in CFB mode |
cast5-ecb | CAST5 in ECB mode |
cast5-ofb | CAST5 in OFB mode |
des-cbc | DES in CBC mode |
des | Alias for des-cbc |
des-cfb | DES in CBC mode |
des-ofb | DES in OFB mode |
des-ecb | DES in ECB mode |
des-ede-cbc | Two key triple DES EDE in CBC mode |
des-ede | Two key triple DES EDE in ECB mode |
des-ede-cfb | Two key triple DES EDE in CFB mode |
des-ede-ofb | Two key triple DES EDE in OFB mode |
des-ede3-cbc | Three key triple DES EDE in CBC mode |
des-ede3 | Three key triple DES EDE in ECB mode |
des3 | Alias for des-ede3-cbc |
des-ede3-cfb | Three key triple DES EDE CFB mode |
des-ede3-ofb | Three key triple DES EDE in OFB mode |
desx | DESX algorithm. |
idea-cbc | IDEA algorithm in CBC mode |
idea | same as idea-cbc |
idea-cfb | IDEA in CFB mode |
idea-ecb | IDEA in ECB mode |
idea-ofb | IDEA in OFB mode |
rc2-cbc | 128 bit RC2 in CBC mode |
rc2 | Alias for rc2-cbc |
rc2-cfb | 128 bit RC2 in CFB mode |
rc2-ecb | 128 bit RC2 in ECB mode |
rc2-ofb | 128 bit RC2 in OFB mode |
rc2-64-cbc | 64 bit RC2 in CBC mode |
rc2-40-cbc | 40 bit RC2 in CBC mode |
rc4 | 128 bit RC4 |
rc4-64 | 64 bit RC4 |
rc4-40 | 40 bit RC4 |
rc5-cbc | RC5 cipher in CBC mode |
rc5 | Alias for rc5-cbc |
rc5-cfb | RC5 cipher in CFB mode |
rc5-ecb | RC5 cipher in ECB mode |
rc5-ofb | RC5 cipher in OFB mode |
aes-[128|192|256]-cbc | 128/192/256 bit AES in CBC mode |
aes-[128|192|256] | Alias for aes-[128|192|256]-cbc |
aes-[128|192|256]-cfb | 128/192/256 bit AES in 128 bit CFB mode |
aes-[128|192|256]-cfb1 | 128/192/256 bit AES in 1 bit CFB mode |
aes-[128|192|256]-cfb8 | 128/192/256 bit AES in 8 bit CFB mode |
aes-[128|192|256]-ecb | 128/192/256 bit AES in ECB mode |
aes-[128|192|256]-ofb | 128/192/256 bit AES in OFB mode |
A list of the currently supported cipher strings, without the explanation can also be produced by calling OpenSSL::Cipher.ciphers
After you’ve instantiated the proper cipher, you tell it to either encrypt or decrypt, give it the key to use (and possibly an IV) and then pass in data using update
:
cipher.encrypt cipher.key = KEY_DATA ciphertext = cipher.update plaintext cipher.reset cipher.decrypt cipher.key = KEY_DATA plaintext = cipher.update plaintext
That’s all. Not really difficult, once you’ve pieced everything together.
London Underground Typeface
Mai 22nd, 2008Monday 2nd July 1979, straight after five years of student life in the UK, was my first day at Banks and Miles, a London based graphic design company. That morning was a bit of a shock. I was given a few large broadsheets with litho printed Johnston type. I was definitely confounded by being asked straightaway to design a new Johnston family with three weights — Light, Medium and Bold — within a month or two. (…) Colin Banks, an external assessor for the LCP, had asked me if I would be interested in redesigning a typeface. I was grateful for the job (…), but the prospect was daunting because I had no experience in type design and very little English language. (…) I expected that in the office there would be at least a kind of preliminary training or guidance for a novice designer — what drawing tools to be used, what size the original artwork should be, how to typeset with newly drawn letters. I remembered one college day in 1975 when our tutor took us to the drawing office of the Monotype Corporation in Salfords. They had impressive purpose-built drawing equipment, precision machines and many skilled draughtsmen and women. In contrast, my tools were very basic: pencils, felt tip pens, a Rotring pen with 0.1 mm nib, Winsor & Newton’s fine brushes and some photographic equipment in the darkroom.
Interesting article about Eiichi Kono’s1979 redesign of the „Johnston“ typeface that London Transport has been using in the Underground since 1913.