Wednesday, September 12, 2012

Coffee/alcohol and dehydration

An interesting question which is very hard to find scientific information about on the internetz is this:

How much alcohol does a drink have to contain to give a net loss of fluid (i.e. act dehydrating)?

Unfortunately, there seems to be no simple answer on this question. A couple of sites cite nutrition experts, such as this one, where a lecturer claims that alcoholic beverages containing more than 10% alcohol gives a net loss; however, the percentage seems to be taken out of thin air. Update: This old study from 1941 hints that on an average every 10 g of alcohol makes you pee out 100 ml, which gives a limit on about 9% (100 g fluid and 10 g alcohol = 10/110 = 9.1%). This would indicate that normal strength beer (~5% alcohol) will actually hydrate you, as only about half of the fluid gets lost due to the diuretic effect of alcohol. However, the response varies highly among individuals.

There are also a couple of random people suggesting that the response is highly individual and dependent on a lot of other circumstances. An anonymous comment here (last comment), for example, suggests that low strengh beer hydrates most people whereas a whiskey does not (duh!). This study from 1997 tells us that drinking 4% beer is worse than drinking water for rehydrating, however it is not clear from the abstract if it has a net positive effect. In this study, results indicate that the diuretic action of alcohol lessens when already dehydrated.

Another, related, question is:

Does coffee really act dehydrating?

This question seems simpler to find an answer to, and that answer is simply no. In fact, under normal circumstances and when not exaggerating intake, coffee can be regarded as water from a hydrating point of view (Wikipedia lists a number of sources). So that coffee acts dehydrating seems to be a plain myth.

Exercise and alcohol

Some short notes about alcohol and exercise:

Many sources, as expected, makes it likely that drinking before or after exercise does not have any positive effects on health. However, there are exceptions, for example the study referenced here indicating that a low alcohol consumption (the equivalent of one pint beer) before exercising has a positive effect in that it reduces the level of clotting substances in the blood thereby having a thinning effect which reduces heart strain.

I have not found any studies showing any increased risks with a moderate alcohol (three beers or less) intake before training, however one should be aware that alcohol causes dehydration, and exercise also causes dehydration, so drinking water and keeping the body hydrated is always important, with or without alcoholic intake in conjunction with training. This study shows that after a little higher alcohol intake (1 g/kg body weight, equivalent to about 1,5 liter beer for a 75 kg person), heart rate increases significantly when exercising with a low intensity, whereas there are no significant change at high intensities. No significant change in systolic blood pressure could be seen.

According to this study, alcohol consumption in conjunction with exercise seem to have a negative effect on the hormone response, making the exercise in itself less effective. However, the negative effect started at 0.75 g/kg body weight (roughly 1 liter beer), and lesser consumption (0.5 g/kg) showed no effect. According to the same study, so called Non-endocrine physiological parameters (NEPP), such as heart rate, blood pressure, ventilation, frequency of breathing, tidal volume, oxygen consumption etc., were the same whether or not alcohol was consumed, indicating no immediate health risks associated with a moderate alcohol consumption.

There are a lot of studies showing that moderate alcohol intake benefits health, for example the study referenced here that shows that people drinking moderately and exercising (not simultaneously :)) has a 50% reduced risk of heart disease, whereas people just drinking, or just exercising, only has a 30% reduced risk.

For people trying to loose weight, alcohol intake seem to have a negative impact in the short term, but unexpectedly people drinking moderately actually weighs less than people that avoids drinking, according to this study. Some sources points out that it is not so much the alcohol in itself that causes weight gain, but the loss of self control introduced by alcohol, which causes intake of other, often high calorific, food. While the liver is engaged with getting rid of the alcohol, fat burning pauses, making the high calorific food in combination with alcohol worse from a weight loss perspective. An article with quite a lot of references on this topic could be found here.


Conclusion:
When searching for information on the topic training and alcohol, one gets a lot of interviews with "health people", such as personal trainers. They generally suggest that alcohol and training is an inappropriate combination, though mostly because the training effect decreases. However, it is hard to find scientific evidence saying that low or moderate alcohol consumption is dangerous or even makes exercise less effective.

Sunday, May 6, 2012

Handbrake in Ubuntu 12.04

As always with early adoption, a few things aren't there just yet. Handbrake, which is my favourite program for DVD ripping, has no stable release for Ubuntu 12.04. It is possible to use the snapshot repository, which is often stable enough, but I prefer to use a stable version, and also one which does not require updates all the time.

This time it worked out fine just adding the release repository (using apt-add-repository) and then manually changing the word precise to oneiric in /etc/apt/sources.list.d/stebbins-handbrake-releases-precise.list (followed by apt-get update and install handbrake-gtk). For some reason the binary handbrake is called ghb, which could be good to know if for some reason you would like to start it from the command line.

Another thing to notice, if there is a problem reading DVD:s, is to 1) enable the css (content scrambling system) thing, with
sudo /usr/share/doc/libdvdread4/install-css.sh
and 2) check whether it works better with libdvdread (uncheck use dvdnav under preferences->advanced).

However, most copying protection systems are not circumventable with handbrake, so you may have to use another application (possibly even on another OS) to get a clean ISO to work from.

Sunday, April 29, 2012

XBMC and Antec Fusion on Ubuntu 12.04

