Blog moved!
Dear readers,
This is to let you know that I have now moved this blog permanently to a new home. You can now find me on the Computers and Buildings blog.
Dear readers,
This is to let you know that I have now moved this blog permanently to a new home. You can now find me on the Computers and Buildings blog.
MathML is a W3C recommendation for putting math directly on the web. That is, your MathML compliant browser should render the math correctly, and you should not have to generate small gifs from your LaTeX equations any longer. Here I show you how to configure your Wordpress blog to correctly serve pages with embedded MathML.
Let’s look at the “Hello World!” example from W3C spec:
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<msup>
<mfenced>
<mrow>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
</mrow>
</mfenced>
<mn>2</mn>
</msup>
</mrow>
</math>
Including this code verbatim in your page won’t work, at least not with Firefox. Why? Right-click, if you will, in any page in your browser (NOT this one), click “View Page Info” and see what it says under “Type:”. Chances are it says “text/html”. Firefox will simply not render any MathML in pages that he thinks are pure HTML.
But, you will say, Wordpress pages are strict XHTML, aren’t they? I mean, if I look at the source of my pages it says right there, at the top:
<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> ...
Well yes, it says so. But chances are your Apache server serves this page with a Content-Type header that says ‘text/html’. Try it now:
$ wget --save-headers http://url.to.your.blog $ cat url.to.your.blog HTTP/1.0 200 OK ... Content-Type: text/html; charset=utf-8
So the trick to make it work is to insert some additional PHP in the document’s template that will modify the declared Content-Type. See this blog post for the full, gory details. Here is what my template looks like:
<?= '<?xml version="1.0"?>' ?>
<?= '<?xml-stylesheet type="text/xsl" href="/mathml/mathml.xsl"?>' ?>
<?php header("Vary: Accept");
if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) {
header("Content-Type: application/xhtml+xml; charset=utf-8"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php } else {
header("Content-Type: text/html; charset=utf-8"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<?php } ?>
Notice also that you need to change the DOCTYPE declaration, or your browser won’t find the special math entities declared by MathML, such as ∑. Notice also there’s a xml-stylesheet declaration; I’ll return to that in a moment.
With this in place, we can now insert, say, the definition of the first system matrix for an equivalent nodal network for building simulation (view the page’s source for the MathML markup):
The final thing I need to explain is the xml-stylesheet declaration in my template’s preamble. The mathml.xsl stylesheet is provided by the W3C and is, I believe, supposed to provide some protection and/or warning against browsers that do not support MathML. You should download all the requires XSL files from this W3C page and put them somewhere on the same server as your blog (some browsers will not execute XSLT that does not come from the same server as the document).
That’s, in a nutshell, the modifications I had to do to my Wordpress installation to enable MathML in my blog posts. I’d love to hear your comments on this.
On a recent episode of The Java Posse they mentioned a project I had never heard about before: project GreenFire.
From the project’s website:
GreenFire efficient manages and controls heating control of houses and saves energy. GreenFire is based on Java EE 5 (is tested with Glassfish v2), Scripting, RMI and Shoal. SunSpot integration is planed.
I applaude the effort to create a J2EE-based solution to cheap and efficient home automation. I’ve often felt that home automation was, and still is, the domain of do-it-yourselfers, with its attendant reliability problems. Running a home automation solution on a J2EE stack might solve many of these problems.
In short, kudos to the creator(s) of this project, I’ll definitely keep an eye on what you are doing.
EJB injection in Web Services does not work with JBoss (yet), so when you want to use an EJB from your @WebService annotated POJO you have no choice but to look it up yourself.
This can get a little tricky, because each J2EE container can use its own JNDI naming convention when registering the EJB in the global naming context. Here I document how I configured JBoss to register my EJB with a name that I choose, and how I mapped a proper EJB name to that JNDI name.
Give your EJB a reasonably unique name in its annotation:
@Stateless(name="MyServiceBean")
@Local(SomeInterface.class)
public class ServiceBean implements SomeInterface {
...
}
Include the following in your jboss.xml file:
<jboss>
<enterprise-beans>
<session>
<ejb-name>MyServiceBean</ejb-name>
<local-jndi-name>myapp/MyJNDIName</local-jndi-name>
</session>
</enterprise-beans>
</jboss>
In your WAR, configure your jboss-web.xml file to include this:
<jboss-web>
<ejb-local-ref>
<ejb-ref-name>ejb/MyEJBName</ejb-ref-name>
<local-jndi-name>myapp/MyJNDIName</local-jndi-name>
</ejb-local-ref>
</jboss-web>
You can now lookup the EJB directly from your Web Service:
@WebService
public class MyWebService {
private SomeInterface getMyBean() {
try {
return (SomeInterface) new InitialContext().lookup("java:comp/env/ejb/MyEJBName");
} catch (NamingException e) {
throw new EJBException(e);
}
}
}
Automating buildings costs money. Lots, lots of money. The return on investment (ROI) is usually very low, and it takes a long, long time (on the order of 5 to 10 years) for such an investment to pay for itself.
To make matters worse, people who rent the home or apartment they live in have little incentive to make it energy-efficient. They have no guarantee they will still live in the same place 10 years in the future. And landlords? Why would they invest? Energy costs are always born by the tenants, so they too have little incentive.
If financial considerations won’t motivate people to invest in smarter buildings, here I propose another incentive. Building automation, if implemented globally, is one of the most cost-effective strategies for keeping the atmospheric CO2 concentration at safe levels until 2050.
I reviewed Thomas L. Friedman’s Hot, Flat and Crowded in an earlier post. In that book, Mr Friedman refers to a paper published by Pacala and Socolow in Science in August 2004.
I’ve traced that paper. You can find it here: Stabilization Wedges: Solving the Climate Problem for the Next 50 Years with Current Technologies. Even if you don’t read the full paper, please do read the first couple of pages. The authors do a fantastic job at summarizing our current situation with respect with CO2 emissions and where we are headed if we do not act now. The abstract speaks for itself:
Humanity already possesses the fundamental scientific, technical, and industrial know-how to solve the carbon and climate problem for the next half-century. A portfolio of technologies now exists to meet the world’s energy needs over the next 50 years and limit atmospheric CO2 to a trajectory that avoids a doubling of the preindustrial concentration. Every element in this portfolio has passed beyond the laboratory bench and demonstration project; many are already implemented somewhere at full industrial scale. Although no element is a credible candidate for doing the entire job (or even half the job) by itself, the portfolio as a whole is large enough that not every element has to be used.
Let me summarize the key figures, and please commit them to memory:
For the most part of human history, the CO2 concentration in the atmosphere remained relatively stable at 280 ppm (parts per million). The industrial revolution coincided with the start of a clear increase in CO2 concentration.
The CO2 concentration at the time of the article (2004). But remember that CO2 concentration has always increased since careful measurements started in the late fifities:

CO2 atmospheric concentration measured on Mauna Loa (Hawaii) for the past 50 years, adapted from my thesis.
Even allowing for (healthy) skepticism, most scientists believe that mankind must at all costs prevent the CO2 levels from reaching double the preindustrial concentration, or about 560 ppm. To err on the side of caution, we as a species should pledge never to let CO2 level cross the 500 ppm limit.
When Pacala and Socolow wrote the article, mankind was dumping in the atmosphere the equivalent of 7 billion tons of CO2 per year (7 GtC/year). That’s enough CO2 to fill 1 billion hot-air balloons each year. It is also the upper limit of allowed global emissions if we are to stabilize CO2 atmospheric concentrations at their current levels for the next 50 years.
If we fail to act now, by 2054 we will be pumping out 14 billion tons of CO2 per year in the atmosphere, according to the so-called Business As Usual (BAU) scenarios. Such an emission rate will almost certainly result in a CO2 concentration of more than 500 ppm, i.e. beyond the safe upper limit. The consequences on global warming can only be disastrous.

Average global temperatures for the last 150 years, adapted from my thesis.
Stabilizing CO2 emissions is only the first half of the battle. Our goal is to stabilize them at their current levels for the next 50 years, but after that we must devise solutions to reduce them.
The paper proposed 15 potential solutions (or “wedges”) for stabilizing our CO2 emissions. Each one of these is technologically feasible and has been commercially demonstrated. Any of them will prevent the increase in CO2 emissions by 1 GtC/year by 2054. Thus, to keep our CO2 emissions to current levels by 2054, we must implement at least 7 of these 15 strategies on a global scale.
The third wedge proposed by the authors appears to me as the easiest to implement:
Cut carbon emissions by one-fourth in buildings and appliances projected for 2054.
Yes, that’s right. If we or our children are to make it safely through the second half of this century, we must implement at least 7 of 15 strategies, one of which is the reduction in carbon emissions by 25% in buildings and appliances.
And how, you may ask, can we achieve this? Well, there are really only two solutions. We may switch to more carbon-neutral energy sources, or we may reduce our energy demand. As I’ve argued in a previous post, we should prefer the latter option for the following reasons:

Credits: RogeSun Media
There’s a nice little article about green energy homes over at Greenprofs.com. The author makes a nice point that home owners have many options when it comes to choosing carbon-neutral energy sources: he mentions solar, wind and even hydroelectric power. I cannot help but submit, respectfully, that this article completely misses the point.
There are, conventionally, five different sources of energy, four of which are carbon-neutral and only three of which can be said to be completely renewable:
But, as Thomas L. Friedman mentioned in his excellent Hot, Flat and Crowded (see my review here), there is a sixth energy source: the energy that we do not use.
And the key challenge we face as a race for the next century or so is to shift our energy consumption patterns more and more towards that sixth source, instead of trying to draw more and more energy from the four carbon-neutral ones.
We have the technology and we have the means, particularly when it comes to the energy needs of homes and buildings; it is only a question of bringing those possibilities to the global awareness, instead of letting people believe they will eventually be able to simple replace all coal-powered plants with wind mills.
Back in 2005, when I was writing Java software for an embedded home automation controller, we ran into a little unforeseen problem. The embedded virtual machine we were using implemented only the Java 1.3 API, and so did not offer any logging facilities (which only Java 1.4 started having).
We ended up using the logging implementation from the GNU Classpath project, but choosing a good logging framework in future projects will make a crucial difference for embedded applications that will run for months, if not years, unattended.
Here I recap the most popular Java logging frameworks of the day, and their relevance to the field of building automation.
ksvhbugq68
According to Eric Evans, the author of Domain-Driven Design:
Tackling Complexity in the Heart of Software, one of your first goals as domain analyst is to define what he calls an Ubiquitous Language, i.e., a common vocabulary that your technical team and your business sponsor will agree on, and will use to communicate. Having such a common vocabulary will prevent misunderstandings and will probably help you name things in your program, such as class and method names.
But what do you do when the business people seem unsure themselves of how to define certain concepts in their own domain? How do you even detect such situations?
I’ve found that certain words, when they begin to show up too often in conversations between the technical team and the business people, are good indicators that something needs to be clarified. Words such as object, element, perform, or do. But one word in particular seems to be particularly difficult to clarify once it has become accepted by business people: entity.
I was working on a business application that involved, well, entities that sold widgets in the world on behalf of a certain company. I asked the business people to help me understand what an entity was, or what exactly their responsibilities were.
So is, for instance, an entity associated with a country? Well no, because entity 33 is responsible for more than one country. Ok, so is an entity responsible for a geographic zone, including one or more countries? Well no, because see here, entity 12 handles all the sales in country Foo but only B2B sales in country Bar. The best definition they seemed to be able to come up with was that an entity was something that sold widgets to some people. Not exactly helpful.
Then I asked them a simple question. “Could you give me a dump from your database of the names of all your entities?” Sure enough, they did. And when I read the list of entities, I saw that they all were names of companies incorporated in their respective countries. “Say”, I asked, “aren’t these, like, subsidiaries?”
Subsidiaries they were indeed. It turned out that the company had segmented the market in each country in B2B and B2C products, and the company’s history explained why a given subsidiary got a given market segment in a given country, even in another country than its own.
This realization led to an immediate simplification of our class diagrams, and a lot of class renaming. But the resulting code is now much, much clearer, something even the business people admit.
It almost always pays off to work on redefining vague or incomplete terms. It will help you as a developer, and it might well help your customer too.
I’ve read Thomas Friedman’s “Hot, Flat and Crowded”, and firmly believe this book belongs on the shelf of anyone involved in making buildings more energy-effective.
Mr Friedman’s previous bestseller, “The World is Flat”, discussed the changes to our world that enabled more and more people to participate in a global economy. “Hot, Flat and Crowded” is sort of a sequel to that book, although there is no need to have read it first (I haven’t).
Mr Friedman’s thesis is that as more and more people participate in the global economy (”flat”), the standards of living are increased everywhere and world population grows (”crowded”), while more and more people aspire to a western style of life, with its damning consequences to the environment (”hot”).
According to Mr Friedman, the small habit changes that we are all asked to pick up (changing incadescent lights to more efficient lights, turning off our TVs instead of leaving it on standby, etc), while commendable, are simply insufficient. There is nothing we can do invidually to prevent atmospheric CO2 levels from reaching dangerously high levels in this century. Instead, he proposes a series of measures nations should take, such as imposing carbon taxes, cap-and-trade schemes, and several regulatory laws on energy efficiency for vehicules and buildings. Only such drastic measures, he argues, will make a significant difference.
An entire chapter, in particular, is dedicated to what he calls an “energy internet”, in which he envisions how a network of appliances and utilities could cooperate to dramatically reduce the energy demand for buildings. Buildings, incidentally, represent about 40% of any nation’s energy demand, and have this annoying property of being long lived. Once a building is built, it will consume energy and water for the next 30-40 years, which makes it all the more important to build them right from the beginning.
Contrary to many “green” books, though, Mr Friedman gives more arguments in favour of “going green” than the obvious environmental ones. There are at least two other, less obvious reasons why we should work on reducing our energy demand and developing renewable energy sources:
The arguments Mr Friedman develops for these aspects of the problem are worth the price of the book alone, in my opinion. But the real eye-opener is the extensive discussion on the way utilities have traditionally worked and how they should work in the future. He doesn’t say that our homes and buildings should simply become more efficient; he says that by wiring together buildings, appliances and utilities together, we can escape from local optimums in energy efficiency and aim for much more important savings.
And that, of course, is one of the aims of this blog: to bring together information on how to achieve that vision. We definitely have the technology (we have had it for the past 30 years or so), we only need the economic incentives to work on this problem. And Mr Friedman provides several suggestions that governments the world over could and should adopt, suggestions that will, if implemented, leave us no choice but to build the infrastructure he describes.
Wikipedia defines polyphasic sleep as the practice of sleeping multiple times in a 24-hour period. Proponents of this practice argue that it results in a much reduced total sleep requirement, sometimes as little as two hours total sleep per day.
This concept immediately caught my interest when I heard about it, as it should interest anyone who feels like they do not get enough sleep. I have a rather long train commute to work (one and a half hour each way), which makes it difficult for me to get what I believe should be my normal sleep hours.
Curious, I’ve decided to give it a tentative try. I cannot yet go the full “Uberman” way, taking 6 x 20 minutes naps in a 24 hours period (and nothing else), but I have been trying to get at least three naps in the day: one during each commute, and one after lunch. Having such long commutes turns out to be kind of a blessing, after all.
After one week practice, I do indeed feel much less tired in the evenings. I’m writing this post at half past ten on a Saturday evening, when I should normally be dead tired. Instead of that I’m wide awake and I think I’ll be writing some C code afterwards.
If you would like more information, here are some links that I have found helpful: