Elmu, shameful solutions by SAP

2010 July 25th
Elmű (Magyar Elektromos Művek, the largest (main) Hungarian Electricity Provider) created a new site not so long ago – until they had their login/password fields on their homepage, everyone was pretty happy, because it worked. A couple of weeks ago they removed it and now the login is a separate page; the only problem here: it doesn’t work on anything, except on Internet Explorer and Hungarian (!) language enabled Firefox. Let’s examine this a bit closer:
  • The system is an SAP server; it’s clearly not a cheap thing. So it’s not just a piece of crap, it’s expensive too.
  • They have a troubleshooting pdf (!): they have a solution for Safari! But wait, what’s that? User agent spoofing.
  • Piece of shit error page (just cancel the auth dialog) with grammatical errors: Bejelentkezés végrehajtva 101 mandanthoz, felhasználóhoz és HU nyelven végrehajtva.
  • Client side code is utter garbage: inline in the html, mostly deals with browser detection and it also disables right click on the page. Too bad they never heard of inspectors.
  • Routing error, problem triggered inside native code (http_route.c).
  • Finally, a cross browser login page (using CSRF) hosted here :)

DVD cataloging software: JDvdKat

2010 June 26th
Pretty crude, but it works, and it works especially for me. The source code and the executable can be downloaded from Google code: http://code.google.com/p/jdvdkat/. Apart from struggling with Swing and encountering totally annoying NetBeans bugs it was an interesting experience.

Formatting documents for the Sony Reader PRS300

2010 May 2nd

Formatting ebooks is a pain in the ass – and this is especially true on Sony’s ebook reader; I do know about Calibre and can write html (epub) files even while dreaming, so it’s not me, I’m sure.

  • The Reader supports these formats: LRF, PDF, TXT, RTF, ePub.
    • LRF I have never used, but the rest: real pain.
    • Stock PDF files can not be perfectly rewrapped (page boundaries are the greatest problem)
    • formatting in TXT is not very good and non ansi characters are broken (same is true with RTF!)
    • RTF is hard to get right withouth Microsoft Word (which I don’t have) and is very hard to reformat (with books larger than 1000 pages sometimes the device can’t even reformat it, it just stops trying after 5 minutes or so) and
    • ePub, while theoretically is very nice, unfortunately has some character rendering problems (I have a fairly recent US firmware, maybe it’s the US part, but Sony driver support is… well, I’d rather not continue this sentence)
  • I usually open files with OpenOffice (OOO), which is quite a crap in itself, but at least it has an albeit useful regexp replacer (which is everything but standard); some tricks:
    • ^$ = empty line
    • $ = paragraph break
    • \n = line break (but if used in the replace-to field, it ends up as a paragraph mark)
    • \r = the letter “r” (yeah, fuck, I had to mention it, it’s so insane)
    • $0 is the full match, $1, $2, $N are the backreferences
    • sometimes it’s easier to remove all line breaks, like replacing “$ signs” to a unique text (%P%) so they can be removed more easily. Unfortunately OOO may choke on bigger documents, but what do you expect for free?
  • OOO “save as” sucks like hell: neither rtf nor doc is okay (sometimes even the simplest formattings like emphasis or strong ends up messed up, like having the wrong font size), but hey, we have PDF
  • so I set the page size to 9cm x 12cm, no margins, 12pt Times (that’s the best for my eyes, font resizing is just plain terrible on the device anyways) and then export to PDF
  • Finally two extra tips:
    • sometimes it’s easier to break up big books into two or three volumes, so that OOO can cope with the horrendous task of formatting text
    • One can convert from html, using OOO: open the html, save as sxw, open the sxw, save as odt, format it and then save as pdf. Yes, a tiny litte bit ridiculous.

Btw, can anyone enlighten me, how on earth can a 20 year old (e)book cost 8 dollars (almost everywhere, probably all bigger sites has an agreement with the publishers), when there is no paper, no printing, no bookshop, no staff? Throw in the draconian DRM and it just feels like daylight robbery – if I lived in the USA, I’d just stick with the antique stores (where we purchased the aforementioned book for 1$ (let me write it down: one dollar), and for that money I can even lend the god forsaken book, without being afraid of having strucked by a lightning).

Simple JavaScript HTML parser

2010 January 30th

Once I needed a very simple and fast HTML parser written in actionscriptunlike John Resig I didn’t want to pretty print or fix broken markup; all I needed to is the structure and the attributes – and since it had to be run many times in a second, I tried not to use regexp. I know, it’s silly – but it works.

Now I “ported” that to javascript and eventually to a jEdit macro – why is this good? Because unlike a full blown SAX parser, this tool will not choke on php tags, so I use it to select the innerHTML or outerHTML in a text/html/php file – or just to find a matching tag. Unfortunately right now it parses the full file, so it’s a bit slow, but I may fix that sometime in the future.

Furthmore since this is javascript, it would be very easy to port it to editors with a javascript macro engine (Notepad++ has a rough one, and we also have Aptana, but I find Aptana’s – pretty much discontinued – scriptmonkey buggy and unreliable).

Download the jEdit javascript macro from here

Format JSON with jEdit

2010 January 14th

Sometimes I have to debug or check a json response from the server: I just paste the response to jEdit and reformat it with a macro (yes, I know about the online json beautifier and I think we did have a firebug extension for this, but still, it’s fun to see how flexible javascript macros are):

Download the json2.js from json.org, place it into your lib directory (see: startup.js), then use this ridiculously simple macro to reformat a valid javascript object (in buffer or selection):

(function(){
if (buffer.isReadOnly())
return;

var text = "",
selections = textArea.getSelection(),
bufferSelected = false,
obj;

if (selections.length == 1) {
text = textArea.getSelectedText(selections[0]);
} else {
text = textArea.getText();
bufferSelected = true;
}

obj = eval("(" + text + ")");
include(MACROLIBPATH + "json.org/json2.js");
textArea[bufferSelected ? "setText" : "setSelectedText"](JSON.stringify(obj, null, '\t'));
})();

You can download this and some of my other macros from here.