<?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>René Samselnig&#039;s Weblog &#187; dev</title>
	<atom:link href="http://sdm-net.org/tag/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://sdm-net.org</link>
	<description>Personal Entertainment and Knowledge Management</description>
	<lastBuildDate>Wed, 21 Dec 2011 06:08:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Take care of your images</title>
		<link>http://sdm-net.org/2008/11/take-care-of-your-images/</link>
		<comments>http://sdm-net.org/2008/11/take-care-of-your-images/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 10:12:07 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://sdm-net.org/?p=277</guid>
		<description><![CDATA[<p>You might have heard of the double post issue, which causes form data to be sent a second time to the server. This can be resolved by a HTTP redirect after the post has been processed. Today another problem occured to me, one that reminded me of that issue. I prepared an IMG tag to [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>You might have heard of the double post issue, which causes form data to be sent a second time to the server. This can be resolved by a HTTP redirect after the post has been processed. Today another problem occured to me, one that reminded me of that issue.<span id="more-277"></span></p>

<p>I prepared an IMG tag to display a specified image URL by setting the src attribute using JavaScript. The src attribute of that image has been left empty for that purpose (see code below).</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;imgWrapper&quot; style=&quot;display: none;&quot;&gt;
  &lt;img id=&quot;imgEl&quot; src=&quot;&quot; alt=&quot;Empty src attribute!&quot; /&gt;
&lt;/div&gt;</pre></td></tr></table></div>



<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> showImage<span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'imgEl'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> src<span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'imgWrapper'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>Later I discovered by using <a href="http://www.getfirebug.org">Firebug</a> that an additional request is being sent to the server. That request used the same path and query string as the original page request used. That way two tickets were added to the shopping cart instead of one. What was keeping me from discovering that issue earlier was that the first response from the server didn&#8217;t know yet about the second ticket &#8211; so the browser displayed only one ticket in the shopping cart. After reloading the second ticket showed up.</p>

<p>Some JavaScript debugging and HTML commenting later I found out that this behaviour comes from the IMG element with its empty src attribute. Firefox uses the currently called URL for that image to get its content! Even though the wrapping DIV is set to not display it the browser loads that images content.</p>

<p>Happy about figuring out what caused the problem I rewrote the JavaScript mechanism for displaying that specific image. Using the excellent <a href="http://www.prototypeapi.org">Prototype Library</a> the code snippet would look something like this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;imgWrapper&quot; style=&quot;display: none;&quot;&gt;
&lt;/div&gt;</pre></td></tr></table></div>



<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> showImage<span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> wrapper <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'imgWrapper'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> src<span style="color: #339933;">;</span>
  img.<span style="color: #660066;">alt</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Don<span style="color: #000099; font-weight: bold;">\'</span>t use an empty src attribute!'</span><span style="color: #339933;">;</span>
  wrapper.<span style="color: #660066;">update</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  wrapper.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  wrapper.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2008/11/take-care-of-your-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evaluation with untyped languages</title>
		<link>http://sdm-net.org/2008/10/evaluation-with-untyped-languages/</link>
		<comments>http://sdm-net.org/2008/10/evaluation-with-untyped-languages/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 10:52:39 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://sdm-net.org/?p=215</guid>
		<description><![CDATA[<p>When using JavaScript or PHP you need to keep in mind that these aren&#8217;t typed languages. Typed languages give us a lot of restrictions whilest keeping us from doing stupid things. Untyped languages do not have those restrictions so they leave us with a lot of freedom. Do we need this kind of freedom? Problem [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>When using JavaScript or PHP you need to keep in mind that these aren&#8217;t typed languages. Typed languages give us a lot of restrictions whilest keeping us from doing stupid things. Untyped languages do not have those restrictions so they leave us with a lot of freedom. Do we need this kind of freedom?
<span id="more-215"></span></p>

<h4>Problem</h4>

<p>A typed language defines types (such as integer, string, boolean, &#8230;) to variables &#8211; that way the contents of variables are clearly defined. When not having this restriction (as JavaScript doesn&#8217;t) one might do the following (JavaScript code):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> alpha <span style="color: #339933;">=</span> <span style="color: #3366CC;">'This is some String'</span><span style="color: #339933;">;</span>
alpha <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Most of the time this is OK, but there are times when you clearly need to know how values are evaluated. You might check for content if you need to do special things for special types. Let us assume you want to assign <code>alpha</code> a default value if it is empty (<code>''</code>). Your code might look like this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>alpha <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    alpha <span style="color: #339933;">=</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>This is perfectly OK if <code>alpha</code> is a string.</p>

<p>Nevertheless, <code>alpha</code> could always be an integer, too. And strangely, when the value of <code>alpha</code> is <code>0</code> (zero) the boolean expression <code>alpha == ''</code> evaluates to <strong>true</strong>! So <code>alpha</code> would become <code>'-'</code> in our case, which is not exactly what we intended to do, right? This could lead to some serious errors in your programme flow.</p>

<h4>Solution</h4>

<p>What can you do about it? Is there anything you could do? Yes, there is. When operating with values like <code>''</code> (empty string), <code>true</code>/<code>false</code> (boolean contents of variable) and <code>0</code> (zero) you should always use the strict equivalence operators: <code>===</code> (equals to and same type) and <code>!==</code> (not equals to or not same type). The above code would then look something like this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>alpha <span style="color: #339933;">===</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    alpha <span style="color: #339933;">=</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>That small change effects the semantics of the code. It now sets the default value if and only if the value of <code>alpha</code> is equals to <code>''</code> and the type of <code>alpha</code> is the same as the type of <code>''</code> (which is string, respectively). In fact, this is what you wanted to do, isn&#8217;t it?</p>

<p>If you use strict equivalence operators correctly then you can make sure the code does what you want it to do. Keep this in mind if you like writing correct code using untyped languages.</p>

<h4>See also</h4>

<p>Here are some useful links for JavaScript and PHP:</p>

<ul>
<li><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Comparison_Operators">JavaScript &#8211; Comparison Operators</a></li>
<li><a href="http://www.php.net/manual/en/language.expressions.php">PHP &#8211; Expressions</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2008/10/evaluation-with-untyped-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimised fotoalbum available</title>
		<link>http://sdm-net.org/2006/03/optimised-fotoalbum-available/</link>
		<comments>http://sdm-net.org/2006/03/optimised-fotoalbum-available/#comments</comments>
		<pubDate>Sun, 12 Mar 2006 14:06:43 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[fotoalbum]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2006/03/optimised-fotoalbum-available/</guid>
		<description><![CDATA[<p>Today I played a bit with my fotoalbum. I learned that I made a whole lot of database queries which are not necessary at all. So I began making optimisations to improve performance. After adding a query counter and looking at some queries and code I found out how to improve the behaviour given. The [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Today I played a bit with my <a href="/development/fotoalbum/">fotoalbum</a>. I learned that I made a whole <strong>lot</strong> of database queries which are not necessary at all. So I began making optimisations to improve performance.
<span id="more-76"></span></p>

<p>After adding a query counter and looking at some queries and code I found out how to improve the behaviour given. The thing that created most of the queries (>60%) was the recursive function <em>isPublished()</em>. But this function is needed to successfully tell if an image is published or not. So what to do? Use caching!</p>

<p>The cache did a good job, but could not reduce the number of queries the way I wanted it to be. So I tried harder on optimising queries, loops and object creation.</p>

<p>Finally I could gain a reduction of about <strong>93%</strong> of the queries made when it was not optimised at all. This is great, you know, because an image gallery should not eat that much server performance.</p>

<p>Well, go to <a href="/fotoalbum/">my installation of fotoalbum</a> if you&#8217;d like to see it in action. If you like it, then you can also  <a href="/download/">get a copy</a> of it! If something fails then please report it to <a href="/development/fotoalbum/">the fotoalbum page</a> so I can help you or at least fix the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2006/03/optimised-fotoalbum-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP Push Client in Posix C</title>
		<link>http://sdm-net.org/2006/02/http-push-client-in-posix-c/</link>
		<comments>http://sdm-net.org/2006/02/http-push-client-in-posix-c/#comments</comments>
		<pubDate>Fri, 03 Feb 2006 13:02:08 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2006/02/http-push-client-in-posix-c/</guid>
		<description><![CDATA[<p>Have you ever wanted to push a value to a HTTP page and don&#8217;t care about the result? Well, you can do it in pure C, but be prepared &#8211; it is not as trivial as you might think. Here is how to do it. Includes 1 2 3 4 #include &#60;stdio.h&#62; #include &#60;errno.h&#62; #include [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to push a value to a HTTP page and don&#8217;t care about the result? Well, you <em>can</em> do it in pure C, but be prepared &#8211; it is not as trivial as you might think. Here is how to do it.
<span id="more-72"></span></p>

<h4>Includes</h4>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;errno.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#include &lt;time.h&gt;</span></pre></td></tr></table></div>


<h5>Distinguish Windows from Unix/Linux</h5>

<p>We need to include <strong>winsock</strong> if we compile under Windows &#8211; otherwise use Unix/Linux headers for networking operations.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifdef _WIN32</span>
<span style="color: #339933;">#include &lt;winsock.h&gt;</span>
<span style="color: #339933;">#include &lt;io.h&gt;</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#include &lt;sys/types.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;netinet/in.h&gt;</span>
<span style="color: #339933;">#include &lt;netdb.h&gt;</span>
<span style="color: #339933;">#define closesocket(s) close(s)</span>
<span style="color: #339933;">#endif</span></pre></td></tr></table></div>


<h4>Defining the port to connect to</h4>

<p>The default port to connect to is 80. You can change it here if you need to.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define HTTP_PORT 80</span></pre></td></tr></table></div>


<h4>The <em>push_value</em> Function</h4>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>16
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> push_value<span style="color: #009900;">&#40;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>host<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>path<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>value <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></td></tr></table></div>


<h5>Variable Declarations</h5>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>17
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    time_t tt<span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>This is the place to save the actual date string to. It&#8217;s length is limited to 15 characters &#8211; 14 for the date string and one for the terminating \0 at the end.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>18
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #993333;">char</span> datum<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">15</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>The actual HTTP Request is being written to this variable.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>19
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #993333;">char</span> request<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">300</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>These are needed to create the socket/connection.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>20
21
22
23
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #993333;">struct</span> sockaddr_in server<span style="color: #339933;">;</span>
    <span style="color: #993333;">struct</span> hostent <span style="color: #339933;">*</span>host_info<span style="color: #339933;">;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> addr<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> sock<span style="color: #339933;">;</span></pre></td></tr></table></div>


<h5>Windows needs Winsock initialisation</h5>

<p>Windows TCP initialisation has to be done only if compiled under Windows.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifdef _WIN32</span>
    <span style="color: #993333;">short</span> wVersReq<span style="color: #339933;">;</span>
    WSADATA wsaData<span style="color: #339933;">;</span>
    wVersReq <span style="color: #339933;">=</span> MAKEWORD<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> WSAStartup<span style="color: #009900;">&#40;</span> wVersReq<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>wsaData <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fprintf<span style="color: #009900;">&#40;</span> stderr<span style="color: #339933;">,</span>
                 <span style="color: #ff0000;">&quot;Failed to init windows sockets<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#endif</span></pre></td></tr></table></div>


<h5>Get actual date</h5>

<p><code>strftime</code> creates the actual date into <em>datum</em>, it uses the format given (<em>&#8220;%Y%m%d%H%M%S&#8221;</em>) and the current time from <em>time(NULL)</em>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>34
35
36
37
38
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    tt <span style="color: #339933;">=</span> time<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    strftime<span style="color: #009900;">&#40;</span> datum<span style="color: #339933;">,</span>
              <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span> datum <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">&quot;%Y%m%d%H%M%S&quot;</span><span style="color: #339933;">,</span>
              localtime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>tt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h5>Create a socket</h5>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>39
40
41
42
43
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">        sock <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span> PF_INET<span style="color: #339933;">,</span> SOCK_STREAM<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> sock <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            perror<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;failed to create socket&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h5>Create struct for connection partner</h5>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>44
45
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    memset<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>server<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span> server <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> addr <span style="color: #339933;">=</span> inet_addr<span style="color: #009900;">&#40;</span> host <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> INADDR_NONE <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></td></tr></table></div>


<p><em>host</em> is a numerical IP Address. Nothing special has to be done.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>46
47
48
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">        memcpy<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>server.<span style="color: #202020;">sin_addr</span><span style="color: #339933;">,</span>
                <span style="color: #339933;">&amp;</span>addr<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span> addr <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span></pre></td></tr></table></div>


<p><em>host</em> is a domain name. Convert this domain name into a numerical IP Address.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">        host_info <span style="color: #339933;">=</span> gethostbyname<span style="color: #009900;">&#40;</span> host <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> NULL <span style="color: #339933;">==</span> host_info <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            fprintf<span style="color: #009900;">&#40;</span> stderr<span style="color: #339933;">,</span>
                     <span style="color: #ff0000;">&quot;unknown server: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                     host <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        memcpy<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>server.<span style="color: #202020;">sin_addr</span><span style="color: #339933;">,</span>
                host_info<span style="color: #339933;">-&gt;</span>h_addr<span style="color: #339933;">,</span>
                host_info<span style="color: #339933;">-&gt;</span>h_length <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>Set <em>server</em> parameters.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>60
61
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    server.<span style="color: #202020;">sin_family</span> <span style="color: #339933;">=</span> AF_INET<span style="color: #339933;">;</span>
    server.<span style="color: #202020;">sin_port</span> <span style="color: #339933;">=</span> htons<span style="color: #009900;">&#40;</span> HTTP_PORT <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h5>Create connection with partner</h5>

<p>Time to get together. Creating connection to server.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>62
63
64
65
66
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> connect<span style="color: #009900;">&#40;</span> sock<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> sockaddr<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>server<span style="color: #339933;">,</span>
                 <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span> server <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        perror<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;can't connect to server&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>Create HTTP 1.0 request with given value <em>value</em> and current time <em>datum</em>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>67
68
69
70
71
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    sprintf<span style="color: #009900;">&#40;</span> request<span style="color: #339933;">,</span>
             <span style="color: #ff0000;">&quot;GET %s?value=%s&amp;time=%s HTTP/1.0<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
             path<span style="color: #339933;">,</span>
             value<span style="color: #339933;">,</span>
             datum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Send created HTTP request to server. Ignore response, as it is not needed (see specification).</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>72
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    send<span style="color: #009900;">&#40;</span> sock<span style="color: #339933;">,</span> request<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span> request <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Close socket, we don&#8217;t need it anymore &#8211; &#8220;fire and forget&#8221;.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>73
74
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">    closesocket<span style="color: #009900;">&#40;</span> sock <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h4>Call push_value</h4>

<p>This is a small main function that gets the <em>host</em>, <em>path</em> and <em>value</em> from the command line and calls the <em>push_value</em> function. Originally for testing purpose only, but I left it in for you to test it on your own.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> argc <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">3</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fprintf<span style="color: #009900;">&#40;</span> stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;usage: %s host path value&quot;</span><span style="color: #339933;">,</span>
                 argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    push_value<span style="color: #009900;">&#40;</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h4>Conclusion</h4>

<p>With a shell script it would have been a lot easier. Given the above C programme we could create an equivalent bash shell script to do that:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;usage: $0 host path value&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #660033;">-1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #007800;">TIME</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #ff0000;">&quot;http://$1:80$2?value=$3&amp;time=<span style="color: #007800;">$TIME</span>&quot;</span></pre></td></tr></table></div>


<p>On the other hand this shell script takes about twice the time to complete than the C programme. Decide for yourself if it&#8217;s worth the cost.</p>

<p>If you like you can download the <a href="http://www.sdm-net.org/data/dev/pushclient.c">C Source Code</a> or the <a href="http://www.sdm-net.org/data/dev/pushclient.sh">Bash Script</a>. Compile the C programme with <code>gcc -o pushclient pushclient.c</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2006/02/http-push-client-in-posix-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Metaprogramming in C++</title>
		<link>http://sdm-net.org/2005/11/metaprogramming-in-c/</link>
		<comments>http://sdm-net.org/2005/11/metaprogramming-in-c/#comments</comments>
		<pubDate>Thu, 17 Nov 2005 20:31:28 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[metaprogramming]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2005/11/metaprogramming-in-c/</guid>
		<description><![CDATA[<p>Today I finished my work on a somehow special exam. Our grade of the course taught by Dr. Zoltán Porkoláb would be calculated by a C++-programme. We had one week to write a header file that is included in that programme. The main goal was to implement a priority queue for a hospital. A must-have [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Today I finished my work on a somehow special exam. Our grade of the course taught by <a href="http://gsd.web.elte.hu/">Dr. Zoltán Porkoláb</a> would be calculated by a C++-programme. We had one week to write a header file that is included in that programme.
<span id="more-43"></span></p>

<p>The <a href="http://aszt.inf.elte.hu/~gsd/klagenfurt/porkolab.html">main goal</a> was to implement a priority queue for a hospital. A must-have was to use templates to implement the so called <em>pqueue</em>. We were free to decide whether to use the <a href="http://www.sgi.com/tech/stl/">Standard Template Library</a> or not. My implementation uses the STL, though there&#8217;s a lot of understanding necessary. Anyway it is a lot easier than writing the data structures (like a list, vector, map, &#8230;) by hand.</p>

<p>Frankly, I had a lot to learn to write that programme, since I&#8217;m quite new to C++ and templating. But it&#8217;s done now, and I&#8217;m glad and relieved I&#8217;ve made it that far.</p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2005/11/metaprogramming-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fotoalbum r1176</title>
		<link>http://sdm-net.org/2005/10/fotoalbum-r1176/</link>
		<comments>http://sdm-net.org/2005/10/fotoalbum-r1176/#comments</comments>
		<pubDate>Thu, 13 Oct 2005 22:55:34 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[fotoalbum]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2005/10/fotoalbum-r1176/</guid>
		<description><![CDATA[<p>Hi folks. I&#8217;ve been working on fotoalbum to improve themes and using custom style sheets. Check it out, it is now capable of a new theme called sdm-fixed (which will evolve in the following versions of fotoalbum). Please send me feedback on how it works and how it could be improved. Changes There are no [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Hi folks. I&#8217;ve been working on fotoalbum to improve themes and using custom style sheets. Check it out, it is now capable of a new theme called sdm-fixed (which will evolve in the following versions of fotoalbum). Please send me feedback on how it works and how it could be improved.
<span id="more-38"></span></p>

<h6>Changes</h6>

<p>There are no new features except the support for themes. If you know <a href="http://smarty.php.net">Smarty</a> then you&#8217;ll be able to create new themes easily. If you don&#8217;t know Smarty, then go and get a look &#8211; it&#8217;s pretty simple and straight forward to use.</p>

<p>I removed the fotoalbum logo from the background at the bottom right because it made scrolling very slow. Instead I created a bar with information on the current view (albums, album, image, search) and added the logo there. This information bar replaces the information div on various places (not on all places though, because the image view needs to display much more information than available in the information bar).</p>

<h6>Download</h6>

<p>As usual I&#8217;ll give you a download link to the <a href="/data/fotoalbum/fotoalbum-r1176.tgz">new version of fotoalbum</a> and the corresponding <a href="/data/fotoalbum/fotoalbum-wp-plugin_0.3.0.zip">fotoalbum wordpress plugin</a>. If you need help give me some feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2005/10/fotoalbum-r1176/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GDM Theme: Green Meadow</title>
		<link>http://sdm-net.org/2005/10/gdm-theme-green-meadow/</link>
		<comments>http://sdm-net.org/2005/10/gdm-theme-green-meadow/#comments</comments>
		<pubDate>Wed, 12 Oct 2005 07:15:58 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[gdm]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2005/10/gdm-theme-green-meadow/</guid>
		<description><![CDATA[<p>Yesterday I found a great image I&#8217;m using now as my background image. It is called Green Meadow. But my GDM greeter didn&#8217;t fit to this image anymore, so I thought it would be nice to have a GDM theme with this image used as my greeter. This is why I made one. Green Meadow [...]</p>
]]></description>
			<content:encoded><![CDATA[<p><fotoalbum><image id="900" /></fotoalbum>
Yesterday I found a great image I&#8217;m using now as my background image. It is called Green Meadow. But my GDM greeter didn&#8217;t fit to this image anymore, so I thought it would be nice to have a GDM theme with this image used as my greeter. This is why I made one.
<span id="more-34"></span></p>

<h6>Green Meadow Image</h6>

<p>The image that was used can be found here: <a href="http://art.gnome.org/backgrounds/nature/1017">GNOME Art &#8211; Nature Backgrounds</a>.</p>

<h6>Download</h6>

<p>Of course you can download the <a href="/data/gdm/greenmeadow.tar.gz">Green Meadow GDM Theme</a>. Have fun using it and leave some comment if you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2005/10/gdm-theme-green-meadow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fotoalbum r1122</title>
		<link>http://sdm-net.org/2005/09/fotoalbum-r1122/</link>
		<comments>http://sdm-net.org/2005/09/fotoalbum-r1122/#comments</comments>
		<pubDate>Thu, 22 Sep 2005 17:20:51 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[fotoalbum]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2005/09/fotoalbum-r1122/</guid>
		<description><![CDATA[<p>A brand new version of my fotoalbum is out today. Grab it while it&#8217;s still hot! With it comes a renewed version of the fotoalbum WordPress plugin. Changes added a configuration screen using objects in templates removing the m:n relation between images and album made changes in templates, classes and others to map the new [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>A brand new version of my <a href="/2005/08/my-fotoalbum">fotoalbum</a> is out today. Grab it while it&#8217;s still hot! With it comes a renewed version of the <a href="/wordpress-fotoalbum-plugin">fotoalbum WordPress plugin</a>.
<span id="more-30"></span></p>

<h6>Changes</h6>

<p><fotoalbum><image id="803" /></fotoalbum></p>

<ul>
<li>added a configuration screen</li>
<li>using objects in templates</li>
<li>removing the m:n relation between images and album</li>
<li>made changes in templates, classes and others to map the new relation</li>
<li>an image is now an image without any more information than whats in the database. It has no more pointers in it</li>
<li>an album now holds all additional information about pages, next/prev image, limits, and so on</li>
<li>a date editor has been added to help people with the date of images and albums</li>
<li>many bugfixes</li>
</ul>

<h6>Download</h6>

<p>You can get the latest version by <a href="/data/fotoalbum">browsing the archive</a> or you can get it directly from here:</p>

<ul>
<li><a href="/data/fotoalbum/fotoalbum-r1122.tgz">fotoalbum r1122</a> for the fotoalbum</li>
<li><a href="http://www.sdm-net.org/data/fotoalbum/fotoalbum-wp-plugin_0.2.0.zip">fotoalbum WordPress plugin</a> for the WordPress plugin.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2005/09/fotoalbum-r1122/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fotoalbum plugin for WordPress</title>
		<link>http://sdm-net.org/2005/09/fotoalbum-plugin-for-wordpress/</link>
		<comments>http://sdm-net.org/2005/09/fotoalbum-plugin-for-wordpress/#comments</comments>
		<pubDate>Wed, 14 Sep 2005 22:24:22 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[fotoalbum]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/2005/09/fotoalbum-test/</guid>
		<description><![CDATA[<p>WordPress has so many fotoalbum plugins for galleries hosted by flickr or other online image databases. I made my own fotoalbum a few months ago and thus I wanted to create a plugin that can be used. It is designed to be simple and has only a few options yet, but you can already get [...]</p>
]]></description>
			<content:encoded><![CDATA[<p><fotoalbum><image id="461" /></fotoalbum>
WordPress has so many fotoalbum plugins for galleries hosted by flickr or other online image databases. I made my own <a href="/2005/08/my-fotoalbum">fotoalbum</a> a few months ago and thus I wanted to create a plugin that can be used. It is designed to be simple and has only a few options yet, but you can already get single thumbnails from fotoalbum images and even whole contents of an album as thumbnails. It also displays the title of the image and uses the current number of image on the page as prefix.
<span id="more-17"></span></p>

<h6>Overview</h6>

<p>This plugin is described in detail at the <a href="/wordpress-fotoalbum-plugin">WordPress fotoalbum Plugin</a> page. You&#8217;ll find the syntax, some more examples and a FAQ there. An example of using the fotoalbum Plugin by displaying an album is followed.</p>

<h6>Example</h6>

<p>My Friends Lena and Michi were on the I-Wolf concert at the pe_zwei in Klagenfurt. Michi had his faboulous Canon EOS 20D with him and took some great shots from the location and &#8211; whats more interesting &#8211; from I-Wolf and company. Because it was very dark he had to use a flash (Canon Speedlite 580EX) to lighten the room, which nevertheless creates high quality fotos. Let&#8217;s have a look.</p>

<p>This is the code I used to display the following album images.</p>

<p><fotoalbum ignore="true"><album id="20" /></fotoalbum></p>

<p><fotoalbum><album id="20" /></fotoalbum></p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2005/09/fotoalbum-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Holly Hack</title>
		<link>http://sdm-net.org/2005/09/the-holly-hack/</link>
		<comments>http://sdm-net.org/2005/09/the-holly-hack/#comments</comments>
		<pubDate>Wed, 07 Sep 2005 21:54:56 +0000</pubDate>
		<dc:creator>René Samselnig</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://www.sdm-net.org/wordpress/?p=6</guid>
		<description><![CDATA[<p>Today I found out about a solution to the Internet Explorer problem I recently had with my fotoalbum. I read about the Holly Hack that prevents Internet Explorer on Windows to behave abnormally and found out it may be a solution to my problem too. The Problem Image 1: fotoalbum float bug (IE) In my [...]</p>
]]></description>
			<content:encoded><![CDATA[<p>Today I found out about a solution to the Internet Explorer problem I recently had with <a href="/2005/08/my-fotoalbum/">my fotoalbum</a>. I read about the Holly Hack that prevents Internet Explorer on Windows to behave abnormally and found out it may be a solution to my problem too.
<span id="more-6"></span></p>

<h6>The Problem</h6>

<div class="left"><a href="/content/fotoalbumfloat_bug.png" target="_blank" rel="lightbox[6]"><img src="/content/thumb-fotoalbumfloat_bug.png" alt="Image showing float bug in IE." /></a><div class="fatitle">Image 1: fotoalbum float bug (IE)</div></div>

<p>In my fotoalbum I use a div for the content containing left-floated div&#8217;s (album covers and image thumbnails). This content div has a right margin such that the information div on the right side will not be overlapped by them. Mozilla Firefox does this very well, IE doesn&#8217;t like it that much. Below the bottom of the information div the thumbnails are floating to the right, ignoring the right margin. As you can imagine I was not quite happy about it. But that&#8217;s the way it is I thought.</p>

<h6>About Hacks</h6>

<p>Normally I don&#8217;t like browser hacks that much. They can be useful, but you never know in what way the next version of a browser is going to behave. Most hacks work around IE bugs, where there&#8217;s no other solution. I prefer using conditional comments when it comes to check for IE.</p>

<h6>Solution &#8211; the Holly Hack</h6>

<div class="left"><a href="/content/fotoalbumfloat_bug_solved.png" target="_blank" rel="lightbox[6]"><img src="/content/thumb-fotoalbumfloat_bug_solved.png" alt="Image showing float bug solved in IE." align="left" /></a><div class="fatitle">Image 2: fotoalbum float bug solved (IE)</div></div>

<p>The Holly Hack uses a CSS rule, that other browsers than IE simply ignore. <code>* html { ... }</code> is being assigned to an html element lying in any element in the DOM. Because the html element is the root element, standard compliant browsers do not apply this rule to any element. IE does. IE also needs a so called &#8220;hasLayout&#8221; property to be set to true &#8211; otherwise the dimension of the element will not be determined. So the CSS will look like this when applied:</p>

<p>* html {
    height: 1%;
    }</p>

<p>This time I found this hack useful, so I tried applying part of it to my style. I left out the <code>* html {}</code> snipped and only applied height: 1% to the <code>#content</code> rule to see what happens.</p>

<p>#content {
    &#8230;
    height: 1%;
    &#8230;
    }</p>

<p>It tells the element with id &#8220;content&#8221; to have a height of 1% of the visible browser height. That might have created other problems, so that I would have to use a workaround for that, but hey &#8211; it worked the way I hoped it would do! IE now floats correctly around the information div.</p>

<h6>Conclusion</h6>

<p>When you use floating of elements be very careful with IE. An element with no dimension (width, height, display) containing floated elements may be rendered abnormally and cause your layout to fail. To avoid this use a height or width where possible. If you can&#8217;t avoid it see if this workaround may help and doesn&#8217;t create more problems &#8211; else use conditional comments to import a special stylesheet.</p>
]]></content:encoded>
			<wfw:commentRss>http://sdm-net.org/2005/09/the-holly-hack/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

