I am an FU Berlin Informatics student in the second/third semester. I do some development now and then and maintain a couple of Debian packges.

In case you should whish to contanct me you can do so at carlos@cmartin.tk. To subscribe RSS 2.0 feed

 

Inverse economy of scale

It seems the local supermarket doesn’t get bulk discounts. A pack of four yogurt costs 50 cent, while a pack of eight (which is two packs of four wrapped in some cardboard) sets you back 1.33 euro.

That’s right, it costs 33 cent to have it wrapped in a bit of cardboard. The situation with tuna is apparently the same. A pack of six costs a couple of cents more per can than three.

Tags: , ,

Filed under:Life

The not-so-enhanced for loop

In Java, there’s a loop construct called “enhanced for loop” (it’s just a foreach, don’t get too excited). I decided to use it in the obvious, straightforward way thus:

for(String str : words){
    str = doSomething(str);
}

return words;

Many will see the problem already. In Java, a variable doesn’t hold your data, everything (except for the built-in numbers) is a pointer. So, what does this code actually do? Instead of processing the strings in the words array (or other enumerable class) and copying them back, the strings in words don’t change  at all.

You see, in each iteration, the str variable points to the nth string in the array. When you assign str a new value (I take a StringBuilder and return its string back, as I’m trimming special characters), it happily points somewhere else, leaving the original one intact.

Remember kids, if you want to use for loops, you might have to go the old-fashioned way to make sure the entries in your array are updated. For reference, this is the correct code:

for(int i = 0; i < words.length; ++i){
    words[i] = doSomething(words[i]);
}

return words;

What I can’t figure out is why the (bytecode) compiler doesn’t do this itself.

Tags: , , ,

Filed under:Programming

Not loading a file’s DTD when doing an XSL Transformation in Java

This has hit me in the face two or three times already in the same project, and last time I solved it by calling /usr/bin/xsltproc --html from inside the servlet. Finally I’ve found a way to tell the underlying levels not to bother loading the DTD as it’s useless and doesn’t even live where the XML file thinks it does.

This problem was not helped by the JVM’s limitations, namely, its inability to change the process’ working directory.

Without further ado, this is the code that transforms an XML file with DTD without trying to load it. The important parts are factory.setValidating(false); and factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); which I’m pretty sure I had tried several times before, but it has only worked this time.