On Ubuntu 12.04, most things actually works out of the box. So, start by installing xbmc:
sudo apt-get install xbmc
A lot of things work right from the start, but to be able to configure every detail, we need lirc:
sudo apt-get install lirc
Lirc is to be configured with linux input layer (devinput). A quick test with
irw
shows that almost every button is recognized on the remote. To configure XBMC, add Lircmap.xml to your ~/.xbmc/userdata directory and adapt the devinput section.
Fix the remote control by installing lcdproc and editing /etc/LCDd.conf to use imonlcd as the driver.

Wednesday, February 29, 2012

Tri-state booleans

There are many cases when Java primitive wrappers are useful, and where null have a different meaning than the default value. However, there are one case where it mostly causes problems: in the java.lang.Boolean.

Using a java.lang.Boolean instead of the primitive type boolean often causes problems, mainly because of its tri-state nature. At first we can find it nice to be able to "define" a boolean as "not defined" (null), but it is much better to define a good default value, and design boolean variables so that "not (actively) defined" and false actually has the same meaning. If we need three states it is better to use an enum.

One immediate advantage of using primitive booleans is that we now can get rid of null checks:
if (valid != null && valid)
becomes
if (valid)  
The most important win, however, is that we now must take the right decision of what value the field should have at any particular moment. We cannot leave it in a state where we say ("I do not know what value to give this field, I just wait and see).

Sometimes the problem is inherited from a database table, in which a boolean field is not marked "NOT NULL" and therefore can have null, 0 or 1. I believe a system which allows this is badly designed.

Tuesday, February 28, 2012

Static imports in Eclipse

When working with testing frameworks such as Junit and Mockito, static imports are quite common. However, Eclipse does not handle those so well when pressing Ctrl+Enter, if they are not already imported. To hint Eclipse of which classes you want to look in for static imports, this handy trick could be useful: under
Java->Editor->Content Assist->Favorites
Choose new Type... and add org.mockito.Mockito and the other classes from which you need static methods.

Thanks to http://piotrjagielski.com/blog/working-with-static-imports-in-eclipse/

Friday, February 24, 2012

An embarrassing NullPointerException

I did a classical mistake today, yet it took me long enough to find the error. I got a NullPointerException on the following method call (somewhat simplified):
myMethod(myObject.getId());
I was totally sure myObject was not null, and even though I knew that the id was null I didn't bother as that should not be a problem...until I checked the method signature of myMethod:
public void myMethod(long value) {...}
As it takes a primitive long as argument, and myObject's id was the object Long, an implicit conversion is made in the calling moment, so the real code looks like:
myMethod(myObject.getId().longValue());
I'm a fan of auto-boxing and -unboxing, but sometimes I obviously have to be a little more observant.

Templating in Eclipse

A great but underused feature in Eclipse (and most other IDE:s) is code templates. I am often declaring a logger member variable which looks like this:
private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
To make this easier, I can create a template, by going to Window->Preferences, Java->Editor->Templates->New...
I fill in a shortcut, for example log, choose "Java Type Members" in the context select box, a short description and then in the "pattern" textarea I write:
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);

Now when I write log followed by Ctrl+Enter, I get the whole thing written for me.

Bean properties with the second letter uppercased

The Java bean specification lacks details in some areas, and how to handle properties with an initial lower case letter followed by an upper case letter is one of those (i.e aProperty). The problem appears when trying to create a getter for a property like this. Should it be called getAProperty or getaProperty?

It turns out that best practice seems to be to call it getaProperty, because of the special handling of properties with two leading upper case letters (See section 8.8 in the specification). GetAProperty could translate to the (approved) property name AProperty, because if a name has two leading upper case letters they are left untouched. Unfortunately, not all tools handle this equally, so JAXB for example creates the getter getAProperty from a schema property aProperty, while jersey/jackson does it right, making interoperabililty difficult.

My recommendation therefore is to avoid this kind of naming alltogether, to avoid those problems.

Thursday, February 23, 2012

JacksonJsonProvider, java.util.Date and java.sql.Date

Today I had a wonderful problem related to the different date objects in Java. I had made the mistake using rs.getDate() to get a date from the database, not realizing that I lose the time part in doing so. It however became apparent to me in an unusual way:

The problem I had was that an object like this
public MyObj {
  java.util.Date myDate; 
}
was serialized by Jackson to a date string "2012-01-05", without the time.

Everywhere I read it said that java.util.Date in Jackson is serialized using unix timestamp, so I did not understand from where this formatted string came. I dug a bit in the serialization process in Jackson and I saw that it was using a SqlDateSerializer to serialize the Date, which I found strange.

I then realized that when fetching the date from the database, I iterated through a ResultSet and set myDate using
myObj.setMyDate(rs.getDate("MY_DATE"));
, which of course is a big no-no. Not only do I lose the time part, but as java.sql.Date inherits from java.util.Date (thanks, jdbc designers) I get a creepy java.sql.Date object in myObj. This in turn caused Jackson to use the SqlDateSerializer, which serialize the dates as strings without time, which I am now happy for, as it made finding out what was wrong a little easier.

So the solution became quite simple; I instead used a method which null-checked rs.getTimestamp() and created my own real java.util.Date-object using
new java.util.Date(timestamp).