Archive for the ‘Programming’ Category

Arguments vs. Parameters

Mittwoch, März 19th, 2008

Just friendly reminder from the language police. The terms argument and parameter aren’t synonyms. Parameters are the variables declared in a function definition, as in:

    void range(int to, int from)

„the function range has two int parameters named to and from„. Arguments on the other hand are the values being passed in when the function is called:


„the function range is being called with the arguments 0 and x.“

ruby main idiom

Mittwoch, Februar 20th, 2008

Because I keep forgetting, it’s

if $0 == __FILE__
  puts "main"

where __FILE__ contains the name of the file that the currently executing code is located in and $0 is the name of the currently executing program.

Digest Ruby (MD5, SHA) in Ruby

Sonntag, Februar 10th, 2008

I don’t know how many times I’ve gone to the stdlib documentation for usage information concerning digest. Unfortunately, there’s nothing to see there, move along. Documentation is provided in the src distribution [src]/ext/digest/digest.txt. The abridged version:

require 'digest/[md5|sha1|sha2|rmd160]'    
digest = Digest::[MD5|SHA1|SHA256|SHA384|SHA512|RMD160].new   
while #some loop     
digest.digest #raw bytes
digest.hexdigest #hex

alternatively, the short form:

require 'digest/MD5'
d =
d.hexdigest('whatever you're digesting')

sha2 contains implementations for the digest classes SHA256,SHA384,SHA512

Finally the lengths of the returned hex strings:

len bytes len hex
MD5 16 32
SHA1 20 40
RMD160 20 40
SHA256 32 64
SHA384 48 96
SHA512 64 128

Webmontag Vortrag: jsxmlrpc

Dienstag, Oktober 2nd, 2007

Heute meine Premiere beim Koelner Webmontag. Kurzer Vortrag zu jsxmlrpc, einer Javascript Bibliothek zum Einbinden von Webservices in Javascript. Vortrag ist hier: webmontag vortrag. Link zum Code.

Farbschema erstellen.

Samstag, Januar 20th, 2007 bietet ein nettes online Tool an, um anhand von einem bestehenden Bild ein Farbschema, z.B. fuer eine Webseite zu erzeugen. Anbei das Resultat meiner Experimente, waere doch ein schoenes Farbschema fuer Pflaster, finde ich.


Aus dem Versuchslabor.

Mittwoch, Dezember 13th, 2006

Ein kurzer Link zu einem Suchmaschinenexperiment. Ein Kind der Langweile. Schon tausendmal dagewesen, braucht kein Mensch.

Javascript Editor.

Samstag, November 25th, 2006

maennchen.pngTrotz tiefgründiger Abneigung gegen Javascript (zumindest sofern’s im Browser läuft), erwische ich mich immer wieder dabei, blöde Tricks in Javascript zu implementieren. Um mir dabei behilflich zu sein, habe ich vor einiger Zeit einen kleinen, browserbasierten Editor gebastelt und per Copy & Paste von Projekt zu Projekt mit mir herumgeschleppt.

Inszwischen bin ich dazu gekommen, diverse Bestandteile zusammenzutragen und zwecks einfacher Wiederverwendbarkeit zu einem Päckchen zu schnüren. Dank eines genialen Bookmarklet, kann man den Editor sogar an beliebige fremde Seiten tackern, und mit den Javascript Elementen dieser Seiten interagieren.

`sprintf` in Javascript

Montag, November 13th, 2006

Schon tausendmal gemacht, aber ich konnte es mir nicht verkneifen meine eigene unvollständige Javascript sprintf Implementierung zu schreiben:

[viewcode source=“sprintf.js“ link=“yes“ scroll=“yes“]

Unterstützt werden die folgenden Formate:

%o : numerischer Wert, oktal, Format: 0…
%x : numerischer Wert, hexadezimal, Format: 0x…
%b : numerischer Wert, binär, Format: 0b…
%d : numerischer Wert dezimal
%s : „normale“ Zeichenkette

Prozentzeichen können durch %% dargestellt werden.


sprintf ("%s, %o, %x, %b", 17, 17, 17, 17)

=> 17, 021, 0x11, 0b10001

sprintf ("Alles Gute zum %d. Geburtstag, %s %s!", 88, "Frau", "Schmitz")

=> Alles Gute zum 88. Geburtstag, Frau Schmitz!

Außerdem wird die eigebaute Javascript Klasse String um die Methode, fmt ergänzt. Dies erlaubt, dass Zeichenketten unmittelbar als Formatstrings verwendet werden können:

"%d.) %s".fmt(1, "an erster Stelle...")

=> 1.) an erster Stelle…

Displaying Source Code in WordPress

Dienstag, November 7th, 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: