<?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>Guy Rutenberg &#187; Tutorials</title>
	<atom:link href="http://www.guyrutenberg.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:53:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>phpMyAdmin + Lighttpd in Gentoo</title>
		<link>http://www.guyrutenberg.com/2009/01/20/phpmyadmin-lighttpd-in-gentoo/</link>
		<comments>http://www.guyrutenberg.com/2009/01/20/phpmyadmin-lighttpd-in-gentoo/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 16:14:57 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=248</guid>
		<description><![CDATA[Usually installing software in Gentoo is a piece of cake. Just emerge what you want and (with the right USE flags) and everything will be ready for you. However, as today I&#8217;ve found out today, installing phpMyAdmin with Lighttpd isn&#8217;t trivial as it should be.
In this post I&#8217;ll try to walk you through the necessary [...]]]></description>
			<content:encoded><![CDATA[<p>Usually installing software in Gentoo is a piece of cake. Just <code>emerge</code> what you want and (with the right USE flags) and everything will be ready for you. However, as today I&#8217;ve found out today, installing phpMyAdmin with Lighttpd isn&#8217;t trivial as it should be.</p>
<p>In this post I&#8217;ll try to walk you through the necessary steps to install phpMyAdmin with Lighttpd in Gentoo.<br />
<span id="more-248"></span></p>
<h3>Installing Lighttpd and PHP</h3>
<p>Before installing Lighttpd and PHP you&#8217;ll need to enable some USE flags. For Lighttpd you&#8217;ll need to at least enable the <code>php</code> and <code>fastcgi</code> USE flags. For PHP enable the <code>cgi</code>, <code>crypt</code>, <code>ctype</code>, <code>pcre</code>, <code>session</code>, <code>unicode</code>. The first one is required for working with Lighttpd, while the others are required for phpMyAdmin.</p>
<p>See the <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&#038;chap=2">handbook</a> for information about enabling USE flags.</p>
<p>Now install the packages</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">emerge -av lighttpd php</pre></div></div>

<p>After installation is complete, start the Lighttpd process</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/etc/init.d/lighttpd start</pre></div></div>

<p>and you should have a working Lighttpd server with PHP support.</p>
<h3>Installing phpMyAdmin</h3>
<p>phpMyAdmin depends on a package called <code>webapp-config</code>. While usually we let Portage take care of dependencies, this time we&#8217;ll have to install <code>webapp-config</code> manually before we install phpMyAdmin, so we can change its configuration for suit Lighttpd.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">emerge -av --oneshot webapp-config</pre></div></div>

<p>After installation is done edit using your favourite editor the <code>/etc/vhosts/webapp-config</code> and change the line:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">vhost_server=&quot;apache&quot;</pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">vhost_server=&quot;lighttpd&quot;</pre></div></div>

<p>Now we are ready to install phpMyAdmin.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">emerge -av phpmyadmin</pre></div></div>

<p>After installation is complete, you&#8217;ll need to create a phpMyAdmin configuration file</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cp /var/www/localhost/htdocs/phpmyadmin/config.sample.inc.php /var/www/localhost/htdocs/phpmyadmin/config.inc.php</pre></div></div>

<p>Now open the newly created configuration file and edit the line with the <code>blowfish_secret</code> (at the top of the file) as explained in it. An easy way to generate the password would be to use <a href="http://www.guyrutenberg.com/2008/05/04/spass-11-secure-password-generator/"><code>spass</code></a>.</p>
<p>Now if you use the default Lighttpd configurations you&#8217;re done. You can access the phpMyAdmin via <code>http://localhost/phpmyadmin</code>. If however you&#8217;ve changed the document root, there is one more step for you. Enable the <code>mod_alias</code> module in <code>/etc/lighttpd/lighttpd.conf</code> and append to the file</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">alias.url += (&quot;/phpmyadmin&quot; =&gt; &quot;/var/www/localhost/htdocs/phpmyadmin&quot;)</pre></div></div>

<p>and don&#8217;t forget to restart the Lighttpd server after making the changes.</p>
<p>You should have by now everything installed and configured to work. If you have any further questions don&#8217;t hesitate to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/01/20/phpmyadmin-lighttpd-in-gentoo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Understanding load average &#8211; A Practitioner Guide</title>
		<link>http://www.guyrutenberg.com/2008/07/25/understanding-load-average-a-practitioner-guide/</link>
		<comments>http://www.guyrutenberg.com/2008/07/25/understanding-load-average-a-practitioner-guide/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 08:50:34 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=61</guid>
		<description><![CDATA[The term &#8220;load average&#8221; is used in many Linux/UNIX utilities. Everybody knows that the numbers the term &#8220;load average&#8221; refers to, usually three numbers, somehow represent the load on the system&#8217;s CPU. In this post I&#8217;ll try making this three numbers clearer and understandable.

The easiest way to see the &#8220;load average&#8221; of your system is [...]]]></description>
			<content:encoded><![CDATA[<p>The term &#8220;load average&#8221; is used in many Linux/UNIX utilities. Everybody knows that the numbers the term &#8220;load average&#8221; refers to, usually three numbers, somehow represent the load on the system&#8217;s CPU. In this post I&#8217;ll try making this three numbers clearer and understandable.<br />
<span id="more-61"></span><br />
The easiest way to see the &#8220;load average&#8221; of your system is by <code>uptime</code>.It also appears in <code>top</code> and can be graphed in the console by <code>tload</code> . In all three cases the load average refers to a group of three numbers. For example, in the following output of <code>uptime</code></p>
<pre>
10:41:47 up 5 days, 48 min,  1 user,  load average: 0.82, 0.71, 0.66
</pre>
<p>the last three numbers are the &#8220;load average&#8221;. Each number represent the systems load as a moving average over 1, 5 and 15 minutes respectively. Now, the important thing is to understand what is being averaged, the load metric.</p>
<p>The metric that represent the load at a given point in time is  how many process are queued for running at each given time (including the process that is currently being ran). Generally speaking, on a single core machine, this can be looked at as CPU utilization percentage when multiplied by 100. For example if I had a load-average of 0.50 in the last minute, this means that over the last minute half of the time the CPU was idle as it had no running process. On the other hand if I had load average of 2.50 it means that over the last minute an average of 1.5 process were waiting to their turn to run. so the CPU was overloaded by 150%.</p>
<p>On a multi-core systems things are a bit different, but in order to avoid unnecessary complications one can usually divide the load-average by the number of cores an treat the result as the load average of single core machine. For example let&#8217;s say the load average of a two-core machine was 3.00 2.00 0.50. This means that over the last minute we had an average of three runnable process, this means that one process, in average, was queued as there are two core in the machine that can run to process at a time. So the machine was overloaded had a load of 150% its capability. Over the last 5 minutes the load average of 2.00 means that we roughly had 2 process running each time, so the machine was fully utilized but wasn&#8217;t overloaded by work. On the other hand over last 15 minutes the load-average of 0.50 means that we could handle 4 time that load without overloading the CPU, we only had (0.50/2)*100=25% CPU utilization in that 15 minutes.</p>
<p>I hope I made the load-average a bit more clearer using the above example. Load-average is an important metric for measuring a system performance, and good understanding of it is beneficial. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/07/25/understanding-load-average-a-practitioner-guide/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim</title>
		<link>http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/</link>
		<comments>http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 19:27:11 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[wxWidgets]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/</guid>
		<description><![CDATA[I use Vim as my main IDE for C/C++ related development (as well as for almost all other development). If you use (or thinking about using) vim as as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by the OmniComplete, which is available since Vim 7.0. Just having [...]]]></description>
			<content:encoded><![CDATA[<p>I use Vim as my main IDE for C/C++ related development (as well as for almost all other development). If you use (or thinking about using) vim as as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by the OmniComplete, which is available since Vim 7.0. Just having  the OmniComplete is a nice thing, but it&#8217;s much more helpful if configured properly to work with the libraries you use, such as wxWidgets. In this post I will show you how to get working the OmniComplete for wxWidgets, however, the procedure I will show can be easily adapted to almost all libraries.<br />
<span id="more-41"></span></p>
<p>The first step is to install <code>ctags</code> (if you haven&#8217;t got it already installed), this provides the tags file, on which the autocompletion is based. <code>ctags</code> is available directly from the package manager of all popular distro&#8217;s.</p>
<p>The next step is to install the <a href="http://www.vim.org/scripts/script.php?script_id=1520">OmniCppComplete</a> plugin for vim. The plugin uses the <code>ctags</code>&#8216; generated tags file for the autocompletion. In order for the autocompletion to properly work with classes, you need to create the <code>~/.ctags</code> file and add some default options. Each option should be listed in a newline. Your <code>~/.ctags</code> file should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">--c++-kinds=+p
--fields=+iaS
--extra=+q</pre></div></div>

<p>These options will now be used as default when running <code>ctags</code>.</p>
<p>The next step is to create a tag file for the wxWidgets library. This can be done using the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"> ctags -f ~/.vim/wxwidgetstags -R /usr/include/wx-2.8</pre></div></div>

<p>Don&#8217;t forget to replace <code>/usr/include/wx-2.8</code> with the path to the header files of wxWidgets. This will create the tags file under your <code>~/.vim</code> directory.</p>
<p>The next step is to tell vim to use this tags file. This is done by adding the following line to your <code>~/.vimrc</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">:set tags+=~/.vim/wxwidgetstags</pre></div></div>

<p>And now your done. OmniComplete will now work for wxWidgets, listing members and functions for any of the wxWidgets classes.<br />
Remember you can repeat the last two steps for any other libraries you use in order for the OmniComplete to work with them too.</p>
<p>N.B. don&#8217;t forget to run <code>ctags -R .</code> in your projects root dir if you want OmniComplete to work for classes you defined.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/02/23/setting-up-omnicomplete-autocompletion-for-wxwidgets-in-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Local SVN Repository (Home Repository)</title>
		<link>http://www.guyrutenberg.com/2007/10/29/creating-local-svn-repository-home-repository/</link>
		<comments>http://www.guyrutenberg.com/2007/10/29/creating-local-svn-repository-home-repository/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 06:39:36 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/10/29/creating-local-svn-repository-home-repository/</guid>
		<description><![CDATA[In this tutorial I will explain how to create a local Subversion (SVN) repository, intended for a single user. I assume that you already know the benefits of keeping track of old revision of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I will explain how to create a local Subversion (SVN) repository, intended for a single user. I assume that you already know the benefits of keeping track of old revision of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient yet strong method to do so, and the easiest way to do so with Subversion (SVN) is to create a local, home, repository intended for a single user &#8211; you.<br />
<span id="more-26"></span><br />
The repository we are going to create will be used by a single user, working locally on the machine. In this tutorial I will assume the repository will be created for a project called &#8220;project1&#8243;. &#8220;project1&#8243; can be a real project you are doing, a paper you are writing or any thing else that can be stored under revision control (that almost everything).</p>
<h4>Creating the repository</h4>
<p>We will start by creating the repository. From the command line do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mkdir /home/user/svnrep
$ cd ~/svnrep
$ svnadmin create project1</pre></div></div>

<p>In the first line we create a directory to house all of your repositories (I assume you are working under the username &#8220;user&#8221;). I prefer to use different repositories for different projects that are unrelated, no matter how small they are. Because I use many repositories, I prefer to have a single directory  underneath all repositories will reside in an organized way (i.e. no junk files or any other kind of stuff except directories). Next thing, is to <code>cd</code> into the directory we created, and actually create the repository using the <code>svnadmin</code> command. To repository we&#8217;ve created is called &#8220;project1&#8243;. </p>
<p>The brand new &#8220;project1&#8243; repository is currently empty and in revision 0. This will change once we put some data in it. The first thing you do with a new repository is to import initial project data into it.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ svn import /home/user/project1 file:///home/user/svnrep/project1/trunk -m &quot;Initial import of project1&quot;</pre></div></div>

<p>Will import the current project1&#8217;s file into the repository (assuming that project1 indeed resides in <code>/home/user/project1</code>). The </code>trunk</code> appended to the end of the repository URL, is part of the directory layout convention used by many Subversion users. The last part of the command is the message that will be attached to the import in the SVN log.</p>
<p>Now the repository holds data and you are ready to checkout the code from it, and start working.</p>
<h4>Checkout a Working Copy and Start Working</h4>
<p>When using SVN (as well as in most revision control systems) you don't work directly on the repository. Instead you checkout a working copy from it, and work on this copy. To checkout a working copy from the repository, use:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ svn co file:///home/user/svnrep/project1/trunk /home/user/project1_work</pre></div></div>

<p>This will create a working copy of the repository under <code>/home/user/project1_work</code>. You can edit this copy safely. </p>
<p>After you've done editing your working copy, you will want to commit those changes back to the repository. Assuming you are already inside the directory of the working copy, just do:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ svn commit -m &quot;Some log message&quot;</pre></div></div>

<p>This will send you changes back to the repository and store them there. Change the "Some log message" to some useful short description of the changes you've made.</p>
<h4>Some Useful Commands</h4>
<p>To view a list of log messages that were attached to the operations on the repository, use:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ svn log
$ svn log -r 5:HEAD</pre></div></div>

<p>The first command will print all log messages. The second command will print the log messages from revision 5 to the latest revision. You can substitute the <code>HEAD</code> with a number to get the log messages of the revisions up to a specific one.</p>
<p>To view the changes you made before committing your code, use:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ svn diff</pre></div></div>

<p>Another important command is the one to update your working copy with the latest revision from the repository. This can be done using:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ svn update</pre></div></div>

<p>However, since your are the only user of the local repository, you won't have to use this function often (if at all), unless you use two, or more, working copies for your project.</p>
<p>This concludes this tutorial. I hope you know by now how to create and use, a single user local SVN repository. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/10/29/creating-local-svn-repository-home-repository/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>ssh-keygen Tutorial &#8211; Generating RSA and DSA keys</title>
		<link>http://www.guyrutenberg.com/2007/10/05/ssh-keygen-tutorial-generating-rsa-and-dsa-keys/</link>
		<comments>http://www.guyrutenberg.com/2007/10/05/ssh-keygen-tutorial-generating-rsa-and-dsa-keys/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 09:32:26 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ssh-keygen]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/10/05/ssh-keygen-tutorial-generating-rsa-and-dsa-keys/</guid>
		<description><![CDATA[In this post I will walk you through generating RSA and DSA keys using ssh-keygen. Public key authentication for SSH sessions are far superior to any password authentication and provide much higher security. ssh-keygen is the basic way for generating keys for such kind of authentication. I will also explain how to maintain those keys [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will walk you through generating RSA and DSA keys using <code>ssh-keygen</code>. Public key authentication for SSH sessions are far superior to any password authentication and provide much higher security. <code>ssh-keygen</code> is the basic way for generating keys for such kind of authentication. I will also explain how to maintain those keys by changing their associated comments and more importantly by changing the passphrases using this handy utility.<br />
<span id="more-22"></span></p>
<h4>Generating Keys</h4>
<p>Generating public keys for authentication is the basic and most often used feature of <code>ssh-keygen</code>. <code>ssh-keygen</code> can generate both RSA and DSA keys. RSA keys have a minimum key length of 768 bits and the default length is 2048. When generating new RSA keys you should use at least 2048 bits of key length unless you really have a good reason for using a shorter and less secure key. The key length for DSA is always 1024 bits as specified in <a href="http://csrc.nist.gov/publications/fips/fips186-2/fips186-2-change1.pdf">FIPS 186-2</a>. Because DSA key length is limited to 1024, and RSA key length isn&#8217;t limited, so one can generate much stronger RSA keys than DSA keys, I prefer using RSA over DSA. Another reason for not using DSA is that DSA is a government standard and one may wonder if the key length was limited deliberately so it will be possible for government agencies to decrypt it.</p>
<p>To generate a pair of public and private keys execute the following command:<br />
<code>ssh-keygen -t rsa -b 2048</code><br />
You can use &#8220;dsa&#8221; instead of the &#8220;rsa&#8221; after the <code>-t</code> to generate a DSA key. The number after the <code>-b</code> specifies the key length in bits.</p>
<p>After executing the command it may take some time to generate the keys (as the program waits for enough entropy to be gathered to generate random numbers). When the key generation is done you would be prompted to enter a filename in which the key will be saved. The public key will have the same filename but it will end with <code>.pub</code>. You should make sure that the key can only be read by you and not by any other user for security reasons. </p>
<p>Next you&#8217;ll be prompted to enter a passphrase. Each generated key can be protected by a passphrase. When a key is generated with a passphrase, the key can&#8217;t be used without the passphrase, so by using a passphrase one can prevent others from using his private keys without first guessing the passphrase. A good passphrase should be at least 10 characters long. One should stay away from English sentences as their entropy level is just too low to be used as a safe passphrase. I usually use a randomly generated passphrase, as this kind is considered the most secure. If you intend to use the key for accessing a remote machine from inside an automated script you may wish to enter an empty password, so the script won&#8217;t need user interaction. In this case just press <code>&lt;ENTER&gt;</code> twice.<br />
If you create a passphrase-less key just make sure you only put it on trusted hosts as it may compromise the remote machine if the key falls to the wrong hands.</p>
<p>After entering you passphrase twice the program will print the key fingerprint, which is some kind of hashing used to distinguish different keys, followed by the default key comment (more on key comments later). After printing the key information the program will terminate. Congratulations, you&#8217;ve just created you own public key using <code>ssh-keygen</code>.</p>
<h4>Comments</h4>
<p>Adding comments to keys can allow you to organize your keys more easily. The comments are stored in end of the public key file and can be viewed in clear text. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cat id_rsa2.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyyA8wePstPC69PeuHFtOwyTecByonsHFAjHbVnZ+h0dpomvLZxUtbknNj3+c7MPYKqKBOx9gUKV/diR/mIDqsb405MlrI1kmNR9zbFGYAAwIH/Gxt0Lv5ffwaqsz7cECHBbMojQGEz3IH3twEvDfF6cu5p00QfP0MSmEi/eB+W+h30NGdqLJCziLDlp409jAfXbQm/4Yx7apLvEmkaYSrb5f/pfvYv1FEV1tS8/J7DgdHUAWo6gyGUUSZJgsyHcuJT7v9Tf0xwiFWOWL9WsWXa9fCKqTeYnYJhHlqfinZRnT/+jkz0OZ7YmXo6j4Hyms3RCOqenIX1W6gnIn+eQIkw== This is the key's comment</pre></div></div>

<p>As you can see the comment is appended in clear text to the end of the public key file. To alter the comment just edit the public key file with a plain text editor such as <code>nano</code> or <code>vim</code>.<br />
To add a comment to the public key file when generating the key add to the key generation command <code>-C "you comment"</code>. For example to generate 4048 bit RSA key with &#8220;home machine&#8221; as a comment you will do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ssh-keygen -b 4048 -t rsa -C &quot;home machine&quot;</pre></div></div>

<p>Notice that each copy of a public key can have its own comment and you cannot retrieve the comment from the private key.</p>
<h4>Passphrases</h4>
<p>Passphrases allow you to prevent unauthorized usage of your key by meaning of protecting the key itself by a password. Although your ssh directory holding the private keys should be unaccessible to other users, the root user of the system, or anyone who can achieve is privileges can access your key and copy it. In this case the passphrase will prevent him from using it. </p>
<p>To add a passphrase to a key just type it when prompted during the key generation process. Keep in mind that the password must be at least 5 characters long. A good passphrase, as I said before, should be at least 10 characters long, and consist of random upper and lower case letters, numbers and symbols.</p>
<p>While the passphrase boosts the security of the key, under some conditions you may want to leave it empty. Leaving the passphrase empty allows you to use the key from within scripts, for example to transfer a file via <code>scp</code>. While passphraseless keys are very useful for scripts just remember to only use them at trusted machines.</p>
<p>You can change the passphrase of key after it&#8217;s been created, and you should do it at least annually. To change the passphrase execute:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ssh-keygen -p</pre></div></div>

<p>After this you will be prompted to enter the location of your private key and enter twice the new passphrase. If you don&#8217;t want a passphrase just enter empty one.</p>
<h4>End Notes</h4>
<p>Feel free to share your public key, as its name suggests, it should be public. Keep in mind that your private key should be kept private. If someone gets hold of your private key, change it imediatly, even if it&#8217;s passphrase protected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/10/05/ssh-keygen-tutorial-generating-rsa-and-dsa-keys/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Profiling Code Using clock_gettime</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/</link>
		<comments>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comments</comments>
		<pubDate>Sat, 22 Sep 2007 08:55:16 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/</guid>
		<description><![CDATA[After raising the issue of the low resolution problem of the timer provided by clock() in Resolution Problems in clock(), I&#8217;ve ended the post by mentioning to two more functions that should provide high-resolution timers suitable for profiling code. In this post I will discuss one of them, clock_gettime().

The clock_gettime() provides access to several useful [...]]]></description>
			<content:encoded><![CDATA[<p>After raising the issue of the low resolution problem of the timer provided by <code>clock()</code> in <a href="">Resolution Problems in <code>clock()</code></a>, I&#8217;ve ended the post by mentioning to two more functions that should provide high-resolution timers suitable for profiling code. In this post I will discuss one of them, <code>clock_gettime()</code>.<br />
<span id="more-18"></span><br />
The <code>clock_gettime()</code> provides access to several useful timers with the resolution of nanoseconds. First, the prototype for the function is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> clock_gettime<span style="color: #009900;">&#40;</span>clockid_t clk_id<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> timespect <span style="color: #339933;">*</span>tp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The <code>clk_id</code> allows us to select a specific clock from the several<br />
offered by the system, which includes:</p>
<ul>
<li>
	<code>CLOCK_REALTIME</code>, a system-wide realtime clock.
	</li>
<li>
	<code>CLOCK_PROCESS_CPUTIME_ID</code>, high-resolution timer provided by the CPU for each process.
	</li>
<li>
	<code>CLOCK_THREAD_CPUTIME_ID</code>, high-resolution timer provided by the CPU for each of the threads.
	</li>
</ul>
<p>Usually, there are more clocks provided, but I find these three the most useful as they allow to get the execution time spent in the system level, process level and the thread level.</p>
<p>The current clock time, for the chosen clock is stored int the struct provided by the <code>*tp</code> pointer. The <code>timespec</code> struct is defined as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> timespec <span style="color: #009900;">&#123;</span>
	time_t tv_sec<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* seconds */</span>
	<span style="color: #993333;">long</span> tv_nsec<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* nanoseconds */</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To time the processing time some function took, one should call <code>clock_gettime()</code> twice. Once before the function call and once right after it and subtract the returned timings to get the actual runtime.</p>
<p>Getting the difference between two timespec structs isn&#8217;t very complicated and can be acheived using the function <code>diff()</code> defined bellow:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">timespec diff<span style="color: #009900;">&#40;</span>timespec start<span style="color: #339933;">,</span> timespec end<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	timespec temp<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>end.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_nsec</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>
		temp.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">=</span> end.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		temp.<span style="color: #202020;">tv_nsec</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1000000000</span><span style="color: #339933;">+</span>end.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		temp.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">=</span> end.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">;</span>
		temp.<span style="color: #202020;">tv_nsec</span> <span style="color: #339933;">=</span> end.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> temp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now let&#8217;s move to some real example:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;iostream&gt;</span>
<span style="color: #339933;">#include &lt;time.h&gt;</span>
using namespace std<span style="color: #339933;">;</span>
&nbsp;
timespec diff<span style="color: #009900;">&#40;</span>timespec start<span style="color: #339933;">,</span> timespec end<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	timespec time1<span style="color: #339933;">,</span> time2<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> temp<span style="color: #339933;">;</span>
	clock_gettime<span style="color: #009900;">&#40;</span>CLOCK_PROCESS_CPUTIME_ID<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>time1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">242000000</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		temp<span style="color: #339933;">+=</span>temp<span style="color: #339933;">;</span>
	clock_gettime<span style="color: #009900;">&#40;</span>CLOCK_PROCESS_CPUTIME_ID<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>time2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	cout<span style="color: #339933;">&lt;&lt;</span>diff<span style="color: #009900;">&#40;</span>time1<span style="color: #339933;">,</span>time2<span style="color: #009900;">&#41;</span>.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #ff0000;">&quot;:&quot;</span><span style="color: #339933;">&lt;&lt;</span>diff<span style="color: #009900;">&#40;</span>time1<span style="color: #339933;">,</span>time2<span style="color: #009900;">&#41;</span>.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">&lt;&lt;</span>endl<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>
&nbsp;
timespec diff<span style="color: #009900;">&#40;</span>timespec start<span style="color: #339933;">,</span> timespec end<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	timespec temp<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>end.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_nsec</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>
		temp.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">=</span> end.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		temp.<span style="color: #202020;">tv_nsec</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1000000000</span><span style="color: #339933;">+</span>end.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		temp.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">=</span> end.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">;</span>
		temp.<span style="color: #202020;">tv_nsec</span> <span style="color: #339933;">=</span> end.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">-</span>start.<span style="color: #202020;">tv_nsec</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> temp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To use <code>clock_gettime</code> you need to include <code>time.h</code> and to link to <code>librt.a</code>. If you use <code>gcc</code> just make sure you add <code>-lrt</code> to your list of arguments.</p>
<p>Play a bit with the length of the for loop. As you can see <code>clock_gettime</code> provides much more accurate results and can register very short processing time too. Just remember that as the case with any profiling functions, this function adds a little overhead to your program, so make sure you disable the profiling code, using preprocessor commands for example, in the production release.</p>
<h4>26/9/2007 &#8211; Update</h4>
<p>You may want to take a look at <a href="/2007/09/26/the-revised-string-iteration-benchmark/">The Revised String Iteration Benchmark</a> post for another, larger, example of using <code>clock_gettime</code> to time performance of code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Introduction to C++ CGI &#8211; Processing Forms</title>
		<link>http://www.guyrutenberg.com/2007/09/07/introduction-to-c-cgi-processing-forms/</link>
		<comments>http://www.guyrutenberg.com/2007/09/07/introduction-to-c-cgi-processing-forms/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 19:11:59 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cgi]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/07/introduction-to-c-cgi-processing-forms/</guid>
		<description><![CDATA[In this post I will show you how to process HTML forms easily using CGIs in C++. I assume you have already basic knowledge of writing CGIs in C++, if you don&#8217;t go a head and read Introduction to C++ CGI.
Processing forms is the basic function of any CGI script and the main purpose of [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will show you how to process HTML forms easily using CGIs in C++. I assume you have already basic knowledge of writing CGIs in C++, if you don&#8217;t go a head and read <a href="/2007/08/10/introduction-to-c-cgi/">Introduction to C++ CGI</a>.</p>
<p>Processing forms is the basic function of any CGI script and the main purpose of CGIs. As you probably know there are two common ways to send form data back to the web server: &#8220;post&#8221; and &#8220;get&#8221;. When form data is sent with the &#8220;get&#8221; method it is appended to the URL string of the form submission URL. The &#8220;post&#8221; method is much like the &#8220;get&#8221; except the data is transmitted via http headers and not via the URL itself. When a form uses &#8220;get&#8221; it allows the user to easily bookmark the query created by the form as the data is transmitted in URL itself, on the other hand the &#8220;post&#8221; method allows to send much more data and spares to user from seeing the data in the URL.</p>
<p>Getting the &#8220;post&#8221; and &#8220;get&#8221; data is relatively easy. To get the data sent by &#8220;get&#8221; you can just call <code>getenv("QUERY_STRING")</code> and you will receive a pointer to null-terminated string containing the &#8220;get&#8221; data. Reading the &#8220;post&#8221; data is a bit more complicated. The data needs to be read from the standard input, but the program won&#8217;t receive an EOF when it reaches the end of the data but instead it should stop reading after reading a specified amount of bytes, which is defined in the environment variable &#8220;<code>CONTENT_LENGTH</code>&#8220;. So you should read <code>getenv("CONTENT_LENGTH")</code> bytes from the standard input to receive the &#8220;post&#8221; data. </p>
<p><span id="more-13"></span></p>
<p>But here it&#8217;s get tricky. The data is received in an encoded way. The data for both &#8220;post&#8221; and &#8220;get&#8221; is a string in the form of &#8220;<code>var1=value1&#038;var2=value2&#038;var3=value3</code>&#8221; and so on, where the &#8220;<code>var*</code>&#8221; is the names of the submitted form elements and &#8220;<code>value*</code>&#8221; is their values respectively. And now it gets a bit more tricky, both the elements&#8217; names and values are <a href="http://en.wikipedia.org/wiki/Url_encoding">url-encoded</a>. That means that almost every non alphanumeric character will be encoded as %XX, where XX represents its ASCII value (see the linked Wikipedia article for more information and extra reading). So to sum up the process of processing forms in CGI you should do the following:</p>
<ol>
<li>Get the data (either by &#8220;post&#8221; or &#8220;get&#8221;).</li>
<li>Parse the data to get key-value pairs.</li>
<li>Decode the url-encoded key-value pairs.</li>
<li>Process the data.</li>
</ol>
<p>Getting the first and last step done is easy. The second and third step require some work, but fortunately when done properly they should only have to be done once, as you will create functions/classes to handle those, so it is really only a one time job. That leaves you only to do yourself the first and last steps. </p>
<p>As I said the second and third steps are troublesome only when not done before. <a href='/wp-content/uploads/2007/09/getpost.h' title='getpost.h'>Here is</a> an implementation for those steps that I&#8217;ve written as a part of (yet unreleased) CGI library for C++. It implements functions that take the care of the first three steps and return to the user an STL map containing the form elements&#8217; names in the key and their value in the map pair&#8217;s value. This functions allows to process forms in a similar way to processing forms in PHP using <code>$_GET</code> and <code>$_POST</code>. </p>
<p>Here is a simple example of processing a &#8220;get&#8221; form using the above <code><a href='/wp-content/uploads/2007/09/getpost.h' title='getpost.h'>getpost.h</a></code> header file.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;string&gt;</span>
<span style="color: #339900;">#include &lt;map&gt;</span>
<span style="color: #339900;">#include &quot;getpost.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	map<span style="color: #000080;">&lt;</span>string,string<span style="color: #000080;">&gt;</span> Get<span style="color: #008080;">;</span>
	initializeGet<span style="color: #008000;">&#40;</span>Get<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//notice that the variable is passed by reference!</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Content-type: text/html&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;html&gt;&lt;body&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;h1&gt;Processing forms&lt;/h1&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;form method=<span style="color: #000099; font-weight: bold;">\&quot;</span>get<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &lt;label for=<span style="color: #000099; font-weight: bold;">\&quot;</span>fname<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;First name: &lt;/label&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>fname<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>fname<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;br&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &lt;label for=<span style="color: #000099; font-weight: bold;">\&quot;</span>lname<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Last name: &lt;/label&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>lname<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>lname<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;br&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>submit<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>Get.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;fname&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">!</span><span style="color: #000080;">=</span>Get.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> Get.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;lname&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">!</span><span style="color: #000080;">=</span>Get.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Hello &quot;</span><span style="color: #000080;">&lt;&lt;</span>Get<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;fname&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #000080;">&lt;&lt;</span>Get<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;lname&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;, isn<span style="color: #000099; font-weight: bold;">\'</span>t &quot;</span>
			<span style="color: #FF0000;">&quot;processing CGI forms with C++ quite easy?&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Fill up the above from and press submit&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>While this is a simple example, it&#8217;s enough to demonstarte how stuff is done. The same way you can process the &#8220;post&#8221; variables. Feel free to take a look at the <code><a href='/wp-content/uploads/2007/09/getpost.h' title='getpost.h'>getpost.h</a></code> source-code to see how the URL decoding and the other implementation aspects were done.</p>
<p><strong>Update 2009-09-18:</strong> There was a bug in <code>getpost.h</code>, see my comment bellow.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/09/07/introduction-to-c-cgi-processing-forms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Introduction to C++ CGI</title>
		<link>http://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/</link>
		<comments>http://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/#comments</comments>
		<pubDate>Thu, 09 Aug 2007 21:22:12 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cgi]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/</guid>
		<description><![CDATA[In this post and its follow ups I intend  to cover the basics of CGI programming in C++. There are great performance gain in writing CGIs in C++ compared to interpreted languages such as PHP and it&#8217;s usually it&#8217;s even faster than PHP scripts which are interpreted via mod_php. On the other hand PHP [...]]]></description>
			<content:encoded><![CDATA[<p>In this post and its follow ups I intend  to cover the basics of CGI programming in C++. There are great performance gain in writing CGIs in C++ compared to interpreted languages such as PHP and it&#8217;s usually it&#8217;s even faster than PHP scripts which are interpreted via mod_php. On the other hand PHP and other traditional web development languages are well suited for the task, by means of libraries and development time. However developing small highly efficient CGI scripts in C++ is easier  than you think.<br />
<span id="more-9"></span><br />
We shall start with a writing a basic &#8220;Hello World&#8221; CGI.  Basically, all output to <code>stdout</code> is directed by the web server to the client&#8217;s web browser. However, the web server requires the CGI application to declare in the first line on output what is the MIME type of the content it is producing. This line should be followed by a blank line. The common MIME types are <code>text/plain</code> for unformatted text and <code>text/html</code> for HTML formated content. The MIME type declaring should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Content-type: text/html&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span></pre></div></div>

<p>So getting back to our &#8220;Hello World&#8221; CGI, it will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Content-type: text/plain&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Hello World!&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Congratulations! You have just created your first C++ CGI. To see it in action, move it to a directory on the web server configured to run CGI scripts, this directory is usually called cgi-bin. Now just point your web browser to the the address of CGI app to see in in action.</p>
<p>Now that you have seen the basic example, let&#8217;s move on to a bit more complex example.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Content-type: text/html&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;html&gt;&lt;body&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;h1&gt;Hello World!&lt;/h1&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;This is HTML formatted Hello World C++ CGI&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>As you see, even writing pages with HTML content isn&#8217;t that hard. Yes, C++ may not be the easiest programming language for developing web applications, but it may turn out easier than you thought.</p>
<p>In this post I covered creating basic CGI that don&#8217;t relay on user input. As proccessing user input in one of the goals of CGI, I will cover it next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.973 seconds -->