String xslPath = getServletContext().getRealPath("content.xsl");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
try {
	factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (ParserConfigurationException e2) {
	// TODO Auto-generated catch block
	e2.printStackTrace();
}
DocumentBuilder builder = null;
try {
	builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
	// TODO Auto-generated catch block
	e1.printStackTrace();
}
InputSource src = new InputSource(item.getInputStream());
Document xmlDocument = null;
try {
	xmlDocument = builder.parse(src.getByteStream());
} catch (SAXException e1) {
	// TODO Auto-generated catch block
	e1.printStackTrace();
}
DOMSource xmlSource = new DOMSource(xmlDocument);
TransformerFactory transFact = TransformerFactory.newInstance();
Result result = new StreamResult(out);
Source xslSource = new StreamSource(xslPath);
try {
	Transformer transformer = transFact.newTransformer(xslSource);
	transformer.transform(xmlSource, result);
} catch (TransformerConfigurationException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} catch (TransformerException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

Tags: , , , , ,

Filed under:hacking

Using mono’s WCF

Meebey uploaded the Mono 2.6 packages to his repo today, so I decided to finish porting blam to WCF and the supposedly perfect SyndicationFeed class, which should make the underlying feed format irrelevant. Big mistake, the code hasn’t been touched in six months and there are some pretty big bugs in it.

First, when reading Atom’s <source> tag (which I believe should be called “element” in XML parlance), it expects (for some reason which escapes my understanding) to have a full Atom-compliant feed embedded in it.

Secondly, it assumes a <guid> tag is always a permalink, and doesn’t check to see if it is.

Both these bugs make the parser stop, which makes my app unusable. I’ll whip out a couple of patches shortly, which will hopefully be backported.

Tags: , ,

Filed under:debian, hacking

Using libindicator-application for fun and profit

After spending two days fighting with DBus, GLib and the several libraries provided by the Ayatana project, I am now confident I know how to proceed implementing support for application indicators and DBus menus in GNOME Shell.

The first thing you have to do is connect to indicator-application-service (the process that). You do this by connecting through the session bus to the onwer of “org.ayatana.indicator.application” with path “/org/ayatana/indicator/application/service” using the interface “org.ayatana.indicator.application.service“.

Now you can know which applications have already connected to the service (or you will as soon as they implement it ;) by calling the “GetApplications” method. This returns an “a(siso)“. That is, an array (list) of structs made out of the following:

  • string: the icon’s name
  • int: the position (I don’t really know what this does)
  • string: the application’s address on the DBus session bus
  • object: this is actually a string with the application’s path on the “org.dbus.dbusmenu” interface

Once you have all this information. You can connect yourself to the “ApplicationAdded” and “ApplicationRemoved” signals. From “ApplicationAdded” you’ll get all the above information, and from “ApplicationRemoved” you get the position (so I guess you can use it as an unique identifier).

You are now ready to talk to the application and request such things as its alert icon, its state (passive, alert), its menu path (again), or its self-chosen id string. You get this information by building a proxy to the “;org.freedesktop.DBus.Properties” interface (again, connecting to the application’s address and the path is still “/need/a/path“) and calling the “Get” method, with the first argument set to “org.ayatana.indicator.application.NotificationItem” to say that you want to use that interface. The second argument is the name of the data you want to get.

Why you can’t simply connect to the “org.ayatana.indicator.application.NotificationItem” interface on the application’s address escapes me, but if I had to guess, I’d say they want to make testing easier.

Whilst this is enough to show the icon on the system tray (sorry, notification area, or whatever), you still need to get the menu from the application and display it. This will be the focus of my next post on this subject (just as soon as I figure out how to do it).

After that, I want to display the menu using clutter actors, which won’t be the easiest thing, I assume.

Tags: , ,

Filed under:gnome, hacking

Warming up to Bologna

I’ve just passed the one-month mark of my stay in Bologna and I must say I’m really warming up to it.

The summer is being very long this year, which means that midday and early afternoon up to the evening, we can relax in the sun. It was only a couple of days ago that I put my jumper on for the first time since I arrived, and that was only because the sun had set a few hours earlier, and last night I didn’t even have to and we stayed out until almost midnight.

One important aspect that this flat has over the one in Berlin is the amount of light that comes it. It certainly makes a difference to cook with natural light instead of that yellow overhead light. The other side-effect of being further south is the strength of the sun. If the day is sunny, it will be warm, if not outright hot. This makes it possible to have the windows and doors to the balcony open and a slow flow of air flowing during most of the day.

There are two things I still need to get used to though. The first is the opening times: most shops close too early and many close during lunch-time.

The second is the public transport: it is very limited and chaotic. Not being able to trust the departure times posted on the bus stops makes me a bit uneasy, specially if I have to plan for an arrival time. It’s not unusual to see two busses following each other doing the same route.

But this is all part of going south, so I have to get used to this and plan my day around early shop closing and unreliable transport.

Filed under:Bologna

Blam 1.8.7 released

This afternoon I uploaded the final tarballs for the 1.8.7 versions. You can get it from the usual location http://cmartin.tk/blam/ and there is information at http://cmartin.tk/blam.html.

The Debian packages will be ready soon. These are the changelog highlights:

  • Context menu on the tray icon.
  • Support channel groups (1-deep (for now) folders). (Bug 166468)
  • Move channels into, out of, and between groups with Drag-and-Drop.
  • Fix the bug which sometimes lost your channel data. (Bug 346553)
  • Make a distinction between old and new unread entries.
  • Use icons to make the above distriction. (Bug 156226)
  • Mark an entry read if needed when we update a feed and the item has already been read in another feed. (Bug 149154)
Filed under:blam

The holidays start

On Friday was my last exam and I’ve been enjoying my lack of commitments ever since. General development speed and Debian packaging should pick up again. My newly-acquired free time will also be spent on trying to organise the next (academic) year.

A Spaniard organising things in Italy… this could be interesting.

At some point in the near future I will have to hand in my Learning Agreement, which requires knowing what courses I can take in the next year, which requires that information being somewhere, which it isn’t. I’ll have to take the information from the current year and change most of it afterwards, but that’s what amendments are for.

It would be interesting to do the “Praktikum” (a kind of internship if you will) also abroad, if we manage to organise that between the Italians, the Spaniard and the Germans.

Tags: , , ,

Filed under:Berlin

Blam development picks up again

I have been on holidays for a few weeks and now I have enough free time that I can continue developing Blam.

Today I integrated a patch that adds a context menu to the tray icon and finally implemented drag-and-drop. This means you can move channels into groups, between groups and out of groups by dragging them to the appropiate places.

Unless I can think of anything big, Blam 1.8.7 will be released shortly. Yesterday Blam 1.8.6 made it into Debian sid, just in time for it not to be the latest version.

Tags: ,

Filed under:blam, debian, gnome

First two weeks at the uni

I’ve just finished the first two weeks of my university education. The “starter (bridge) courses” have been interesting, even if the Maths one just got me confused.

I have finally managed to write a 3D program with proper movement, partly because processing makes it easier and partly because I am now much more comfortable with 3D geometry than a few years ago.

The food at the “Mensa” is good and the bandwidth generous. The “Institut” is gets its Internet from the ZIB (Zuse Institut Berlin), which is connected to the German research network via a Gigabit link.

Tags: , ,

Filed under:Uncategorized