<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Web Development - Programming - Codehead</title>
	
	<link>http://blog.code-head.com</link>
	<description>Web development and programming blog focusing on webmaster's experience with PHP, MySQL, AJAX, server performance, security, SEO and more.</description>
	<pubDate>Tue, 30 Jun 2009 20:55:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/WebDevelopment-Seo-Codehead" type="application/rss+xml" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FWebDevelopment-Seo-Codehead" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FWebDevelopment-Seo-Codehead" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FWebDevelopment-Seo-Codehead" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/WebDevelopment-Seo-Codehead" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FWebDevelopment-Seo-Codehead" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FWebDevelopment-Seo-Codehead" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FWebDevelopment-Seo-Codehead" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Basic threading in JavaScript; multiple threads of execution in JavaScript</title>
		<link>http://blog.code-head.com/basic-threading-in-javascript-multiple-threads-of-execution-in-javascript</link>
		<comments>http://blog.code-head.com/basic-threading-in-javascript-multiple-threads-of-execution-in-javascript#comments</comments>
		<pubDate>Tue, 30 Jun 2009 20:45:25 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=657</guid>
		<description><![CDATA[I was searching the web yesterday for this and didn&#8217;t really find a simple way of doing this and suddenly, I remembered something.
It&#8217;s extremely simple, someone could build on it with all sorts of features but for now, here is an example:
http://images.code-head.com/code/javascript/js-threads.html
As you can see there are two counters, one is counting up and the [...]]]></description>
			<content:encoded><![CDATA[<p>I was searching the web yesterday for this and didn&#8217;t really find a simple way of doing this and suddenly, I remembered something.</p>
<p>It&#8217;s extremely simple, someone could build on it with all sorts of features but for now, here is an example:<br />
<a href="http://images.code-head.com/code/javascript/js-threads.html">http://images.code-head.com/code/javascript/js-threads.html</a></p>
<p>As you can see there are two counters, one is counting up and the other down simultaneously.</p>
<p>Here is the start_thread function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">             <span style="color: #003366; font-weight: bold;">function</span> thread_start<span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		setTimeout<span style="color: #009900;">&#40;</span>callback<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The trick is that setTimeout *does not* block the execution <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I hope this helps someone <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8ml_EfZ8-RM:iIvEroLnh20:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8ml_EfZ8-RM:iIvEroLnh20:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=8ml_EfZ8-RM:iIvEroLnh20:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8ml_EfZ8-RM:iIvEroLnh20:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=8ml_EfZ8-RM:iIvEroLnh20:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8ml_EfZ8-RM:iIvEroLnh20:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8ml_EfZ8-RM:iIvEroLnh20:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=8ml_EfZ8-RM:iIvEroLnh20:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8ml_EfZ8-RM:iIvEroLnh20:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/basic-threading-in-javascript-multiple-threads-of-execution-in-javascript/feed</wfw:commentRss>
		</item>
		<item>
		<title>Missing from Python: kill-able threads and popens with timeouts…</title>
		<link>http://blog.code-head.com/missing-from-python-kill-able-threads-and-popens-with-timeouts</link>
		<comments>http://blog.code-head.com/missing-from-python-kill-able-threads-and-popens-with-timeouts#comments</comments>
		<pubDate>Fri, 15 May 2009 21:15:13 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=647</guid>
		<description><![CDATA[It would be nice to be able to kill threads anytime you wanted, there are solutions to this but are not part of the Python library and I didn&#8217;t yet get a chance to try them&#8230; Actually there is only one promising solution to this.
The other thing I would love to have in Python is [...]]]></description>
			<content:encoded><![CDATA[<p>It would be nice to be able to kill threads anytime you wanted, there are solutions to this but are not part of the Python library and I didn&#8217;t yet get a chance to try them&#8230; Actually there is only one promising solution to this.</p>
<p>The other thing I would love to have in Python is to be able to call popen with a second parameter which is a timeout, That is (obviously) popen would give up and return if the call was taking more than x number of seconds&#8230;</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=X_vxPSXki3Y:AeYkf10YaII:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=X_vxPSXki3Y:AeYkf10YaII:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=X_vxPSXki3Y:AeYkf10YaII:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=X_vxPSXki3Y:AeYkf10YaII:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=X_vxPSXki3Y:AeYkf10YaII:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=X_vxPSXki3Y:AeYkf10YaII:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=X_vxPSXki3Y:AeYkf10YaII:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=X_vxPSXki3Y:AeYkf10YaII:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=X_vxPSXki3Y:AeYkf10YaII:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/missing-from-python-kill-able-threads-and-popens-with-timeouts/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python win32api and pywintypes.error: (5, ‘TerminateProcess’, ‘Access is denied.’)</title>
		<link>http://blog.code-head.com/python-win32api-and-pywintypeserror-5-terminateprocess-access-is-denied</link>
		<comments>http://blog.code-head.com/python-win32api-and-pywintypeserror-5-terminateprocess-access-is-denied#comments</comments>
		<pubDate>Fri, 15 May 2009 21:10:57 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=645</guid>
		<description><![CDATA[I was working on a piece of code that was supposed to close a bunch of processes &#8216;with the same name&#8217; right after each other and was getting this error message:
pywintypes.error: (5, &#8216;TerminateProcess&#8217;, &#8216;Access is denied.&#8217;)
The problem was that I was doing this in a loop and Windows didn&#8217;t get enough time to close the [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a piece of code that was supposed to close a bunch of processes &#8216;with the same name&#8217; right after each other and was getting this error message:<br />
pywintypes.error: (5, &#8216;TerminateProcess&#8217;, &#8216;Access is denied.&#8217;)</p>
<p>The problem was that I was doing this in a loop and Windows didn&#8217;t get enough time to close the first process yet. To fix this, just add a time.sleep(0.5) in your loop and you will be all set&#8230;</p>
<p>I hope this helps <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is the code I&#8217;m using (found in Python mailing list):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> win32api, win32pdhutil, win32con
<span style="color: #ff7700;font-weight:bold;">import</span> win32pdh, <span style="color: #dc143c;">string</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #ff7700;font-weight:bold;">def</span> GetAllProcesses<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
  <span style="color: #008000;">object</span> = <span style="color: #483d8b;">&quot;Process&quot;</span>
  items, instances = win32pdh.<span style="color: black;">EnumObjectItems</span><span style="color: black;">&#40;</span><span style="color: #008000;">None</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">object</span>, 
win32pdh.<span style="color: black;">PERF_DETAIL_WIZARD</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> instances
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #ff7700;font-weight:bold;">def</span> GetProcessID <span style="color: black;">&#40;</span> name <span style="color: black;">&#41;</span> :
  <span style="color: #008000;">object</span> = <span style="color: #483d8b;">&quot;Process&quot;</span>
  items, instances = win32pdh.<span style="color: black;">EnumObjectItems</span><span style="color: black;">&#40;</span><span style="color: #008000;">None</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">object</span>, win32pdh.<span style="color: black;">PERF_DETAIL_WIZARD</span><span style="color: black;">&#41;</span>
&nbsp;
  val = <span style="color: #008000;">None</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> name <span style="color: #ff7700;font-weight:bold;">in</span> instances :
    hq = win32pdh.<span style="color: black;">OpenQuery</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    hcs = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    item = <span style="color: #483d8b;">&quot;ID Process&quot;</span>
    path = win32pdh.<span style="color: black;">MakeCounterPath</span><span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span><span style="color: #008000;">None</span>,<span style="color: #008000;">object</span>,name, <span style="color: #008000;">None</span>, <span style="color: #ff4500;">0</span>, item<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
    hcs.<span style="color: black;">append</span><span style="color: black;">&#40;</span>win32pdh.<span style="color: black;">AddCounter</span><span style="color: black;">&#40;</span>hq, path<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    win32pdh.<span style="color: black;">CollectQueryData</span><span style="color: black;">&#40;</span>hq<span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0.01</span><span style="color: black;">&#41;</span>
    win32pdh.<span style="color: black;">CollectQueryData</span><span style="color: black;">&#40;</span>hq<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">for</span> hc <span style="color: #ff7700;font-weight:bold;">in</span> hcs:
      <span style="color: #008000;">type</span>, val = win32pdh.<span style="color: black;">GetFormattedCounterValue</span><span style="color: black;">&#40;</span>hc, win32pdh.<span style="color: black;">PDH_FMT_LONG</span><span style="color: black;">&#41;</span>
      win32pdh.<span style="color: black;">RemoveCounter</span><span style="color: black;">&#40;</span>hc<span style="color: black;">&#41;</span>
    win32pdh.<span style="color: black;">CloseQuery</span><span style="color: black;">&#40;</span>hq<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> val
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #ff7700;font-weight:bold;">def</span> Kill_Process_pid <span style="color: black;">&#40;</span> pid <span style="color: black;">&#41;</span> :
  handle = win32api.<span style="color: black;">OpenProcess</span><span style="color: black;">&#40;</span>win32con.<span style="color: black;">PROCESS_TERMINATE</span>, <span style="color: #ff4500;">0</span>, pid<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#get process handle</span>
  win32api.<span style="color: black;">TerminateProcess</span><span style="color: black;">&#40;</span>handle, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#kill by handle</span>
  win32api.<span style="color: black;">CloseHandle</span><span style="color: black;">&#40;</span>handle<span style="color: black;">&#41;</span>        <span style="color: #808080; font-style: italic;">#close api</span>
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span>
<span style="color: #ff7700;font-weight:bold;">def</span> Kill_Process <span style="color: black;">&#40;</span> name <span style="color: black;">&#41;</span> :
  pid = GetProcessID<span style="color: black;">&#40;</span>name<span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> pid:
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        Kill_Process_pid<span style="color: black;">&#40;</span>pid<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">except</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
<span style="color: #808080; font-style: italic;"># ***********************************************************************</span></pre></div></div>

<p>I just modified the last function, it&#8217;s kind of funny I know but that works for me, then I call it like:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Killing IEs...'</span>,
<span style="color: #ff7700;font-weight:bold;">while</span> Kill_Process<span style="color: black;">&#40;</span><span style="color: #483d8b;">'iexplore'</span><span style="color: black;">&#41;</span>:
   <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0.5</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Done!'</span></pre></div></div>

<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=NMGoZDrDGdo:aXZlVWJzPAw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=NMGoZDrDGdo:aXZlVWJzPAw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=NMGoZDrDGdo:aXZlVWJzPAw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=NMGoZDrDGdo:aXZlVWJzPAw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=NMGoZDrDGdo:aXZlVWJzPAw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=NMGoZDrDGdo:aXZlVWJzPAw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=NMGoZDrDGdo:aXZlVWJzPAw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=NMGoZDrDGdo:aXZlVWJzPAw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=NMGoZDrDGdo:aXZlVWJzPAw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/python-win32api-and-pywintypeserror-5-terminateprocess-access-is-denied/feed</wfw:commentRss>
		</item>
		<item>
		<title>Ungzip a string in Python - gzinflate in Python</title>
		<link>http://blog.code-head.com/ungzip-a-string-in-python-gzinflate-in-python</link>
		<comments>http://blog.code-head.com/ungzip-a-string-in-python-gzinflate-in-python#comments</comments>
		<pubDate>Thu, 07 May 2009 02:55:54 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=642</guid>
		<description><![CDATA[I was very surprised that I couldn&#8217;t do this easily in Python, so here is the solution to this:

import zlib
# ...
ungziped_str = zlib.decompressobj&#40;&#41;.decompress&#40;'x\x9c' + gziped_str&#41;

Wow, PHP does it like this:

$ungziped_str = gzinflate&#40;$gziped_str&#41;;

]]></description>
			<content:encoded><![CDATA[<p>I was very surprised that I couldn&#8217;t do this easily in Python, so here is the solution to this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">zlib</span>
<span style="color: #808080; font-style: italic;"># ...</span>
ungziped_str = <span style="color: #dc143c;">zlib</span>.<span style="color: black;">decompressobj</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decompress</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'x<span style="color: #000099; font-weight: bold;">\x</span>9c'</span> + gziped_str<span style="color: black;">&#41;</span></pre></div></div>

<p>Wow, PHP does it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ungziped_str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gzinflate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gziped_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=6wcF3uX-bjE:ELO-cGvPnAM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=6wcF3uX-bjE:ELO-cGvPnAM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=6wcF3uX-bjE:ELO-cGvPnAM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=6wcF3uX-bjE:ELO-cGvPnAM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=6wcF3uX-bjE:ELO-cGvPnAM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=6wcF3uX-bjE:ELO-cGvPnAM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=6wcF3uX-bjE:ELO-cGvPnAM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=6wcF3uX-bjE:ELO-cGvPnAM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=6wcF3uX-bjE:ELO-cGvPnAM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/ungzip-a-string-in-python-gzinflate-in-python/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python “Unhandled exception in thread started by Error in sys.excepthook:”</title>
		<link>http://blog.code-head.com/python-unhandled-exception-in-thread-started-by-error-in-sysexcepthook</link>
		<comments>http://blog.code-head.com/python-unhandled-exception-in-thread-started-by-error-in-sysexcepthook#comments</comments>
		<pubDate>Thu, 07 May 2009 02:50:57 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=640</guid>
		<description><![CDATA[I was getting this error message and I was using a Queue object to queue some jobs and block everything until all threads are done with:

the_queue.join&#40;&#41;

Well, in my particular case, I was getting these error messages the work was not done in worker threads:
Unhandled exception in thread started by
Error in sys.excepthook: 
Original exception was: 
So [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting this error message and I was using a Queue object to queue some jobs and block everything until all threads are done with:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">the_queue.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Well, in my particular case, I was getting these error messages the work was not done in worker threads:</p>
<p><em>Unhandled exception in thread started by<br />
Error in sys.excepthook: </p>
<p>Original exception was: </em></p>
<p>So what I did was this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">threads = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, max_threads<span style="color: black;">&#41;</span>:
   <span style="color: #dc143c;">thread</span> = Worker<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
   <span style="color: #dc143c;">thread</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
   threads.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">thread</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># And then...</span>
<span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #dc143c;">thread</span> <span style="color: #ff7700;font-weight:bold;">in</span> threads:
   <span style="color: #dc143c;">thread</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>And this fixed my issue, this will make sense to people with this problem <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wk0fEMVvhC8:wqdADK6_qss:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wk0fEMVvhC8:wqdADK6_qss:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=wk0fEMVvhC8:wqdADK6_qss:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wk0fEMVvhC8:wqdADK6_qss:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=wk0fEMVvhC8:wqdADK6_qss:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wk0fEMVvhC8:wqdADK6_qss:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wk0fEMVvhC8:wqdADK6_qss:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=wk0fEMVvhC8:wqdADK6_qss:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wk0fEMVvhC8:wqdADK6_qss:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/python-unhandled-exception-in-thread-started-by-error-in-sysexcepthook/feed</wfw:commentRss>
		</item>
		<item>
		<title>Manually move WHM/cPanel accounts - WHM account transfer function timeout</title>
		<link>http://blog.code-head.com/manually-move-whm-cpanel-accounts-whm-account-transfer-function-timesout</link>
		<comments>http://blog.code-head.com/manually-move-whm-cpanel-accounts-whm-account-transfer-function-timesout#comments</comments>
		<pubDate>Mon, 13 Apr 2009 18:22:21 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Server]]></category>

		<category><![CDATA[WHM/cPanel]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=636</guid>
		<description><![CDATA[Before you do it
You will have to make sure that both Apache web servers are the same version, I didn&#8217;t and it caused some problems.
My hosting company also mentioned that both cPanels must be the same version too, but I&#8217;m not sure about this.
You will also need root access to both servers and an SSH [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Before you do it</strong><br />
You will have to make sure that both Apache web servers are the same version, I didn&#8217;t and it caused some problems.</p>
<p>My hosting company also mentioned that both cPanels must be the same version too, but I&#8217;m not sure about this.</p>
<p>You will also need root access to both servers and an SSH client like <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank">putty</a>, so go ahead and connect to both servers.</p>
<p><strong>Manually Moving WHM/cPanel accounts</strong><br />
Follow these steps:<br />
1 - In your old server do:<br />
<em>/scripts/pkgacct &#8220;username&#8221;</em>                       <------- Don't type the quotes</p>
<p>2 - After the first step is done do:<br />
<em>scp /home/username.tar.gz  root@IP:/home/</em>             <------- Where IP is the IP of your destination server</p>
<p>You will be asked for the root password.</p>
<p>3 - In your destination server do:<br />
cd /home<br />
<em>/scripts/restorepkg &#8220;username&#8221;</em>                       <------- Don't type the quotes</p>
<p><strong>Disclaimer</strong><br />
<strong>Do this at your own risk</strong>, it worked fine on my version of WHM/cPanel/CentOS.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=Q7JUIlHl_lQ:RszbvC42-r0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=Q7JUIlHl_lQ:RszbvC42-r0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=Q7JUIlHl_lQ:RszbvC42-r0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=Q7JUIlHl_lQ:RszbvC42-r0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=Q7JUIlHl_lQ:RszbvC42-r0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=Q7JUIlHl_lQ:RszbvC42-r0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=Q7JUIlHl_lQ:RszbvC42-r0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=Q7JUIlHl_lQ:RszbvC42-r0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=Q7JUIlHl_lQ:RszbvC42-r0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/manually-move-whm-cpanel-accounts-whm-account-transfer-function-timesout/feed</wfw:commentRss>
		</item>
		<item>
		<title>The nx service is not available or the nx access was disabled - CentOS</title>
		<link>http://blog.code-head.com/the-nx-service-is-not-available-or-the-nx-access-was-disabled-centos</link>
		<comments>http://blog.code-head.com/the-nx-service-is-not-available-or-the-nx-access-was-disabled-centos#comments</comments>
		<pubDate>Thu, 02 Apr 2009 21:00:37 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[CentOS]]></category>

		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=632</guid>
		<description><![CDATA[If you follow the instruction here:
http://wiki.centos.org/HowTos/FreeNX
You will get an error message from NX client:
The nx service is not available or the nx access was disabled
To fix this, connect to your SSH and type:
cat /var/lib/nxserver/home/.ssh/client.id_dsa.key
Copy the text you get and in your NX client, on your login dialog box go to:
Configure&#8230; > General Tab > Key
And [...]]]></description>
			<content:encoded><![CDATA[<p>If you follow the instruction here:<br />
<a href="http://wiki.centos.org/HowTos/FreeNX">http://wiki.centos.org/HowTos/FreeNX</a></p>
<p>You will get an error message from NX client:<br />
The nx service is not available or the nx access was disabled</p>
<p>To fix this, connect to your SSH and type:<br />
cat /var/lib/nxserver/home/.ssh/client.id_dsa.key</p>
<p>Copy the text you get and in your NX client, on your login dialog box go to:<br />
Configure&#8230; > General Tab > Key</p>
<p>And paste the text there and you will be fine <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wetKzhtIl04:hsbpS6Cr3QM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wetKzhtIl04:hsbpS6Cr3QM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=wetKzhtIl04:hsbpS6Cr3QM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wetKzhtIl04:hsbpS6Cr3QM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=wetKzhtIl04:hsbpS6Cr3QM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wetKzhtIl04:hsbpS6Cr3QM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wetKzhtIl04:hsbpS6Cr3QM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=wetKzhtIl04:hsbpS6Cr3QM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=wetKzhtIl04:hsbpS6Cr3QM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/the-nx-service-is-not-available-or-the-nx-access-was-disabled-centos/feed</wfw:commentRss>
		</item>
		<item>
		<title>PML - A Python template engine</title>
		<link>http://blog.code-head.com/pml-a-python-template-engine</link>
		<comments>http://blog.code-head.com/pml-a-python-template-engine#comments</comments>
		<pubDate>Tue, 31 Mar 2009 17:49:26 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Web Design]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=623</guid>
		<description><![CDATA[I finally decided to release PML as an open source software. I developed this template engine for a project that unfortunately never happened using Python.
Here is a sample application using PML and Yahoo! Search API:
http://web-search.code-head.com/
You can download it here:
[D O W N L O A D]
The web search example is also included in the download.
PML [...]]]></description>
			<content:encoded><![CDATA[<p>I finally decided to release PML as an open source software. I developed this template engine for a project that unfortunately never happened using Python.</p>
<p>Here is a sample application using PML and Yahoo! Search API:<br />
<a href="http://web-search.code-head.com/" target="_blank" rel="nofollow">http://web-search.code-head.com/</a></p>
<p>You can download it here:</p>
<p><a href="http://images.code-head.com/code/python/PML-0.7.8-Beta.zip">[D O W N L O A D]</a></p>
<p>The web search example is also included in the download.</p>
<p>PML was written to be fast, simple and compact. Here are some of it&#8217;s features:<br />
1 - Template filters<br />
2 - Output filters<br />
3 - Template variable filters<br />
4 - Template cache - default<br />
5 - Bytecode cache - default<br />
6 - Complete output buffer cache<br />
7 - Garbage collection<br />
8 - Output compression - GZIP<br />
9 - A powerful, quick compiler<br />
10 - Ability to add helpers easily<br />
11 - Ability to add custom compiler tags<br />
12 - Auto escaping your variables, even lists, dicts, and tuples<br />
13 - Compile templates once until you edit them</p>
<p>And more.</p>
<p>I will write a tutorial in my next post.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=m3UtGQw_C7o:w-ByVVzSJxw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=m3UtGQw_C7o:w-ByVVzSJxw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=m3UtGQw_C7o:w-ByVVzSJxw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=m3UtGQw_C7o:w-ByVVzSJxw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=m3UtGQw_C7o:w-ByVVzSJxw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=m3UtGQw_C7o:w-ByVVzSJxw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=m3UtGQw_C7o:w-ByVVzSJxw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=m3UtGQw_C7o:w-ByVVzSJxw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=m3UtGQw_C7o:w-ByVVzSJxw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/pml-a-python-template-engine/feed</wfw:commentRss>
		</item>
		<item>
		<title>A PHP Competition 2</title>
		<link>http://blog.code-head.com/a-php-competition-2</link>
		<comments>http://blog.code-head.com/a-php-competition-2#comments</comments>
		<pubDate>Mon, 30 Mar 2009 20:00:57 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=619</guid>
		<description><![CDATA[Say that you are generating an XML sitemap for your site and there are 5,000 URLs.
Here is the code:

&#60;?php
&#160;
	$buffer =
'&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;urlset xmlns=&#34;http://www.sitemaps.org/schemas/sitemap/0.9&#34;&#62;
';
&#160;
	$results = fetch_5000_urls_order_by_importance&#40;&#41;;
	$count = 0;
	while &#40;$row = $results-&#62;fetch_next_url&#40;&#41;&#41; &#123;
		$priority = ##########################################;
		$url = $row&#91;'url'&#93;;
		$date = date&#40;'Y-m-d', $row&#91;'date'&#93;&#41;;
		$buffer .= &#34;
			&#60;url&#62;
				&#60;loc&#62;$url&#60;/loc&#62;
				&#60;lastmod&#62;$date&#60;/lastmod&#62;
				&#60;changefreq&#62;weekly&#60;/changefreq&#62;
				&#60;priority&#62;$priority&#60;/priority&#62;
			&#60;/url&#62;
			&#34;;
	&#125;
&#160;
	$buffer .= '
	&#60;/urlset&#62;
	';
&#160;
	echo $buffer;
&#160;
?&#62;

What you want to do is to give each URL a priority; URLs [...]]]></description>
			<content:encoded><![CDATA[<p>Say that you are generating an XML sitemap for your site and there are 5,000 URLs.</p>
<p>Here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span>
<span style="color: #0000ff;">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;urlset xmlns=&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;&gt;
'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> fetch_5000_urls_order_by_importance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_next_url</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$priority</span> <span style="color: #339933;">=</span> <span style="color: #666666; font-style: italic;">##########################################;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;url&gt;
				&lt;loc&gt;<span style="color: #006699; font-weight: bold;">$url</span>&lt;/loc&gt;
				&lt;lastmod&gt;<span style="color: #006699; font-weight: bold;">$date</span>&lt;/lastmod&gt;
				&lt;changefreq&gt;weekly&lt;/changefreq&gt;
				&lt;priority&gt;<span style="color: #006699; font-weight: bold;">$priority</span>&lt;/priority&gt;
			&lt;/url&gt;
			&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'
	&lt;/urlset&gt;
	'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">echo</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>What you want to do is to give each URL a priority; URLs between 0 to 1000 will have a priority of 0.9<br />
1000 to 2000 => 0.8<br />
2000 to 3000 => 0.7<br />
3000 to 5000 => 0.6<br />
4000 to 5000 => 0.5</p>
<p>Replace ########################################## with the code that calculates the priorities, and remember not to use ; in it <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=vCYt9qBEadQ:QOtuJ3-1vOQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=vCYt9qBEadQ:QOtuJ3-1vOQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=vCYt9qBEadQ:QOtuJ3-1vOQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=vCYt9qBEadQ:QOtuJ3-1vOQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=vCYt9qBEadQ:QOtuJ3-1vOQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=vCYt9qBEadQ:QOtuJ3-1vOQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=vCYt9qBEadQ:QOtuJ3-1vOQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=vCYt9qBEadQ:QOtuJ3-1vOQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=vCYt9qBEadQ:QOtuJ3-1vOQ:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/a-php-competition-2/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to clean the screen with PHP in Linux (cls, Linux, PHP)</title>
		<link>http://blog.code-head.com/how-to-clean-the-screen-with-php-in-linux-cls-linux-php</link>
		<comments>http://blog.code-head.com/how-to-clean-the-screen-with-php-in-linux-cls-linux-php#comments</comments>
		<pubDate>Tue, 17 Mar 2009 22:58:37 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Operating Systems]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=613</guid>
		<description><![CDATA[Here is the trick, in your script use:

system&#40;&#34;clear&#34;&#41;;

I hope this helps someone.
]]></description>
			<content:encoded><![CDATA[<p>Here is the trick, in your script use:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;clear&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope this helps someone.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8vrnNU831aI:W10yZXoiU-0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8vrnNU831aI:W10yZXoiU-0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=8vrnNU831aI:W10yZXoiU-0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8vrnNU831aI:W10yZXoiU-0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=8vrnNU831aI:W10yZXoiU-0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8vrnNU831aI:W10yZXoiU-0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8vrnNU831aI:W10yZXoiU-0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=8vrnNU831aI:W10yZXoiU-0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=8vrnNU831aI:W10yZXoiU-0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/how-to-clean-the-screen-with-php-in-linux-cls-linux-php/feed</wfw:commentRss>
		</item>
		<item>
		<title>A PHP script for dealing with DoS attacks</title>
		<link>http://blog.code-head.com/a-php-script-for-dealing-with-dos-attacks</link>
		<comments>http://blog.code-head.com/a-php-script-for-dealing-with-dos-attacks#comments</comments>
		<pubDate>Mon, 16 Mar 2009 20:57:14 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=608</guid>
		<description><![CDATA[Here is a simple script that will show you what IP addresses are making how many requests to your server.

&#60;?php
&#160;
## Functions ##
&#160;
function getIP&#40;$line&#41; &#123;
	ereg&#40;&#34;[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}&#34;,$line,$regMatch&#41;;
	$ip = $regMatch&#91;0&#93;;
	if&#40;$ip&#41; return $ip; else return &#34;false&#34;;
&#125;
&#160;
function processString&#40;$string, $size = 18&#41; &#123;
	$string = &#34;[ &#34;.$string;
	$length = strlen&#40;$string&#41;;
	$toAdd = $size - $length;
&#160;
	for&#40;$x = 0; $x &#60; $toAdd; $x++&#41; &#123;
		$string = $string.&#34; &#34;;
	&#125;
	$string [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple script that will show you what IP addresses are making how many requests to your server.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Functions ##</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getIP<span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">ereg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$line</span><span style="color: #339933;">,</span><span style="color: #000088;">$regMatch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$regMatch</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;false&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> processString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[ &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$toAdd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$length</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$toAdd</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$string</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$string</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Code ##</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;netstat -n | awk '{ print <span style="color: #006699; font-weight: bold;">$5</span> }'&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$netstatArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ipArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$netstatArray</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> getIP<span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;false&quot;</span> <span style="color: #339933;">&amp;&amp;</span> ip <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ipArray</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
						 <span style="color: #009900;">&#123;</span>
									<span style="color: #000088;">$ipArray</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
						 <span style="color: #009900;">&#125;</span>
						 <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// if not, count=1</span>
						 <span style="color: #009900;">&#123;</span>
									<span style="color: #000088;">$ipArray</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
						 <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #990000;">asort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ipArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;clear&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ipArray</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> processString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span>processString<span style="color: #009900;">&#40;</span><span style="color: #990000;">gethostbyaddr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">55</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>Times Accessed: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$count</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #990000;">echo</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;top -n 1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$top_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#load average:(.+)#i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$top_str</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Load Average: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">echo</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'Showing $count &gt;= 15: (Escape with ctrl+c)'</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>After identifying the IP addresses that are sending many requests at once to crash your server, you can ban them using a firewall software. I personally recommend APF: http://rfxnetworks.com/apf.php</p>
<p>You can do:<br />
apf -d THEIPADDRESS SOMECOMMENTLIKEPOSSIBLEDOS</p>
<p>This script was originally written by a former employee of <a href="http://www.ace-host.net/">Acenet Inc</a> and was modified by me. Acenet Inc is a great web hosting company with great support and fantastic staff members who will help you 24&#215;7.</p>
<p>Here is some info about Denial of Service attacks (DoS attacks).<br />
<a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">http://en.wikipedia.org/wiki/Denial-of-service_attack</a></p>
<p>I hope this helps someone.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=psLeRs5rB74:HGnF9S3ukOU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=psLeRs5rB74:HGnF9S3ukOU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=psLeRs5rB74:HGnF9S3ukOU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=psLeRs5rB74:HGnF9S3ukOU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=psLeRs5rB74:HGnF9S3ukOU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=psLeRs5rB74:HGnF9S3ukOU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=psLeRs5rB74:HGnF9S3ukOU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=psLeRs5rB74:HGnF9S3ukOU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=psLeRs5rB74:HGnF9S3ukOU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/a-php-script-for-dealing-with-dos-attacks/feed</wfw:commentRss>
		</item>
		<item>
		<title>Another great TED talk: David Bolinsky: Fantastic voyage inside a cell</title>
		<link>http://blog.code-head.com/another-great-ted-talk-david-bolinsky-fantastic-voyage-inside-a-cell</link>
		<comments>http://blog.code-head.com/another-great-ted-talk-david-bolinsky-fantastic-voyage-inside-a-cell#comments</comments>
		<pubDate>Thu, 26 Feb 2009 20:13:16 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=603</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Id2rZS59xSE&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Id2rZS59xSE&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=TnnWc4gJdeE:TINw2o0MmfE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=TnnWc4gJdeE:TINw2o0MmfE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=TnnWc4gJdeE:TINw2o0MmfE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=TnnWc4gJdeE:TINw2o0MmfE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=TnnWc4gJdeE:TINw2o0MmfE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=TnnWc4gJdeE:TINw2o0MmfE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=TnnWc4gJdeE:TINw2o0MmfE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=TnnWc4gJdeE:TINw2o0MmfE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=TnnWc4gJdeE:TINw2o0MmfE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/another-great-ted-talk-david-bolinsky-fantastic-voyage-inside-a-cell/feed</wfw:commentRss>
		</item>
		<item>
		<title>A Tiny MySQL++ Tutorial; C++ and MySQL; MySQL++ Example</title>
		<link>http://blog.code-head.com/a-tiny-mysql-tutorial-c-and-mysql-example</link>
		<comments>http://blog.code-head.com/a-tiny-mysql-tutorial-c-and-mysql-example#comments</comments>
		<pubDate>Wed, 25 Feb 2009 20:23:26 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[C++]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=594</guid>
		<description><![CDATA[I wrote a post about how to install MySQL++ and I thought I will write a quick tutorial on how to use it too.
This is a very basic MySQL++ program and it&#8217;s very self explanatory:

#include &#60;mysql++.h&#62;
#include &#60;stdlib.h&#62;
&#160;
using namespace std;
using namespace mysqlpp;
&#160;
int main&#40;&#41; &#123;
    try &#123;
        [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a <a href="http://blog.code-head.com/mysql-installation-how-to-install-mysql-on-linux-centos">post</a> about <a href="http://blog.code-head.com/mysql-installation-how-to-install-mysql-on-linux-centos">how to install MySQL++ </a>and I thought I will write a quick tutorial on how to use it too.</p>
<p>This is a very basic MySQL++ program and it&#8217;s very self explanatory:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;mysql++.h&gt;</span>
<span style="color: #339900;">#include &lt;stdlib.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> mysqlpp<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: #0000ff;">try</span> <span style="color: #008000;">&#123;</span>
        Connection conn<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        conn.<span style="color: #007788;">connect</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;DB NAME&quot;</span>, <span style="color: #FF0000;">&quot;DB HOST probably localhost&quot;</span>, <span style="color: #FF0000;">&quot;DB USER&quot;</span>, <span style="color: #FF0000;">&quot;DB PASS&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        Query query <span style="color: #000080;">=</span> conn.<span style="color: #007788;">query</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span>BadQuery er<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// handle any connection or                      </span>
        <span style="color: #666666;">// query errors that may come up </span>
        <span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Error: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> 
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> BadConversion<span style="color: #000040;">&amp;</span> er<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #666666;">// Handle bad conversions</span>
        <span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Conversion error: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl <span style="color: #000080;">&lt;&lt;</span>
                <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>retrieved data size: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">retrieved</span> <span style="color: #000080;">&lt;&lt;</span>
                <span style="color: #FF0000;">&quot;, actual size: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">actual_size</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> Exception<span style="color: #000040;">&amp;</span> er<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #666666;">// Catch-all for any other MySQL++ exceptions</span>
        <span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Error: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">EXIT_SUCCESS</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This will connect to your database and creates a query object ready to go. Save this as test.cpp</p>
<p>To compile this, you will have to create a Makefile in the same folder, so create a file and name it &#8220;Makefile&#8221; (no quotes) and add these to it:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">CXX <span style="color: #004400;">:=</span> g<span style="color: #004400;">++</span>
CXXFLAGS <span style="color: #004400;">:=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span><span style="color: #004400;">/</span>mysql <span style="color: #004400;">-</span>I<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span><span style="color: #004400;">/</span>mysql<span style="color: #004400;">++</span>
LDFLAGS <span style="color: #004400;">:=</span> <span style="color: #004400;">-</span>L<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span>lib <span style="color: #004400;">-</span>lmysqlpp <span style="color: #004400;">-</span>lmysqlclient <span style="color: #004400;">-</span>lnsl <span style="color: #004400;">-</span>lz <span style="color: #004400;">-</span>lm
EXECUTABLE <span style="color: #004400;">:=</span> main
&nbsp;
all<span style="color: #004400;">:</span> test
&nbsp;
clean<span style="color: #004400;">:</span>
	rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">EXECUTABLE</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">*.</span>o</pre></div></div>

<p>If you get funny errors, make sure there are no extra spaces in this file, and there is only one &#8220;tab&#8221; behind the line: rm -f $(EXECUTABLE) *.o</p>
<p>Now, you can make and run this by doing:<br />
make<br />
./test</p>
<p>Now, I&#8217;m going to show you how to execute some queries and you can go ahead and experiment on your own tables.</p>
<p>Here is a INSERT query followed by a SELECT; this will hopefully cover a lot, because INSERT is a type of query that doesn&#8217;t return anything and you need to escape values in order to INSERT.<br />
SELECT on the other hand returns rows, although there are 3 ways that they can be done but here is a simple way that works for me.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;mysql++.h&gt;</span>
<span style="color: #339900;">#include &lt;stdlib.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> mysqlpp<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: #0000ff;">try</span> <span style="color: #008000;">&#123;</span>
        Connection conn<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        conn.<span style="color: #007788;">connect</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;DB NAME&quot;</span>, <span style="color: #FF0000;">&quot;DB HOST probably localhost&quot;</span>, <span style="color: #FF0000;">&quot;DB USER&quot;</span>, <span style="color: #FF0000;">&quot;DB PASS&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        Query query <span style="color: #000080;">=</span> conn.<span style="color: #007788;">query</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #ff0000; font-style: italic;">/* To insert stuff with escaping */</span>
        query <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;INSERT INTO some_table &quot;</span> <span style="color: #000080;">&lt;&lt;</span>
                     <span style="color: #FF0000;">&quot;VALUES (&quot;</span> <span style="color: #000080;">&lt;&lt;</span>
                     <span style="color: #FF0000;">&quot;'', &quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #ff0000; font-style: italic;">/* This is left empty because the column is AUTO_INCREMENT */</span>
                     <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #000080;">&lt;&lt;</span> escape <span style="color: #000080;">&lt;&lt;</span> some_var_that_contains_some_value <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #000080;">&lt;&lt;</span>
                     <span style="color: #FF0000;">&quot;);&quot;</span><span style="color: #008080;">;</span>
        query.<span style="color: #007788;">execute</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #ff0000; font-style: italic;">/* That's it for INSERT */</span>
&nbsp;
        <span style="color: #ff0000; font-style: italic;">/* Now SELECT */</span>
        query <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;SELECT * FROM biz LIMIT 10&quot;</span><span style="color: #008080;">;</span>
        StoreQueryResult ares <span style="color: #000080;">=</span> query.<span style="color: #007788;">store</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">size_t</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> ares.<span style="color: #007788;">num_rows</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
           <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Name: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> ares<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;name&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; - Address: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> ares<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;address&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #ff0000; font-style: italic;">/* Let's get a count of something */</span>
        query <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;SELECT COUNT(*) AS row_count FROM biz&quot;</span><span style="color: #008080;">;</span>
        StoreQueryResult bres <span style="color: #000080;">=</span> query.<span style="color: #007788;">store</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Total rows: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> bres<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;row_count&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span>BadQuery er<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">// handle any connection or                      </span>
        <span style="color: #666666;">// query errors that may come up </span>
        <span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Error: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> 
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> BadConversion<span style="color: #000040;">&amp;</span> er<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #666666;">// Handle bad conversions</span>
        <span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Conversion error: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl <span style="color: #000080;">&lt;&lt;</span>
                <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>retrieved data size: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">retrieved</span> <span style="color: #000080;">&lt;&lt;</span>
                <span style="color: #FF0000;">&quot;, actual size: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">actual_size</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> Exception<span style="color: #000040;">&amp;</span> er<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #666666;">// Catch-all for any other MySQL++ exceptions</span>
        <span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Error: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> er.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">EXIT_SUCCESS</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Again, whenever you want to run your code do:<br />
make<br />
./test</p>
<p>I wrote this because something like this would help myself a lot.</p>
<p>Good Luck <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Update</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">query.<span style="color: #007788;">reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Will reset the query object; this is useful when you are (in your program) generating a MySQL query but must discard it and generate another query (based on some condition).</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=bKxB3f88ud8:e1qEHynGKpA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=bKxB3f88ud8:e1qEHynGKpA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=bKxB3f88ud8:e1qEHynGKpA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=bKxB3f88ud8:e1qEHynGKpA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=bKxB3f88ud8:e1qEHynGKpA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=bKxB3f88ud8:e1qEHynGKpA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=bKxB3f88ud8:e1qEHynGKpA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=bKxB3f88ud8:e1qEHynGKpA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=bKxB3f88ud8:e1qEHynGKpA:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/a-tiny-mysql-tutorial-c-and-mysql-example/feed</wfw:commentRss>
		</item>
		<item>
		<title>Installing MySQL++; How to install MySQL++ on Linux-CentOS</title>
		<link>http://blog.code-head.com/installing-mysql-how-to-install-mysql-on-linux-centos</link>
		<comments>http://blog.code-head.com/installing-mysql-how-to-install-mysql-on-linux-centos#comments</comments>
		<pubDate>Wed, 25 Feb 2009 19:56:50 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[C++]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=589</guid>
		<description><![CDATA[There is a lack of documentation on how to do this, I guess they assume that you must know a lot IF you are trying to use this library.
But here are step by step instructions on how to do it.
What you need
Root access to your server.
An SSH client, like putty, it&#8217;s free.
Let&#8217;s do it
1 - [...]]]></description>
			<content:encoded><![CDATA[<p>There is a lack of documentation on how to do this, I guess they assume that you must know a lot IF you are trying to use this library.</p>
<p>But here are step by step instructions on how to do it.</p>
<p><strong>What you need</strong><br />
Root access to your server.<br />
An SSH client, like <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">putty</a>, it&#8217;s free.</p>
<p><strong>Let&#8217;s do it</strong><br />
1 - Run your SSH client and connect to your server using root.</p>
<p>2 - Do:</p>
<p>cd /</p>
<p><em>Note: I always make a folder like this</em></p>
<p>mkdir Tools<br />
cd Tools</p>
<p><em>Note: This is version 3.0.9 obviously, it&#8217;s best if you check this web page and download the latest source code: http://www.tangentsoft.net/mysql++/</em></p>
<p>wget http://www.tangentsoft.net/mysql++/releases/mysql++-3.0.9.tar.gz<br />
tar xvfz mysql++-3.0.9.tar.gz<br />
cd mysql++-3.0.9<br />
./configure<br />
make<br />
make install</p>
<p>3 - Now, in order for:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;mysql++.h&gt;</span></pre></div></div>

<p>To work, you will have to add a line to your ld.so.conf; you will find this file (hopefully) in /etc so go to:<br />
/etc<br />
And edit ld.so.conf and add this line to the end of it:<br />
/usr/local/lib</p>
<p><em>Note: If ld.so.conf is not in /etc you can try &#8220;whereis ld.so.conf&#8221; (no quotes)</em></p>
<p>Save it and run:</p>
<p>ldconfig</p>
<p>And you are all set.</p>
<p>Please also note that, this worked on my CentOS and might not work exactly like this on your distribution.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=il_ALAp5mmw:LFVD1m73GIU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=il_ALAp5mmw:LFVD1m73GIU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=il_ALAp5mmw:LFVD1m73GIU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=il_ALAp5mmw:LFVD1m73GIU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=il_ALAp5mmw:LFVD1m73GIU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=il_ALAp5mmw:LFVD1m73GIU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=il_ALAp5mmw:LFVD1m73GIU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=il_ALAp5mmw:LFVD1m73GIU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=il_ALAp5mmw:LFVD1m73GIU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/installing-mysql-how-to-install-mysql-on-linux-centos/feed</wfw:commentRss>
		</item>
		<item>
		<title>Slowing down Yahoo! Slurp (Yahoo! Search Bot)</title>
		<link>http://blog.code-head.com/slowing-down-yahoo-slurp-yahoo-search-bot</link>
		<comments>http://blog.code-head.com/slowing-down-yahoo-slurp-yahoo-search-bot#comments</comments>
		<pubDate>Sun, 22 Feb 2009 20:13:49 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Annoying Stuff]]></category>

		<category><![CDATA[Search Engines]]></category>

		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=584</guid>
		<description><![CDATA[A few weeks ago one of our servers started to crash every few days.
After investigating this issue for a while we found 100s of IP addresses from Yahoo! and Inktomi Corporation which is the company who developed Yahoo! Slurp.
So basically Yahoo! was launching DOS attacks against our server although unintentional but very annoying. It also [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago one of our servers started to crash every few days.</p>
<p>After investigating this issue for a while we found 100s of IP addresses from Yahoo! and <a href="http://en.wikipedia.org/wiki/Inktomi">Inktomi Corporation</a> which is the company who developed Yahoo! Slurp.</p>
<p>So basically Yahoo! was launching <a href="http://en.wikipedia.org/wiki/DoS_attacks">DOS attacks</a> against our server although unintentional but very annoying. It also shows that their technology is not as advanced as Google or other search engines or it&#8217;s buggy, Whatever you think, crashing people&#8217;s servers with your search bot is not cool at all and shows that you have to work on it a little more&#8230;</p>
<p>If you have the same problem here is a simple solution Yahoo! suggest; open your <a href="http://en.wikipedia.org/wiki/Robots.txt">robots.txt</a> (create it if you don&#8217;t have it and place it in your root folder) and add these lines to it:</p>
<p>User-agent: Slurp<br />
Crawl-delay: 1</p>
<p>Only Yahoo! will understand the line Crawl-delay: X and <a href="http://help.yahoo.com/l/us/yahoo/search/webcrawler/slurp-03.html">Yahoo! suggests</a> that you use a small number between 0.5 and 1.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=frubKsHwy1M:T1ntLA8PwcQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=frubKsHwy1M:T1ntLA8PwcQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=frubKsHwy1M:T1ntLA8PwcQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=frubKsHwy1M:T1ntLA8PwcQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=frubKsHwy1M:T1ntLA8PwcQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=frubKsHwy1M:T1ntLA8PwcQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=frubKsHwy1M:T1ntLA8PwcQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=frubKsHwy1M:T1ntLA8PwcQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=frubKsHwy1M:T1ntLA8PwcQ:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.code-head.com/slowing-down-yahoo-slurp-yahoo-search-bot/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
