How to allow link-local access to Apache when using IPv6

Some of my Apache pages are served only to clients on the local network. Using IPv4, it was easy to Allow from the local subnet. Nowadays, most machines are autoconfigured for IPv6 as well as IPv6, and local traffic seems to go over IPv6 (entries in my Apache log file prove that). Not being up-to-date on IPv6 addressing schemes, I spent some time looking for the solution. The default Apache config file already contains references to ip6-localhost (resolves to ::1). It appears that the link-local unicast addresses can be masked using fe80::/10 (see Internet Protocol Version 6 Address Space).

Hence the syntax to allow from the local network only apache2.conf is:

    Allow from fe80::/10

JavaScript variable scope inside a loop

I got stung because I forgot (once again) that JavaScript does not have block scope. Doh! So I hope writing this down (even if it is embarrassing) will help me remember for next time.

A loop such as this:
for (i = 0; i < 10; i++) {
var x;
if (Math.random() > .5) x = i;
alert(x);
}
will not yield occasional empty x values, as one might expect. In JavaScript, having a variable declaration within the for-loop block does not reset the variable's value, as it would in languages that do have block scope.


Transparent PNGs in IE6 (when does it end!!!)

When transparent PNGs look ugly in IE6, your first step should be to use the AlphaImageLoader Filter, or use one of the ready-made JavaScript snippets, like the excellent pngfix.js script.  But those scripts may be complicated to use, and if you have a lot of images (e.g. icons in a list) the filters will slow down your page.  Then you can use the GIMP to make a transparent PNG with background color:
  1. Open the original image.
  2. Set a proper background colour as oposed to it being transparent. It is best to make this colour similar to the background colour of the website to generate the antialiasing in your image borders in order for the image to blend nicely.
  3. Flatten the image (Image - Flatten image).
  4. Add an alpha channel (Layer - Transparency - Add alpha channel).
  5. Select the background color (Selection - By color).
  6. Clear the background colour (Edit - Clear).
  7. Convert the image to indexed color (Image - Mode - Indexed color).
  8. Save the image to the final PNG file (File - Save as) and remember to check: Save color values from transparent pixels.
Thank you Matthew!



P.S. And yes, there are still people out there using IE6.

Kompaktne kalender 2009 Eesti pühadega


Hiljuti avastasin DavidSeah The Printable CEO sarja kuuluva Exceli kalendritemplate'i Compact Calendar 2009.  See kalender ei jäta iga kuu algusesse ja lõppu nädalate keskele auke, seetõttu on planeerimise jaoks praktilisem kui paljud muud tavapärased kalendrid. Eesti Vabariigi rahvus- ja riiklike pühadega eestikeelne versioon (Excel 97-2003 template) on saadaval siin:

Kompaktne Kalender 2009 Eesti

(This page links to the Estonian-language version of the Excel template for DavidSeah's Compact Calendar 2009.  The template contains Estonian public holidays.)

XML Diff

Today I googled for XML diff tools and found this great XML Diff tool!  And it comes with source code, so I can run it on my own machine without uploading confidential files to their servers (you also need the XML Pretty Printer they graciously provide).  

There are other tools that came up in google results, but none other proved so simple and effective.  

Host-specific configuration files in Spring, with fallback

I was very happy to find a practical example of how to use host-specific configuration files in Spring, but unfortunately, the given example still forces one to specify a configuration entry for each host that the application might ever be deployed on.  I am lazy, I would like to have a reasonable fallback, and only configure for the specific exception cases.  Hence I have enhanced Jeff's code a little further:

// In class HostPrecedingPropertyPlaceholderConfigurer
protected String resolvePlaceholder(String placeholder, Properties props) {
try {
if (placeholder.startsWith("HOST.")) {
String hostname = InetAddress.getLocalHost().getHostName();
String hostSpecific = placeholder.replaceFirst("HOST", hostname);
log.debug("Looking for property " + hostSpecific);
String value = props.getProperty(hostSpecific);
if (value == null) {
log.debug("Falling back to default property " + placeholder);
value = props.getProperty(placeholder);
}
return value;
} else {
return props.getProperty(placeholder);
}
} catch (UnknownHostException e) {
log.warn(e);
return null;
}
}

Now, my ${HOST.jdbc.url} in the Spring context file will first look for my hostname.jdbc.url property, but alas, if that returns null, it will default to the value of the HOST.jdbc.url property, enabling me to have a properties file like this:

prodweb.jdbc.url=jdbc:mysql://proddata/db
testweb.jdbc.url=jdbc:mysql://testdata/db
mstest.jdbc.url=jdbc:sqlserver://mstest\\sql2005;database=db;integratedSecurity=true
HOST.jdbc.url=jdbc:mysql://localhost/db

It might be even nicer if it looked for default.jdbc.url, or fallback.jdbc.url, depending on your taste. :-)

Trip tracker

Added Tomek & Rita's trip tracker to the left sidebar.

Apparently it cannot just be copy-pasted into Edit HTML section as-is... :-(
But it can be done via the Layouts / Page Elements section!  Here is how:
After clicking Add a Page Element, a new window will appear.  In the new window, choose:
Well, the layout of these instructions is now all messy... I don't really know how to arrange pictures in a blogger post yet.  But hey!  after you add the new HTML/JavaScript element, it will ask you for the title (anything) and for the actual code (which you have from whereever you got it).  Save, and then you can already arrange your new widget by drag-and-dropping it to the right location:


There you should have it!
:-)