<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andreas Joensen</title>
	<atom:link href="http://joensen.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://joensen.eu</link>
	<description>Endnu en WordPress-blog</description>
	<lastBuildDate>Thu, 01 Dec 2011 21:15:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Monty Hall paradox</title>
		<link>http://joensen.eu/2011/12/01/monty-hall-paradox/</link>
		<comments>http://joensen.eu/2011/12/01/monty-hall-paradox/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 21:15:25 +0000</pubDate>
		<dc:creator>Andreas Joensen</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[monty hall]]></category>
		<category><![CDATA[mythbusters]]></category>
		<category><![CDATA[paradox]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://joensen.eu/?p=86</guid>
		<description><![CDATA[I was watching the latest episode of Mythbusters where they tried to see if the Monty Hall paradox was true: Suppose you&#8217;re on a game show, and you&#8217;re given the choice of three doors: Behind one door is a car; &#8230; <a href="http://joensen.eu/2011/12/01/monty-hall-paradox/">Læs resten <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was watching the latest episode of Mythbusters where they tried to see if the Monty Hall paradox was true:</p>
<blockquote><p>Suppose you&#8217;re on a game show, and you&#8217;re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1 [but the door is not opened], and the host, who knows what&#8217;s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, &#8220;Do you want to pick door No. 2?&#8221; Is it to your advantage to switch your choice?</p></blockquote>
<p>Through different experiments they conclude that no one switches and you win more often by switching.</p>
<p>I remember learning about this in maths, so the results didn&#8217;t surprise me, but it&#8217;s still difficult not to fall into the trap of thinking that both doors still have a 50% chance after one of them have been opened. The problem lies in that the host knows which door has the car and the host opens the door after you pick your door. You can read about the problem here: <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem">http://en.wikipedia.org/wiki/Monty_Hall_problem</a></p>
<p>Naturally I wanted to test this programmatically, so I created this java code to test the paradox for 1 million games:</p>
<pre class="brush: java; title: ; notranslate">
		int wins = 0;
		int gameNr = 0;
		Random random = new Random();
		for (; gameNr &lt; 1000000; gameNr++) {
			// Host chooses a random winning door
			int winningDoor = random.nextInt(3);

			// Player chooses a random door
			int chosenDoor = random.nextInt(3);

			// Host opens a door that is not the winning or chosen.
			int openDoor;
			do {
				openDoor = random.nextInt(3);
			} while (openDoor == winningDoor || openDoor == chosenDoor);

			// Player switches his choice
			chosenDoor = 5 % (chosenDoor + openDoor + 2);

			// Host reveals the players choice and sees what's behind
			if (chosenDoor == winningDoor)
				wins++;
		}

		System.out.println(&quot;Wins: &quot; + wins);
		System.out.println(&quot;Loses: &quot; + (gameNr - wins));
</pre>
<p>The result confirms the mythbusters conclusion:</p>
<blockquote><p><code>Wins: 667297<br />
Loses: 332703</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://joensen.eu/2011/12/01/monty-hall-paradox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change IE compatibility in JSF</title>
		<link>http://joensen.eu/2011/11/27/change-ie-compatibility-in-jsf/</link>
		<comments>http://joensen.eu/2011/11/27/change-ie-compatibility-in-jsf/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 13:58:06 +0000</pubDate>
		<dc:creator>Andreas Joensen</dc:creator>
				<category><![CDATA[HTTP]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[X-UA-Compatible]]></category>

		<guid isPermaLink="false">http://joensen.eu/?p=43</guid>
		<description><![CDATA[Developing for internet explorer is a pain, due to them not adhering to standards for html, css, javascript and almost everything web related. Thankfully they have started following the standards all the other major browers use. The problem now is &#8230; <a href="http://joensen.eu/2011/11/27/change-ie-compatibility-in-jsf/">Læs resten <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Developing for internet explorer is a pain, due to them not adhering to standards for html, css, javascript and almost everything web related. Thankfully they have started following the standards all the other major browers use. The problem now is all the sites that were made to work in IE7, break in newer the newer versions that follow the standards. To fix this, microsoft introduced a compatitility mode in IE. The browser some how detects which version your website is made for, by looking at things like the DOCTYPE and tags specific to different IE versions. The problem is that it doesn&#8217;t always work and your site breaks, because IE turns on compatibility mode, even when the site follows the standards.</p>
<p>To fix this, microsoft has defined a meta tag you can put in your HTML, so you can override which IE version is chosen in compatibility mode. This can be because your site uses IE7 only markup and to make sure that it still works in newer browsers, you can tell IE to switch to IE7 mode. It could also be that you want to force IE to use the newest version, when it deceides to use the wrong version.</p>
<p>To do this you add the following META tag:</p>
<pre> &lt;meta http-equiv="X-UA-Compatible" content="IE=9" &gt;</pre>
<p>More information about the X-UA-Compatible meta tag can be found here: <a href="http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx</a></p>
<p>However, this won&#8217;t work if you use JSF to develop your website. The meta tag must be before any javascript, for IE to recognise the tag. This is not possible in JSF mojarra, since it puts the JSF related javascript before all other tags in the head element. Instead you must insert it into the header of the HTTP request.</p>
<p>This is done using a filter:</p>
<pre class="brush: java; title: ; notranslate">
package eu.joensen.filter;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

public class IEFilter implements Filter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletResponse res = (HttpServletResponse) response;
		res.addHeader(&quot;X-UA-Compatible&quot;, &quot;IE=Edge&quot;);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
	}
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}
}
</pre>
<p>This takes the response before it is delivered to the browser and adds a X-UA-Comaptible header field, where the value is which version you wish to enforce. I have chosen the Edge version, which is the latest version of IE, even when new versions are released.</p>
<p>To add the filter, you must add some configuration in the web.xml file:</p>
<pre class="brush: xml; title: ; notranslate">
	&lt;filter&gt;
		&lt;filter-name&gt;IEFilter&lt;/filter-name&gt;
		&lt;filter-class&gt;eu.joensen.filter.IEFilter&lt;/filter-class&gt;
	&lt;/filter&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;IEFilter&lt;/filter-name&gt;
		&lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
	&lt;/filter-mapping&gt;
</pre>
<p>First the filter is registered, where the filter-name is a string you choose. The filter-class is the java class you made to filter the response. Secondly you add a fitler-mapping, where you put the chosen filter-name in the first field and the expression to be filtered on in the url-pattern element in the second.</p>
<p>The HTTP reponse:</p>
<blockquote><pre class="brush: plain; highlight: [3]; title: ; notranslate">
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-UA-Compatible: IE=Edge
Accept-Ranges: bytes
ETag: W/&quot;453-1322401175000&quot;
Last-Modified: Sun, 27 Nov 2011 13:39:35 GMT
Content-Type: application/xhtml+xml
Content-Length: 453
Date: Sun, 27 Nov 2011 13:39:45 GMT
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://joensen.eu/2011/11/27/change-ie-compatibility-in-jsf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glassfish admin console on headless server</title>
		<link>http://joensen.eu/2011/11/25/glassfish-admin-console-on-headless-server/</link>
		<comments>http://joensen.eu/2011/11/25/glassfish-admin-console-on-headless-server/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 15:06:07 +0000</pubDate>
		<dc:creator>Andreas Joensen</dc:creator>
				<category><![CDATA[glassfish]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[administraion]]></category>
		<category><![CDATA[asadmin]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[headless]]></category>
		<category><![CDATA[password]]></category>

		<guid isPermaLink="false">http://joensen.eu/?p=22</guid>
		<description><![CDATA[The glassfish administraion console requires that you reach it from localhost, which I believe is for safety reasons. However, this is not possible if you want to reach the administraion console on a headless server without a X Server. You &#8230; <a href="http://joensen.eu/2011/11/25/glassfish-admin-console-on-headless-server/">Læs resten <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The glassfish administraion console requires that you reach it from localhost, which I believe is for safety reasons. However, this is not possible if you want to reach the administraion console on a headless server without a X Server. You could use a text only browser like lynx to navigate the admin console, which would work, but the console is not built for this senario, and it would be much easier to just use asadmin for everything instead.</p>
<p>First you must set the admin password, since it is now required, unlike when using the console from localhost. This is done use this command:</p>
<blockquote><p><code>asadmin change-admin-password</code></p></blockquote>
<p>Depending on which glassfish version, the default admin password is one of the following:</p>
<ul>
<li>&#8220;adminadmin&#8221;</li>
<li>&#8220;changeit&#8221;</li>
<li>no password</li>
</ul>
<p>It is also adviserable to set the master password for security reasons, which is done using this command:</p>
<blockquote><p><code>asadmin change-master-password</code></p></blockquote>
<p>When the password has been set, all you need to do is enable the secure admin console, which is not enabled by default:</p>
<blockquote><p><code>asadmin enable-secure-admin</code></p></blockquote>
<p>Then after a restart of the glassfish server, you should be able to access the admin console remotely.</p>
]]></content:encoded>
			<wfw:commentRss>http://joensen.eu/2011/11/25/glassfish-admin-console-on-headless-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

