<?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"
	>

<channel>
	<title>My little Codelog</title>
	<atom:link href="http://www.codelog.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codelog.net</link>
	<description>Code snippets, tutorials and reviews for whom they might be useful.</description>
	<pubDate>Tue, 17 Jun 2008 10:58:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Restore SSH Public Key</title>
		<link>http://www.codelog.net/tips/restore-ssh-public-key</link>
		<comments>http://www.codelog.net/tips/restore-ssh-public-key#comments</comments>
		<pubDate>Tue, 17 Jun 2008 10:58:19 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[authentication]]></category>

		<category><![CDATA[private key]]></category>

		<category><![CDATA[public key]]></category>

		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.codelog.net/tips/restore-ssh-public-key</guid>
		<description><![CDATA[Today I did something stupid: I overwrote an SSH public key with a file from a different machine:
PLAIN TEXT
CODE:




scp id_rsa.pub user@example.org:~/.ssh 






Obviously, I wanted to place the Public Key for the account from one machine on the other one to append it to the authorized_keys file of the target account. Unfortunately, I didn't bear in [...]]]></description>
			<content:encoded><![CDATA[<p>Today I did something stupid: I overwrote an SSH public key with a file from a different machine:</p>
<div class="igBar"><span id="lcode-3"><a href="#" onclick="javascript:showPlainTxt('code-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-3">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">scp id_rsa.<span style="">pub</span> user@example.<span style="">org</span>:~/.<span style="">ssh</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Obviously, I wanted to place the Public Key for the account from one machine on the other one to append it to the <code>authorized_keys</code> file of the target account. Unfortunately, I didn't bear in mind that I already had a public key file (<code>id_rsa.pub</code>) in this directory. So I had to re-create the Public Key file from the Private Key. This is quite easy, it appears that the SSH developers already thought of this situation. The following code will restore the Public Key file from the Private Key (example for an RSA key):</p>
<div class="igBar"><span id="lcode-4"><a href="#" onclick="javascript:showPlainTxt('code-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-4">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cd ~/.<span style="">ssh</span>; echo <span style="color:#CC0000;">"id_rsa"</span> | ssh-keygen -y&gt; id_rsa.<span style="">pub</span> <span style="color:#800000;color:#800000;">2</span>&gt;/dev/null </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/tips/restore-ssh-public-key/feed</wfw:commentRss>
		</item>
		<item>
		<title>Shell script to optimize all tables in all databases (MySQL)</title>
		<link>http://www.codelog.net/codebits/shell-script-to-optimize-all-tables-in-all-databases-mysql</link>
		<comments>http://www.codelog.net/codebits/shell-script-to-optimize-all-tables-in-all-databases-mysql#comments</comments>
		<pubDate>Wed, 11 Jun 2008 10:03:22 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Codebits]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[OPTIMIZE TABLE]]></category>

		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.codelog.net/codebits/shell-script-to-optimize-all-tables-in-all-databases-mysql</guid>
		<description><![CDATA[If you have many databases with many write operations, it may be that the table overhead takes a good amount of space. (This is due to the fact that MySQL doesn't free the space of deleted entries.) With "optimizing" the tables, you can free that space.
Save the following script as /usr/local/sbin/optimizealltables.sh, make it chmod 700 [...]]]></description>
			<content:encoded><![CDATA[<p>If you have many databases with many write operations, it may be that the table overhead takes a good amount of space. (This is due to the fact that MySQL doesn't free the space of deleted entries.) With "optimizing" the tables, you can free that space.</p>
<p>Save the following script as <code>/usr/local/sbin/optimizealltables.sh</code>, make it <code>chmod 700</code> (very important!), then replace <em>YOURPASSWORD</em> with your root MySQL password.</p>
<div class="igBar"><span id="lcode-6"><a href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-6">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#!/bin/bash</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MYSQL_LOGIN=<span style="color:#CC0000;">'-u root --password=YOURPASSWORD'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">for db in $<span style="color:#006600; font-weight:bold;">&#40;</span>echo <span style="color:#CC0000;">"SHOW DATABASES;"</span> | mysql $MYSQL_LOGIN | grep -v -e <span style="color:#CC0000;">"Database"</span> -e <span style="color:#CC0000;">"information_schema"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">do</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; TABLES=$<span style="color:#006600; font-weight:bold;">&#40;</span>echo <span style="color:#CC0000;">"USE $db; SHOW TABLES;"</span> | mysql $MYSQL_LOGIN |&nbsp; grep -v Tables_in_<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; echo <span style="color:#CC0000;">"Switching to database $db"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; for table in $TABLES</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; do</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -n <span style="color:#CC0000;">" * Optimizing table $table ... "</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo <span style="color:#CC0000;">"USE $db; OPTIMIZE TABLE $table"</span> | mysql $MYSQL_LOGIN &gt;/dev/null</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo <span style="color:#CC0000;">"done."</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; done</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">done </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/codebits/shell-script-to-optimize-all-tables-in-all-databases-mysql/feed</wfw:commentRss>
		</item>
		<item>
		<title>Clear a sized select field</title>
		<link>http://www.codelog.net/codebits/clear-a-sized-select-field</link>
		<comments>http://www.codelog.net/codebits/clear-a-sized-select-field#comments</comments>
		<pubDate>Wed, 16 Apr 2008 10:20:06 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Codebits]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[multiple]]></category>

		<category><![CDATA[select]]></category>

		<category><![CDATA[size]]></category>

		<guid isPermaLink="false">http://www.codelog.net/codebits/clear-a-sized-select-field</guid>
		<description><![CDATA[If you have have a select form element with a size attribute, one common option for the user is to leave it empty (especially in combination with multiple). The problem is, as soon as one or more options are selected, it is quite impossible in most browsers, to not select anything at all. And even [...]]]></description>
			<content:encoded><![CDATA[<p>If you have have a <code>select</code> form element with a <code>size</code> attribute, one common option for the user is to leave it empty (especially in combination with <code>multiple</code>). The problem is, as soon as one or more options are selected, it is quite impossible in most browsers, to not select anything at all. And even if there is a way, it is not easy to accomplish. Try for yourself to deselect all items:</p>
<select size="3" style="font-size: 0.95em;" multiple="multiple">
  <option value="1">Item 1</option><br />
  <option value="2" selected="selected">Item 2</option><br />
  <option value="3">Item 3</option><br />
  <option value="4">Item 4</option><br />
</select>
<p>With a little JavaScript magic, we can offer a button to clear the select field:</p>
<div class="igBar"><span id="ljavascript-8"><a href="#" onclick="javascript:showPlainTxt('javascript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-8">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> nl_clear_select<span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> opt_length = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">options</span>.<span style="color: #006600;">length</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i = <span style="color: #CC0000;color:#800000;">0</span>; i &lt;opt_length; i++<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">options</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">selected</span> = <span style="color: #003366; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><script type="text/javascript">
function nl_clear_select(element)
{
	var opt_length = document.getElementById(element).options.length;
	for (var i = 0; i < opt_length; i++)
		document.getElementById(element).options[i].selected = false;
}
</script></p>
<p>Now try again to clear the select field. Hint: clicking on "Clear selection" will help a lot. <img src='http://www.codelog.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<select size="3" id="clear_me" style="font-size: 0.95em;" multiple="multiple">
  <option value="1">Item 1</option><br />
  <option value="2" selected="selected">Item 2</option><br />
  <option value="3">Item 3</option><br />
  <option value="4">Item 4</option><br />
</select>
<p><strong style='cursor: pointer;' onclick='nl_clear_select("clear_me")'>Clear selection</strong></p>
<p>Neat, eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/codebits/clear-a-sized-select-field/feed</wfw:commentRss>
		</item>
		<item>
		<title>Get radio button value in JavaScript</title>
		<link>http://www.codelog.net/codebits/get-radio-button-value-in-javascript</link>
		<comments>http://www.codelog.net/codebits/get-radio-button-value-in-javascript#comments</comments>
		<pubDate>Thu, 10 Apr 2008 11:14:28 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Codebits]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[radio buttons]]></category>

		<guid isPermaLink="false">http://www.codelog.net/codebits/get-radio-button-value-in-javascript</guid>
		<description><![CDATA[Here's how to get the currently checked value of radio button section. The parameter elementName is the name attribute of the radio input.
PLAIN TEXT
JavaScript:




function getRadioValue&#40;elementName&#41;


&#123;


&#160; &#160; var element = document.getElementsByName&#40;elementName&#41;;


&#160; &#160; var bt_count = element.length; // can't use element.length in the loop, as it would decrement


&#160;


&#160; &#160; for &#40;var i = 0; i &#60;bt_count; i++&#41;


&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Here's how to get the currently checked value of radio button section. The parameter <code>elementName</code> is the <em>name</em> attribute of the radio input.</p>
<div class="igBar"><span id="ljavascript-10"><a href="#" onclick="javascript:showPlainTxt('javascript-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-10">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> getRadioValue<span style="color: #66cc66;">&#40;</span>elementName<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> element = document.<span style="color: #006600;">getElementsByName</span><span style="color: #66cc66;">&#40;</span>elementName<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> bt_count = element.<span style="color: #006600;">length</span>; <span style="color: #009900; font-style: italic;">// can't use element.length in the loop, as it would decrement</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i = <span style="color: #CC0000;color:#800000;">0</span>; i &lt;bt_count; i++<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">checked</span> == <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> element<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">value</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/codebits/get-radio-button-value-in-javascript/feed</wfw:commentRss>
		</item>
		<item>
		<title>Calculate interest rates with a shell script</title>
		<link>http://www.codelog.net/codebits/calculate-interest-rates-with-a-shell-script</link>
		<comments>http://www.codelog.net/codebits/calculate-interest-rates-with-a-shell-script#comments</comments>
		<pubDate>Thu, 03 Apr 2008 11:06:55 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Codebits]]></category>

		<category><![CDATA[bank]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[duration]]></category>

		<category><![CDATA[loan]]></category>

		<guid isPermaLink="false">http://www.codelog.net/codebits/calculate-interest-rates-with-a-shell-script</guid>
		<description><![CDATA[If you put your cash to a bank account, you will want to know how much money you get with a certain amount at a given rate within a given period. Save the following Bash script as /usr/local/bin/loancalc (or something like that), make it executable, and you will be able to calculate the return on [...]]]></description>
			<content:encoded><![CDATA[<p>If you put your cash to a bank account, you will want to know how much money you get with a certain amount at a given rate within a given period. Save the following Bash script as <code>/usr/local/bin/loancalc</code> (or something like that), make it executable, and you will be able to calculate the return on your investments with a single one-liner.</p>
<div class="igBar"><span id="lcode-13"><a href="#" onclick="javascript:showPlainTxt('code-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-13">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#!/bin/bash</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">function calc<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; return $<span style="color:#006600; font-weight:bold;">&#40;</span>echo <span style="color:#CC0000;">"scale=$2; $1"</span> | bc<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC0000;">"$1"</span> == <span style="color:#CC0000;">"-h"</span> <span style="color:#006600; font-weight:bold;">&#93;</span> || <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#CC0000;">"$1"</span> == <span style="color:#CC0000;">"--help"</span> <span style="color:#006600; font-weight:bold;">&#93;</span>; then</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; echo <span style="color:#CC0000;">"$0 calculates the interest loan of a given amount with a given rate for a given duration."</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; echo <span style="color:#CC0000;">"Usage: $0 AMOUNT RATE DURATION"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; exit <span style="color:#800000;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fi</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#91;</span> -z <span style="color:#CC0000;">"$3"</span> <span style="color:#006600; font-weight:bold;">&#93;</span>; then</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; echo <span style="color:#CC0000;">"Please enter the amount, the rate and the duration (in this order)."</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; exit <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fi</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">AMOUNT=$<span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ZINS=$<span style="color:#800000;color:#800000;">2</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">DURATION=$<span style="color:#800000;color:#800000;">3</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"Investment: $AMOUNT bucks at a rate of $ZINS% for $DURATION years."</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Loan&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Total"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">for i in $<span style="color:#006600; font-weight:bold;">&#40;</span>seq <span style="color:#800000;color:#800000;">1</span> $DURATION<span style="color:#006600; font-weight:bold;">&#41;</span>; do</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; INTERESTLOAN=$<span style="color:#006600; font-weight:bold;">&#40;</span>echo <span style="color:#CC0000;">"scale=10; ($AMOUNT/100)*$ZINS"</span> | bc<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; AMOUNT=$<span style="color:#006600; font-weight:bold;">&#40;</span>echo <span style="color:#CC0000;">"scale=10; $AMOUNT+$INTERESTLOAN"</span> | bc<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; printf <span style="color:#CC0000;">"Year ${i} %8.2f "</span> $INTERESTLOAN; printf <span style="color:#CC0000;">" %14.2f<span style="color:#000099; font-weight:bold;">\n</span>"</span> $AMOUNT;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">done</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">printf <span style="color:#CC0000;">"Final amount: %1.2f bucks.<span style="color:#000099; font-weight:bold;">\n</span>"</span> $AMOUNT </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>For example:</p>
<div class="igBar"><span id="lcode-14"><a href="#" onclick="javascript:showPlainTxt('code-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-14">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">you@yourmachine ~ $ loancalc <span style="color:#800000;color:#800000;">3000</span> <span style="color:#800000;color:#800000;">3</span>.<span style="color:#800000;color:#800000;">5</span> <span style="color:#800000;color:#800000;">5</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Investment: <span style="color:#800000;color:#800000;">3000</span> bucks at a rate of <span style="color:#800000;color:#800000;">3</span>.<span style="color:#800000;color:#800000;">5</span>% for <span style="color:#800000;color:#800000;">5</span> years.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="">Loan</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Total</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Year <span style="color:#800000;color:#800000;">1</span>&nbsp; &nbsp;<span style="color:#800000;color:#800000;">105</span>.<span style="color:#800000;color:#800000;">00</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">3105</span>.<span style="color:#800000;color:#800000;">00</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Year <span style="color:#800000;color:#800000;">2</span>&nbsp; &nbsp;<span style="color:#800000;color:#800000;">108</span>.<span style="color:#800000;color:#800000;">68</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">3213</span>.<span style="color:#800000;color:#800000;">68</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Year <span style="color:#800000;color:#800000;">3</span>&nbsp; &nbsp;<span style="color:#800000;color:#800000;">112</span>.<span style="color:#800000;color:#800000;">48</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">3326</span>.<span style="color:#800000;color:#800000;">15</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Year <span style="color:#800000;color:#800000;">4</span>&nbsp; &nbsp;<span style="color:#800000;color:#800000;">116</span>.<span style="color:#800000;color:#800000;">42</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">3442</span>.<span style="color:#800000;color:#800000;">57</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Year <span style="color:#800000;color:#800000;">5</span>&nbsp; &nbsp;<span style="color:#800000;color:#800000;">120</span>.<span style="color:#800000;color:#800000;">49</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">3563</span>.<span style="color:#800000;color:#800000;">06</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Final amount: <span style="color:#800000;color:#800000;">3563</span>.<span style="color:#800000;color:#800000;">06</span> bucks. </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/codebits/calculate-interest-rates-with-a-shell-script/feed</wfw:commentRss>
		</item>
		<item>
		<title>Looks like document root, but is in a subfolder</title>
		<link>http://www.codelog.net/tips/looks-like-document-root-but-is-in-a-subfolder</link>
		<comments>http://www.codelog.net/tips/looks-like-document-root-but-is-in-a-subfolder#comments</comments>
		<pubDate>Sat, 12 Jan 2008 17:23:57 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Google Webmasters]]></category>

		<category><![CDATA[mod_rewrite]]></category>

		<category><![CDATA[Sitemaps]]></category>

		<guid isPermaLink="false">http://www.codelog.net/tips/13</guid>
		<description><![CDATA[Are you using Google Sitemaps, and does your website have very many pages? Then you will usually have a sitemap index file along with a number of sitemap files in your document root. Now, you might want to tidy up and move those sitemap files to a subfolder -- but that doesn't work, as Google [...]]]></description>
			<content:encoded><![CDATA[<p>Are you using Google Sitemaps, and does your website have very many pages? Then you will usually have a sitemap index file along with a number of sitemap files in your document root. Now, you might want to tidy up and move those sitemap files to a subfolder -- but that doesn't work, as Google requires the sitemap files to be in the document root. What to do? You can use <code>mod_rewrite</code> to solve this:</p>
<p>Create the directory <code>gg_sitemaps</code> and move your sitemaps index as well as all your sitemap files there.</p>
<p>Add the following line to the file <code>.htaccess</code> in your document root (if it doesn't exists, create it):</p>
<div class="igBar"><span id="lcode-17"><a href="#" onclick="javascript:showPlainTxt('code-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-17">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteRule ^<span style="color:#006600; font-weight:bold;">&#40;</span>sitemap.*<span style="color:#006600; font-weight:bold;">&#41;</span>$ /gg_sitemaps/$<span style="color:#800000;color:#800000;">1</span> <span style="color:#006600; font-weight:bold;">&#91;</span>L<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>(Note: This assumes that your sitemap index and the sitemaps files start with the string <code>sitemap</code>, e.g. your sitemap index file it could be <code>sitemaps.xml</code>, while the sitemaps files could be <code>sitemap0.xml</code>, <code>sitemap1.xml</code> and so on.)</p>
<p>Now your sitemaps are out of the document root, but Google will still see them as if they were in there.</p>
<p>By the way, this also works for the Google sitemaps verification files: If you want to verify your site in Google Webmasters, you need to upload a file to your document root. (You could also add a meta tag, but that's not so good.) Adding a single file isn't a problem, but if you want to allow different people to manage this domain in different Google Webmaster accounts, or if you have multiple domains in the same document root, you will need to upload more than one file. Again, we can solve this with some mod_rewrite magic:</p>
<p>Create the directory <code>gg_verify</code> and move all your verification files there.</p>
<p>Add another line to the file <code>.htaccess</code> in your document root:</p>
<div class="igBar"><span id="lcode-18"><a href="#" onclick="javascript:showPlainTxt('code-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-18">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteRule <span style="color:#006600; font-weight:bold;">&#40;</span>^google.*$<span style="color:#006600; font-weight:bold;">&#41;</span> /gg_verify/$<span style="color:#800000;color:#800000;">1</span> <span style="color:#006600; font-weight:bold;">&#91;</span>L<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Again, Google will think, the respective file is in the document root, while actually it is in the designated subfolder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/tips/looks-like-document-root-but-is-in-a-subfolder/feed</wfw:commentRss>
		</item>
		<item>
		<title>Optimize your CSS</title>
		<link>http://www.codelog.net/various/optimize-your-css</link>
		<comments>http://www.codelog.net/various/optimize-your-css#comments</comments>
		<pubDate>Sat, 22 Dec 2007 14:32:36 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Various]]></category>

		<category><![CDATA[Compression]]></category>

		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Loading Speed]]></category>

		<guid isPermaLink="false">http://www.codelog.net/various/optimize-your-css</guid>
		<description><![CDATA[CSS files are the most downloaded parts of a website, as they are usually loaded with every webpage. Also, CSS files usually contain a lot of, from a technical point of view, unnesseccery characters. Therefore it is a good idea to optimize your CSS file(s) for faster loading. A good tool to remove pretty much [...]]]></description>
			<content:encoded><![CDATA[<p>CSS files are the most downloaded parts of a website, as they are usually loaded with every webpage. Also, CSS files usually contain a lot of, from a technical point of view, unnesseccery characters. Therefore it is a good idea to optimize your CSS file(s) for faster loading. A good tool to remove pretty much all spare characters is the <a href="http://www.cssdrive.com/index.php/main/csscompressor/">CSS compressor</a>, which can reduce the file size of your CSS up to 25%. Of course, you should always keep a "source" version for modifications.</p>
<p>That tool of course is not able to optimize your CSS semantically, this must be done by you. Semantic optimization means that you should scrutinize your CSS file for <em>redundancy</em>. Do you possibly define <code>background-image</code>, <code>background-position</code> and <code>background-repeat</code> separately? Merge them into a single statement like <code>background: #fff url(image.png) top left;</code> -- you need the first ones only for overwriting a single other property. (That's why they are called <em>Cascading</em> Style Sheets.) Same goes for <code>margin</code>, <code>border</code> and <code>padding</code>  with their <code>-top</code>, <code>-right</code>, <code>-bottom</code>, <code>-left</code>: Use them only for overwriting. In all other cases, merge them into one statement: For example, <code>margin: 5px 2px;</code> will assign a margin of 5px to the top and bottom, and 2px to the left and right. <code>margin: 5px 2px 3px;</code> will assign a margin of 5px to the top, 2px to the left and right, and 3px to the bottom. And <code>margin: 5px 2px 3px 4px;</code> will assign a margin of 5px to the top, 2px to the right, 3px to the bottom, and 4px to the left.</p>
<p>Other possibilities: Consider using relative paths to images instead of absolute ones. Remove unneeded definitions (or comment them out before sending them through the compressor). Combine multiple selectors in a single one (e.g. if you have <code>#content_left a, #content_right a</code> it could be possible to use <code>#content a</code> instead).</p>
<p>Optimizing your CSS by compression and good semantical style will shrink your CSS by 30-60%. This will make the loading of a webpage from your website noticeably faster, even with a fast connection.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/various/optimize-your-css/feed</wfw:commentRss>
		</item>
		<item>
		<title>Codelog WordPress theme released</title>
		<link>http://www.codelog.net/various/codelog-wordpress-theme-released</link>
		<comments>http://www.codelog.net/various/codelog-wordpress-theme-released#comments</comments>
		<pubDate>Wed, 19 Dec 2007 21:14:59 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Various]]></category>

		<category><![CDATA[Codelog]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.codelog.net/various/codelog-wordpress-theme-released</guid>
		<description><![CDATA[I'm happy to announce the public release of the Codelog theme 0.1 for WordPress. The Codelog theme is a stylish and very lightweight two-column theme. If plain blogging is what you do, this theme is for you. The only features of this theme are fast loading, clean code and the elegant look. Ok, it also [...]]]></description>
			<content:encoded><![CDATA[<p>I'm happy to announce the public release of the Codelog theme 0.1 for WordPress. The Codelog theme is a stylish and very lightweight two-column theme. If plain blogging is what you do, this theme is for you. The only features of this theme are fast loading, clean code and the elegant look. Ok, it also comes with multi-language support (German translation already included). But that's it, less is more!</p>
<p>If you like the Codelog theme, <a href="/codelog-theme">download it</a> and give your blog a new look!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/various/codelog-wordpress-theme-released/feed</wfw:commentRss>
		</item>
		<item>
		<title>Improve loading speed of webpages by compressing HTML</title>
		<link>http://www.codelog.net/codebits/improve-loading-speed-of-webpages-by-compressing-html</link>
		<comments>http://www.codelog.net/codebits/improve-loading-speed-of-webpages-by-compressing-html#comments</comments>
		<pubDate>Tue, 18 Dec 2007 09:07:51 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Codebits]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Compression]]></category>

		<category><![CDATA[HTML]]></category>

		<category><![CDATA[Loading Speed]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codelog.net/codebits/improve-loading-speed-of-webpages-by-compressing-html</guid>
		<description><![CDATA[Here's a simple HTML "compressor" in PHP, which will reduce the size of HTML served to the client by 10 to 20 percent, depending on your indentation style and commenting. If many of your readers have lousy bandwidth, the slight overhead of this method is worth it.
PLAIN TEXT
PHP:




&#60;?php


&#160; &#160; function compress&#40;$content&#41;


&#160; &#160; &#123;


&#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a simple HTML "compressor" in PHP, which will reduce the size of HTML served to the client by 10 to 20 percent, depending on your indentation style and commenting. If many of your readers have lousy bandwidth, the slight overhead of this method is worth it.</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">function</span> compress<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$content</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$content</span> = <a href="http://www.php.net/preg_replace"><span style="color:#000066;">preg_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/[<span style="color:#000099; font-weight:bold;">\n</span><span style="color:#000099; font-weight:bold;">\t</span><span style="color:#000099; font-weight:bold;">\s</span>]+/s'</span>, <span style="color:#FF0000;">' '</span>, <span style="color:#0000FF;">$content</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$content</span> = <a href="http://www.php.net/preg_replace"><span style="color:#000066;">preg_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/&lt;!--.*?--&gt;/s'</span>, <span style="color:#FF0000;">''</span>, <span style="color:#0000FF;">$content</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$content</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/ob_start"><span style="color:#000066;">ob_start</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">require</span> <span style="color:#FF0000;">"/var/www/htdocs/somefile.php"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$content</span> = <a href="http://www.php.net/ob_get_contents"><span style="color:#000066;">ob_get_contents</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/ob_end_clean"><span style="color:#000066;">ob_end_clean</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> compress<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$content</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>By the way, if you have a rather hungry dynamic application (e.g. WordPress with certain plugins) on a rather weak server, consider using a caching solution like <a href="http://1blogcacher.com/">1 Blog Cacher</a>, so you don't have to regenerate the pages everytime somebody retrieves them. And, of course, consider using output gzip compression -- be it via webserver modules such as mod_gzip/mod_deflate or based on your web application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/codebits/improve-loading-speed-of-webpages-by-compressing-html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Copying is expensive, moving is cheap</title>
		<link>http://www.codelog.net/tips/copying-is-expensive-moving-is-cheap</link>
		<comments>http://www.codelog.net/tips/copying-is-expensive-moving-is-cheap#comments</comments>
		<pubDate>Mon, 17 Dec 2007 15:31:49 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[FTP]]></category>

		<category><![CDATA[Upload]]></category>

		<guid isPermaLink="false">http://www.codelog.net/?p=6</guid>
		<description><![CDATA[When you replace a comprehensive file tree via FTP, you will realize that it takes some time to do all the uploading. If your upload is going to replace old content, then one would usually first delete the old content, then upload the new one. (It is not a good idea to let the FTP [...]]]></description>
			<content:encoded><![CDATA[<p>When you replace a comprehensive file tree via FTP, you will realize that it takes some time to do all the uploading. If your upload is going to replace old content, then one would usually first delete the old content, then upload the new one. (It is not a good idea to let the FTP client overwrite old contents, unless one knows exactly how the client behaves. For example, some clients merge existing trees, not deleting old files that are expunged rather than replaced, thus potentially raising security problems.)</p>
<p>However, the procedure of first deleting and then copying can leave your site naked or uncomplete for a couple of endless minutes. In the worst case, a user retrieves a page from your incomplete site and causes a database corruption or messes up the internal settings (this is not too unlikely with CMS applications). Therefore, the better way is to first upload the new content under a different name and then rename folders.</p>
<p>For example, if your web documents are in <code>/var/www/docroot/</code>, you would usually do the following: You delete everything in that directory and then upload the new content -- which has the above mentioned side effects. Instead, you should better do the following: Upload all new content to <code>/var/www/docroot_new/</code>, rename <code>/var/www/docroot/</code> to <code>/var/www/docroot_old/</code>, finally rename <code>/var/www/docroot_new/</code> to <code>/var/www/docroot/</code>. Afterwards, you can delete <code>/var/www/docroot_old/</code>. Renaming is very fast, as only the base directory's name has to be changed in the filesystem.</p>
<p>With this method, your website will only be naked for a few seconds, and there won't be an incomplete installation at any time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codelog.net/tips/copying-is-expensive-moving-is-cheap/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
