<?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, 27 Oct 2009 22:20:19 +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>SEO Tip: do you have any good content</title>
		<link>http://blog.code-head.com/seo-tip-do-you-have-any-good-content</link>
		<comments>http://blog.code-head.com/seo-tip-do-you-have-any-good-content#comments</comments>
		<pubDate>Tue, 27 Oct 2009 21:07:08 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=715</guid>
		<description><![CDATA[Imagine 2 similar websites, they both sell quilts, site A is just a simple shopping cart with a list of quilts and their prices. Site B has the same structure but site B has some articles about quilts. Now, which one of them is going to get more traffic???
Here is the tip, if you sell [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine 2 similar websites, they both sell quilts, site A is just a simple shopping cart with a list of quilts and their prices. Site B has the same structure but site B has some articles about quilts. Now, which one of them is going to get more traffic???</p>
<p>Here is the tip, if you sell something - let&#8217;s say quilts - write some articles about quilts, write about their history, about how different countries make them differently, and even how to make one!</p>
<p>The trick is to show your website to as many people as possible&#8230;</p>
<p> <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=JMnypRXhtag:XvMStqh88Is: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=JMnypRXhtag:XvMStqh88Is:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=JMnypRXhtag:XvMStqh88Is:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=JMnypRXhtag:XvMStqh88Is:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=JMnypRXhtag:XvMStqh88Is:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=JMnypRXhtag:XvMStqh88Is: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=JMnypRXhtag:XvMStqh88Is:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=JMnypRXhtag:XvMStqh88Is:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=JMnypRXhtag:XvMStqh88Is: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/seo-tip-do-you-have-any-good-content/feed</wfw:commentRss>
		</item>
		<item>
		<title>Write About The Solutions You Find; it’s good for SEO too</title>
		<link>http://blog.code-head.com/write-about-the-solutions-you-find-its-good-for-seo-too</link>
		<comments>http://blog.code-head.com/write-about-the-solutions-you-find-its-good-for-seo-too#comments</comments>
		<pubDate>Tue, 27 Oct 2009 20:56:58 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Ideas]]></category>

		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=710</guid>
		<description><![CDATA[I ran into some issues yesterday and was searching for a solution and I was surprised by so many forum posts like this:
Thanks everyone for helping me out but I found the solution yesterday!
That&#8217;s it?! It would be nice if users would also take a few extra minutes to write about how they did it.
I [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into some issues yesterday and was searching for a solution and I was surprised by so many forum posts like this:</p>
<p>Thanks everyone for helping me out but I found the solution yesterday!</p>
<p>That&#8217;s it?! It would be nice if users would also take a few extra minutes to write about how they did it.</p>
<p>I get a lot of traffic to this blog and it&#8217;s because I write about these little solutions and surprisingly so many people are interested in them too. I don&#8217;t sell any ads or don&#8217;t have any sort of PPC on here and the only reason I did it was to help others and also keep my collection somewhere I can go back too.</p>
<p>But I was very surprised by the amount of traffic it started to bring to me, so many people who have the same problems are searching for most of the titles on here.</p>
<p>So however small your problem seems, THERE ARE people who have the same problem and searching for a solution every day.</p>
<p>And again, for me, it wasn&#8217;t about traffic but it&#8217;s bringing a lot of traffic, even more than a lot of our older websites that we also did SEO for and this proves again that the best SEO strategy is to write good content&#8230;</p>
<p>Good Luck <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=aA3mMC4HkJs:-2wpiHO8VBo: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=aA3mMC4HkJs:-2wpiHO8VBo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=aA3mMC4HkJs:-2wpiHO8VBo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=aA3mMC4HkJs:-2wpiHO8VBo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=aA3mMC4HkJs:-2wpiHO8VBo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=aA3mMC4HkJs:-2wpiHO8VBo: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=aA3mMC4HkJs:-2wpiHO8VBo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=aA3mMC4HkJs:-2wpiHO8VBo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=aA3mMC4HkJs:-2wpiHO8VBo: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/write-about-the-solutions-you-find-its-good-for-seo-too/feed</wfw:commentRss>
		</item>
		<item>
		<title>“Actions - Button” Window In Flash</title>
		<link>http://blog.code-head.com/actions-button-window-in-flash</link>
		<comments>http://blog.code-head.com/actions-button-window-in-flash#comments</comments>
		<pubDate>Mon, 26 Oct 2009 22:15:22 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=717</guid>
		<description><![CDATA[If you are editing a Flash file like a menu and you can&#8217;t open the &#8220;Actions - Button&#8221; panel and only you see is &#8220;Actions - Frame&#8221; and you are 100% sure that you are dealing with actual buttons here is what you do:
Where you can see the layers, there is a lock icon, for [...]]]></description>
			<content:encoded><![CDATA[<p>If you are editing a Flash file like a menu and you can&#8217;t open the &#8220;Actions - Button&#8221; panel and only you see is &#8220;Actions - Frame&#8221; and you are 100% sure that you are dealing with actual buttons here is what you do:</p>
<p>Where you can see the layers, there is a lock icon, for every layer there must be a dot under it rather than a lock; so you have to unlock the layers before you can see the &#8220;Actions - Button&#8221; layer. To do this, simply click on each layer&#8217;s lock icon and that will turn it into a dot. Then go to &#8220;Window > Actions&#8221; and select a button and voila.</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=7sPxGeiV4Io:4fSPtCbN_TM: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=7sPxGeiV4Io:4fSPtCbN_TM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=7sPxGeiV4Io:4fSPtCbN_TM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=7sPxGeiV4Io:4fSPtCbN_TM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=7sPxGeiV4Io:4fSPtCbN_TM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=7sPxGeiV4Io:4fSPtCbN_TM: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=7sPxGeiV4Io:4fSPtCbN_TM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=7sPxGeiV4Io:4fSPtCbN_TM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=7sPxGeiV4Io:4fSPtCbN_TM: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/actions-button-window-in-flash/feed</wfw:commentRss>
		</item>
		<item>
		<title>A JavaScript/jQuery News Ticker</title>
		<link>http://blog.code-head.com/a-javascript-jquery-news-ticker</link>
		<comments>http://blog.code-head.com/a-javascript-jquery-news-ticker#comments</comments>
		<pubDate>Wed, 21 Oct 2009 23:27:43 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=706</guid>
		<description><![CDATA[I know I haven&#8217;t posted anything lately, I have been busy which is a good thing but I couldn&#8217;t resist this one, here is a simple news ticker using JavaScript and the great jQuery library.
Here is the example:
http://images.code-head.com/code/javascript/jquery-news-ticker.html
I know you might be able to write this using objects in a nicer form but this will [...]]]></description>
			<content:encoded><![CDATA[<p>I know I haven&#8217;t posted anything lately, I have been busy which is a good thing but I couldn&#8217;t resist this one, here is a simple news ticker using JavaScript and the great jQuery library.</p>
<p>Here is the example:<br />
<a href="http://images.code-head.com/code/javascript/jquery-news-ticker.html" target="_blank">http://images.code-head.com/code/javascript/jquery-news-ticker.html</a></p>
<p>I know you might be able to write this using objects in a nicer form but this will work and it&#8217;s to demonstrate the idea&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;jQuery New Ticker&lt;/title&gt;
&nbsp;
	&lt;script type=&quot;text/javascript&quot; src=&quot;http://images.code-head.com/jquery/jquery.js&quot;&gt; &lt;/script&gt;
&nbsp;
   &lt;script type=&quot;text/javascript&quot;&gt;
		$(document).ready(function() {
			var current = -1;
			var elems = new Array();
			var elems_i = 0;
			$('.items').each(function() {
				elems[elems_i++] = $(this);
			});
			var num_elems = elems_i - 1;
			var animate_out = function() {
				elems[current].animate({ top: '-100px' }, 'fast', 'linear', animate_in);
			}
			var animate_out_delay = function() {
				setTimeout(animate_out, 1000); /****************************** Change 1000 to make it longer/shorter/whatever */
			}
			var animate_in = function() {
				current = current &lt; num_elems ? current + 1 : 0;
				elems[current].css('top', '200px').animate({ top: '0px' }, 'fast', 'linear', animate_out_delay);
			}
			animate_in();
		});
	&lt;/script&gt;
&nbsp;
   &lt;style type=&quot;text/css&quot;&gt;
		.ticker {
			position: relative; /* So we can absolute the .items */
			width: 400px;
			height: 100px;
			overflow: hidden;
			margin: 100px;
			border: 1px dashed #666666;
		}
		.items {
			position: absolute;
			top: 200px;
			margin: 10px;
		}
	&lt;/style&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
   &lt;div class=&quot;ticker&quot;&gt;
      &lt;div class=&quot;items&quot;&gt;I'm a Cool&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;JavaScript&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;News Ticker&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;Using jQuery&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;For Smooth&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;And Nice&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;Animation&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;By Hamid Alipour&lt;/div&gt;
      &lt;div class=&quot;items&quot;&gt;@ &lt;a href=&quot;http://blog.code-head.com&quot; target=&quot;_blank&quot;&gt;blog.code-head.com&lt;/a&gt;&lt;/div&gt;
   &lt;/div&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Again, the code is straight forward, you must be able to understand what happens but here is a little explanation.</p>
<p>&lt;div class=&#8221;items&#8221;&gt; &#8230; &lt;/div&gt; are the news headlines to be animated and using CSS, they are absolute-positioned somewhere under the parent &lt;div class=&#8221;ticker&#8221;&gt; &#8230; &lt;/div&gt; box.</p>
<p>Normally, .itmes would be visible under the box, even when they are absolute-positioned but if you look into the stylesheet you will see:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.ticker</span> <span style="color: #00AA00;">&#123;</span>
   ...
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
   ...
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>That will prevent this from hapenning, so now our .items are floating somewhere under the box which is what we want. (Change it&#8217;s &#8216;width&#8217; and &#8216;height&#8217; to fit in whatever space you want&#8230;)</p>
<p>The JavaScript code starts with the first one and animates it all the way to the top and then pauses for a second (you can change it to whatever time you want), then it animates the one on the top to the top of the box by animating it all the way to &#8216;top: -100px;&#8217;, note that the same &#8216;overflow: hidden;&#8217; prevents it from showing.</p>
<p>It then picks up the next item, sets it&#8217;s top to 200px and animates it all the way to the top again and then repeat forever.</p>
<p>You might ask why it&#8217;s first setting the .items top to 200px; it&#8217;s because we are animating them to top of the box so we have to set their top to 200px again each time (we did this first in CSS), this is not important in the first iteration but after that every single item is on top of the box and has to be moved under the box.</p>
<p>I hope this makes sense.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=34SNgFMiK1o:3ETmKH-6kOQ: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=34SNgFMiK1o:3ETmKH-6kOQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=34SNgFMiK1o:3ETmKH-6kOQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=34SNgFMiK1o:3ETmKH-6kOQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=34SNgFMiK1o:3ETmKH-6kOQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=34SNgFMiK1o:3ETmKH-6kOQ: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=34SNgFMiK1o:3ETmKH-6kOQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=34SNgFMiK1o:3ETmKH-6kOQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=34SNgFMiK1o:3ETmKH-6kOQ: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-javascript-jquery-news-ticker/feed</wfw:commentRss>
		</item>
		<item>
		<title>Codehead Search Engine API; how to write your own Search Application in ~150 lines of code</title>
		<link>http://blog.code-head.com/codehead-search-engine-api-how-to-write-your-own-search-application-in-150-lines-of-code</link>
		<comments>http://blog.code-head.com/codehead-search-engine-api-how-to-write-your-own-search-application-in-150-lines-of-code#comments</comments>
		<pubDate>Thu, 03 Sep 2009 00:08:20 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Codehead Web Services]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Search Engines]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=696</guid>
		<description><![CDATA[We launched Codehead Web Services a while ago and have introduced 2 APIs so far [A Website Thumnail API and a Search Engine API].
Our goal is to provide some cool functionality that is rather hard to implement through a set of simple web services/APIs so users can create and enhance their own applications.
Here is a [...]]]></description>
			<content:encoded><![CDATA[<p>We launched <a href="http://webservices.code-head.com/">Codehead Web Services</a> a while ago and have introduced 2 APIs so far [A <a href="http://webservices.code-head.com/about-website-thumbnails">Website Thumnail API</a> and a <a href="http://webservices.code-head.com/about-codehead-search-api">Search Engine API</a>].</p>
<p>Our goal is to provide some cool functionality that is rather hard to implement through a set of simple web services/APIs so users can create and enhance their own applications.</p>
<p>Here is a full working search engine using the Codehead Search Engine API:</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: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">E_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Save sort order and match mode prefrences in a session variable */</span>
	<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Set default values for sort, match_mode and search_section */</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'relevance_date'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'any'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'articles'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'libs/codehead_api/codehead_api.php'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Codehead_API<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Assume there is a $_GET['q'], @ makes sure PHP won't trow E_NOTICE and if there is no $_GET['q'] then $q will be empty or '' */</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* $rpp is results per page */</span>
	<span style="color: #000088;">$rpp</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* $start is where to start the next page; at what item number? 10, 20, 50? This usually comes from a pager */</span>
	<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Whether or not the user want to change sort, match_mode or search section */</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Search - Powered By Codehead Search API&lt;/title&gt;
&nbsp;
	&lt;style type=&quot;text/css&quot;&gt;
		input { vertical-align: middle; }
	&lt;/style&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
&lt;!-- The search form --&gt;
&lt;form method=&quot;get&quot; action=&quot;&quot;&gt;
Search For: &lt;input type=&quot;text&quot; name=&quot;q&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt; &lt;input type=&quot;submit&quot; value=&quot;  GO  &quot; /&gt;
&lt;/form&gt;
Search in: 
	&lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;search_section=articles&quot;&gt;Articles&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;search_section=forums&quot;&gt;Forums&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;search_section=jobs&quot;&gt;Jobs&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;search_section=news&quot;&gt;News&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;search_section=blogs&quot;&gt;Blogs&lt;/a&gt; - It's '<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>' right now
&lt;br /&gt;
Sort by: 
	&lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;sort=relevance_date&quot;&gt;Relevance Date&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;sort=relevance&quot;&gt;Relevance Only&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;sort=date&quot;&gt;Date Only&lt;/a&gt; - It's '<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>' right now
&lt;br /&gt;
Matching Mode:
	&lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;match_mode=any&quot;&gt;Any Keyword&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;match_mode=all&quot;&gt;All Keywords&lt;/a&gt; - 
   &lt;a href=&quot;?q=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;match_mode=exact&quot;&gt;Exact Match&lt;/a&gt; - It's '<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>' right now
&lt;br /&gt;&lt;br /&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* If $q is not empty, do the search */</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/* Do the actual search, note how simple and painless it is! */</span>
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_section'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rpp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'match_mode'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/* Error checking is always necessary! */</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">has_error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'OOPS! there was a temporary error.'</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">/* If you want to display the internal error, go ahead and do */</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">/* All good, loop through and display the results */</span>
			<span style="color: #666666; font-style: italic;">// echo '&lt;pre&gt;'; print_r($results); exit;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Results <span style="color: #006699; font-weight: bold;">$start</span> to &quot;</span> <span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; out of around <span style="color: #006699; font-weight: bold;">{$results['total']}</span> total results; search took <span style="color: #006699; font-weight: bold;">{$results['search_time']}</span> second(s)!&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Show the previous/next page link */</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$rpp</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>?q=<span style="color: #006699; font-weight: bold;">$q</span>&amp;start=&quot;</span> <span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Next <span style="color: #006699; font-weight: bold;">$rpp</span> results&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span>
					<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot; - &lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>?q=<span style="color: #006699; font-weight: bold;">$q</span>&amp;start=&quot;</span> <span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Previous <span style="color: #006699; font-weight: bold;">$rpp</span> results&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">else</span>
					<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'results'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">/* Very rarely, some items might be deleted from the index so this check is necessary */</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
						<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">?&gt;</span>
					&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;br /&gt;
					&lt;small&gt;From: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'formated_date'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/small&gt;&lt;br /&gt;
					<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;br /&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span>
					<span style="color: #666666; font-style: italic;">/* Codehead Search groups results for news stories */</span>
					<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'grouped'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'grouped'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$gresult</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000000; font-weight: bold;">?&gt;</span>
							&lt;small&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gresult</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gresult</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt; - &lt;span style=&quot;color: #999999;&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gresult</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;
                  <span style="color: #000000; font-weight: bold;">&lt;?php</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Show the previous/next page link */</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$rpp</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>?q=<span style="color: #006699; font-weight: bold;">$q</span>&amp;start=&quot;</span> <span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Next <span style="color: #006699; font-weight: bold;">$rpp</span> results&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span>
					<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot; - &lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>?q=<span style="color: #006699; font-weight: bold;">$q</span>&amp;start=&quot;</span> <span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$rpp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Previous <span style="color: #006699; font-weight: bold;">$rpp</span> results&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'Your search didn\'</span>t match any documents<span style="color: #339933;">.</span><span style="color: #0000ff;">';
			}
&nbsp;
		}
&nbsp;
	}
&nbsp;
?&gt;</span>
&nbsp;
&lt;/body&gt;
&lt;/html&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> ENT_QUOTES<span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf-8'</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>It&#8217;s very easy to understand this code but I&#8217;ll try to explain a few things about how it works.</p>
<p>Here is the full documentation of our <a href="http://webservices.code-head.com/">Search Engine API</a>:</p>
<ul class="reference faq-style">
<li>
<div>
<h3>Simple Usage</h3>
<p>      	Here is the simplest way of searching our database for the term &#8216;PHP Sessions&#8217;:</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;">/* Include and instantiate Codehead_API here, if you don't know how, read from the beginning of this documentation */</span>
&nbsp;
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'articles'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'PHP Sessions'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">has_error</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;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'results'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">/* Very rarely, some items might be deleted from the index so this check is necessary */</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;br /&gt;
			&lt;small&gt;From: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'formated_date'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/small&gt;&lt;br /&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;br /&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #666666; font-style: italic;">/* Codehead Search groups results for news stories */</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'grouped'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'grouped'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$gresult</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">?&gt;</span>
					&lt;small&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gresult</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gresult</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt; - &lt;span style=&quot;color: #999999;&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gresult</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'Your search didn\'</span>t match any documents<span style="color: #339933;">.</span><span style="color: #0000ff;">';
	}
}
&nbsp;
?&gt;</span>
&lt;br /&gt;
			The function __escape() is not necessary but we like to escape EVERYTHING before printing, this function is very simple:&lt;br /&gt;&lt;br /&gt;
&lt;pre lang=&quot;php&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> __escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> ENT_QUOTES<span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf-8'</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></div>
</li>
<li>
<div>
<h3>Methods</h3>
<p>      	There are 6 methods that you can use to retrieve search results:</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: #990000;">array</span> do_search<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$section</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$search_term</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$results_per_page</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$sort_mode</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$match_mode</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #990000;">array</span> articles<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$search_term</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$results_per_page</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$sort_mode</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$match_mode</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> jobs<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$search_term</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$results_per_page</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$sort_mode</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$match_mode</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> forums<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$search_term</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$results_per_page</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$sort_mode</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$match_mode</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> blogs<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$search_term</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$results_per_page</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$sort_mode</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$match_mode</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #990000;">array</span> news<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$search_term</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$offset</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> int <span style="color: #000088;">$results_per_page</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$sort_mode</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$match_mode</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
         Below are detailed descriptions of these arguments and the reply from the server&#8230;
      </div>
</li>
<li>
<div>
<h3>Search Sections</h3>
<p>      	Codehead Search Engine API has 5 sections for searching:</p>
<p>         &nbsp; &nbsp; 1 - forums<br />
         &nbsp; &nbsp; 2 - articles<br />
         &nbsp; &nbsp; 3 - blogs<br />
         &nbsp; &nbsp; 4 - news<br />
         &nbsp; &nbsp; 5 - jobs</p>
<p>         You could search these sections directly like:</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;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jobs</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Python'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
         Or use the generic do_search method like:</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;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jobs'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Java'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
			<strong>!!!Please note that, the default section is &#8216;articles&#8217; so if you misspell the section or pass in an empty section, the API will respond with all the articles matching your term!!!</strong>
      </div>
</li>
<li>
<div>
<h3>Offset and Results Per Page (RPP)</h3>
<p>      	The offset is the start offset in which you want the results; if you have a pager and a user clicks on &#8216;Page 2&#8242; then you must pass in the starting offset of the page 2. The default value for offset is 0 which means starting at the beginning of the result set.</p>
<p>         Results per page (RPP) is the number of search results that you want to show on each of your SERP pages. Valid values for RPP are 10 or 25 and the default value is 10.</p>
<p>         As an example, suppose you are showing 10 search results per page so the starting offset of your page 3 would be 3 * 10 or 30 so:</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;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
			Will display the page 3.
      </div>
</li>
<li>
<div>
<h3>Sort Mode</h3>
<p>      	This is the mode in which the Search Engine API will sort your search results and valid values are:</p>
<h4>relevance_date</h4>
<p>         Which will sort your results in order of relevance to the search term and also their freshness, this is our prefered mode.</p>
<h4>relevance - Also Default</h4>
<p>         Will only sort your results based on their relevance to the search term. This is the default value for $sort_mode.</p>
<h4>date</h4>
<p>         Will only sort your results based on date and it&#8217;s the least favorite sorting mode.</p>
<h4>Examples</h4>

<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;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relevance_date'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* or */</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relevance'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* or */</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
      </div>
</li>
<li>
<div>
<h3>Match Mode</h3>
<p>      	There are 3 matching modes:</p>
<h4>any</h4>
<p>         This will tell the Search Engine API to match any of the keywords in your search term, for example if your search term is &#8216;SEO Jobs&#8217;, the API will return all the documents with either &#8216;SEO&#8217; or &#8216;Jobs&#8217; in them and that will include documents with both keywords in them too.</p>
<h4>all - Also Default</h4>
<p>         Will return all the documents with all the keywords in them. This is also the default $match_mode.</p>
<h4>exact</h4>
<p>         This will match all the documents with all the keywords in them but this time it will make sure that the keywords will appear in the exact order in the search term. This is basically phrase match, for example if your search term is &#8216;PHP Jobs Las Vegas&#8217;, the Search Engine API will return all the documents with the exact phrase &#8216;PHP Jobs Las Vegas&#8217; in them.</p>
<h4>Examples</h4>

<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;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relevance_date'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'any'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* or */</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relevance_date'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* or */</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bing'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relevance_date'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'exact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</p></div>
</li>
<li>
<div>
<h3>All About The Results Array</h3>
<p>      	The return value of any of the above methods is an array that contains the search results along with some data about the search.</p>
<p>         The components of this array are:</p>
<p>         &nbsp; &nbsp; 1 - results - Which is an array containing the search results.<br />
         &nbsp; &nbsp; 2 - total - Is the total number of matches, this is useful when building pagers.<br />
         &nbsp; &nbsp; 3 - encoding - Is the encoding of the items in the result.<br />
         &nbsp; &nbsp; 4 - time_now - The current time of the server in Unix timestamp.<br />
         &nbsp; &nbsp; 5 - start - The start offset of the results.<br />
         &nbsp; &nbsp; 6 - rpp - Results per page.<br />
         &nbsp; &nbsp; 7 - sort - Sort mode.<br />
         &nbsp; &nbsp; 8 - match_mode - Match mode.<br />
         &nbsp; &nbsp; 9 - search_time - The time it took to perform the search in milliseconds.</p>
<p>         <strong>!!!Please note that, each item in the &#8216;results&#8217; might contain another sub-array named &#8216;grouped&#8217; which are the results that were similar to that item; this will only be the case when you search the news!!!</strong></p>
<p>         The best way to examine the &#8216;results&#8217; array is to perform a search and then print_r() the results.</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;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blogs'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'snow leopard'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relevance_date'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'any'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</p></div>
</li>
</ul>
<p>Any problems with the API? You can create a support ticket in your <a href="http://webservices.code-head.com/">Codehead Webservice Account</a> under Account > Help.</p>
<p>Good Luck <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. Check out the original <a href="http://search.code-head.com/">Codehead Search</a>, our super-fast, custom search engine, where you can scour the best content on the net for computer and web related jobs, forum posts, articles and tutorials, blog posts and news stories all in one place. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=MojcGOmKcgM:umo4xOhqFMk: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=MojcGOmKcgM:umo4xOhqFMk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=MojcGOmKcgM:umo4xOhqFMk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=MojcGOmKcgM:umo4xOhqFMk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=MojcGOmKcgM:umo4xOhqFMk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=MojcGOmKcgM:umo4xOhqFMk: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=MojcGOmKcgM:umo4xOhqFMk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=MojcGOmKcgM:umo4xOhqFMk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=MojcGOmKcgM:umo4xOhqFMk: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/codehead-search-engine-api-how-to-write-your-own-search-application-in-150-lines-of-code/feed</wfw:commentRss>
		</item>
		<item>
		<title>CentOS-Yum: warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6</title>
		<link>http://blog.code-head.com/centos-yum-warning-rpmts_hdrfromfdno-header-v3-dsa-signature-nokey-key-id-6b8d79e6</link>
		<comments>http://blog.code-head.com/centos-yum-warning-rpmts_hdrfromfdno-header-v3-dsa-signature-nokey-key-id-6b8d79e6#comments</comments>
		<pubDate>Tue, 18 Aug 2009 00:31:46 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[CentOS]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=691</guid>
		<description><![CDATA[Try:
rpm &#8211;import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
rpm &#8211;import ftp://mirrors.easynews.com//linux/centos/RPM-GPG-K
  
]]></description>
			<content:encoded><![CDATA[<p>Try:</p>
<p>rpm &#8211;import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt<br />
rpm &#8211;import ftp://mirrors.easynews.com//linux/centos/RPM-GPG-K</p>
<p> <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=rTipj4uzeAU:s2Anp0ze_ao: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=rTipj4uzeAU:s2Anp0ze_ao:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=rTipj4uzeAU:s2Anp0ze_ao:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=rTipj4uzeAU:s2Anp0ze_ao:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=rTipj4uzeAU:s2Anp0ze_ao:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=rTipj4uzeAU:s2Anp0ze_ao: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=rTipj4uzeAU:s2Anp0ze_ao:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=rTipj4uzeAU:s2Anp0ze_ao:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=rTipj4uzeAU:s2Anp0ze_ao: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/centos-yum-warning-rpmts_hdrfromfdno-header-v3-dsa-signature-nokey-key-id-6b8d79e6/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to write a permission system using bits and bitwise operations in PHP</title>
		<link>http://blog.code-head.com/how-to-write-a-permission-system-using-bits-and-bitwise-operations-in-php</link>
		<comments>http://blog.code-head.com/how-to-write-a-permission-system-using-bits-and-bitwise-operations-in-php#comments</comments>
		<pubDate>Fri, 24 Jul 2009 05:24:11 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=685</guid>
		<description><![CDATA[I wrote this in PHP but you can use the same concept in other languages, I also assume an understanding of bits, bytes, binary to decimal conversion and vice-versa and bitwise operations on numbers like &#8216;or&#8217;, &#8216;and&#8217; and &#8216;xor&#8217; etc. if you have no idea, search and read about these first. You don&#8217;t have to [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this in PHP but you can use the same concept in other languages, I also assume an understanding of bits, bytes, binary to decimal conversion and vice-versa and bitwise operations on numbers like &#8216;or&#8217;, &#8216;and&#8217; and &#8216;xor&#8217; etc. if you have no idea, search and read about these first. You don&#8217;t have to be a guru but you should have an idea. Here are some pages to get you started:</p>
<p><a href="http://en.wikipedia.org/wiki/Byte">http://en.wikipedia.org/wiki/Byte</a><br />
<a href="http://en.wikipedia.org/wiki/Bitwise_operation">http://en.wikipedia.org/wiki/Bitwise_operation</a><br />
<a href="http://us.php.net/manual/en/language.operators.bitwise.php">http://us.php.net/manual/en/language.operators.bitwise.php</a><br />
<a href="http://www.google.com/search?q=Binary+to+decimal+conversion&#038;hl=en&#038;rls=com.microsoft%3A*%3AIE-SearchBox&#038;rlz=1I7GGLL_en&#038;sa=2">Some binary to decimal calculators to make it easier</a></p>
<p>We will use simple numbers to represent different permissions and as you might know a number is a collection of bytes. For example: an integer is usually 4 bytes. Although you don&#8217;t have to worry about the size of a number in a high level language like PHP but a little understanding of representation of numbers will help you better understand this technique.</p>
<p>So let&#8217;s assume when I say:</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;">$user_perms</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Internally the variable $user_perms looks like this:</p>
<p>|0|0|0|0|0|0|0|0|0|0|0|0|0|1|1|1|</p>
<p>This is a 2 byte representation of number 7, although, it might not look like this internally - it looks similar. Just assume this for now.</p>
<p>Let&#8217;s say that your application supports 4 functions that a user can use:</p>
<p>1 - Post a blog post<br />
2 - Comment on blog posts<br />
3 - Edit posts<br />
4 - Delete posts</p>
<p>Normally, you could have 4 fields in your database table (structure or whatever) for a user titled:</p>
<p>1 - can_post<br />
2 - can_comment<br />
3 - can_edit<br />
4 - can_delete</p>
<p>This is not good, 4 additional fields for your user table and who knows, what if your application has 100 functions? Do you want to add 100 fields to your user table?</p>
<p>With bits, you can have only 1 column and track all the permissions.</p>
<p>1 - perms</p>
<p>To do this, we will have to assign numbers for each of the functions: (Tip: use one of the calculators in the above list ;))</p>
<p>1 - Post a blog post 			|0|0|0|0|0|0|0|1|       is 1 in decimal<br />
2 - Comment on blog posts		|0|0|0|0|0|0|1|0|			is 2 in decimal<br />
3 - Edit posts						|0|0|0|0|0|1|0|0|			is 4 in decimal<br />
4 - Delete posts					|0|0|0|0|1|0|0|0|			is 8 in decimal</p>
<p>So you could have an array like this:</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;">$perms</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'can_post'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'can_comment'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'can_edit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'can_delete'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Almost there, let&#8217;s look at user&#8217;s perms field now.</p>
<p>I hope you know about bitwise &#8216;or&#8217;, when you &#8216;or&#8217; 1 and 1 you get 1; 0 &#8216;or&#8217; 1 is 1; 1 &#8216;or&#8217; 0, is 1 and finally 0 &#8216;or&#8217; 0 is 0, it&#8217;s just like the meaning of &#8216;or&#8217; in the English language.</p>
<p>Similarly, bitwise &#8216;and&#8217;; when you &#8216;and&#8217; 1 and 1 you get 1; 0 &#8216;and&#8217; 1 is 0; 1 &#8216;and&#8217; 0, is 0 and finally 0 &#8216;and&#8217; 0 is 0, again it&#8217;s just like the meaning of &#8216;or&#8217; in the English language.</p>
<p>Bitwise &#8216;xor&#8217;; when you &#8216;xor&#8217; 1 and 1 you get 0; 0 &#8216;xor&#8217; 1 is 1; 1 &#8216;xor&#8217; 0, is 1 and finally 0 &#8216;xor&#8217; 0 is 0.</p>
<p>So suppose you want to give a user permissions to post a blog post, post a comment and edit posts but not delete posts, you do it like this:</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;">$user_perms</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_post'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_comment'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_edit'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Note that, in PHP &#8216;|&#8217; means &#8216;or&#8217;, so what just happened is something like this:</p>
<p>|0|0|0|0|0|0|0|1| &#8216;or&#8217;<br />
|0|0|0|0|0|0|1|0| &#8216;or&#8217;<br />
|0|0|0|0|0|1|0|0|<br />
_______________________<br />
|0|0|0|0|0|1|1|1|</p>
<p>Now $user_perms has the value 7 and |0|0|0|0|0|1|1|1| in it internally.</p>
<p>Suppose that this is on top of your post_blog.php or where ever you want to handle permissions for posting a blog, the only thing you need to do is:</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_perms</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_post'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/* He/She has permissios to do this */</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/* He/She doesn't */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In PHP &#8216;&#038;&#8217; is for bitwise &#8216;and&#8217;, please also note that &#8216;&#038;&#038;&#8217; is logical &#8216;and&#8217; and doesn&#8217;t operate on individual bits.</p>
<p>This is exactly what just happened:</p>
<p>|0|0|0|0|0|1|1|1| &#8216;and&#8217;<br />
|0|0|0|0|0|0|0|1|<br />
_______________________<br />
|0|0|0|0|0|0|0|1|</p>
<p>So that&#8217;s &#8216;one&#8217; not &#8216;0&#8242;, which  means &#8216;if&#8217; passes and the user has permissions to do this. But when it comes to deleting posts:</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_perms</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_delete'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/* He/She does permissios to do this */</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/* He/She doesn't */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Thus:</p>
<p>|0|0|0|0|0|1|1|1| &#8216;and&#8217;<br />
|0|0|0|0|1|0|0|0|<br />
_______________________<br />
|0|0|0|0|0|0|0|0|</p>
<p>It&#8217;s &#8216;zero&#8217; so &#8216;if&#8217; fails and you show an error message or whatever it is you do.</p>
<p>To add &#8216;delete&#8217; permissions, you use &#8216;or&#8217; again:</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;">$user_perms</span> <span style="color: #339933;">|=</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_delete'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So this happens:</p>
<p>|0|0|0|0|0|1|1|1| &#8216;or&#8217;<br />
|0|0|0|0|1|0|0|0|<br />
_______________________<br />
|0|0|0|0|1|1|1|1|</p>
<p>To take away permissions you use &#8216;xor&#8217;:</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;">$user_perms</span> ^<span style="color: #339933;">=</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_delete'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And this will happen:</p>
<p>|0|0|0|0|1|1|1|1| &#8216;xor&#8217;<br />
|0|0|0|0|1|0|0|0|<br />
_______________________<br />
|0|0|0|0|0|1|1|1|</p>
<p>And delete permissions are gone!</p>
<p>Now let&#8217;s take away post permissions:</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;">$user_perms</span> ^<span style="color: #339933;">=</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'can_post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Thus:</p>
<p>|0|0|0|0|0|1|1|1| &#8216;xor&#8217;<br />
|0|0|0|0|0|0|0|1|<br />
_______________________<br />
|0|0|0|0|0|1|1|0|</p>
<p>So this was just the basics, you can build on this and do more once you understand.</p>
<p>I hope this post will help 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=_EuLtJg-nBA:tkpAmL4waw4: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=_EuLtJg-nBA:tkpAmL4waw4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=_EuLtJg-nBA:tkpAmL4waw4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=_EuLtJg-nBA:tkpAmL4waw4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=_EuLtJg-nBA:tkpAmL4waw4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=_EuLtJg-nBA:tkpAmL4waw4: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=_EuLtJg-nBA:tkpAmL4waw4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=_EuLtJg-nBA:tkpAmL4waw4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=_EuLtJg-nBA:tkpAmL4waw4: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-write-a-permission-system-using-bits-and-bitwise-operations-in-php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Implementation of a Vector data structure in C</title>
		<link>http://blog.code-head.com/implementation-of-a-vector-data-structure-in-c</link>
		<comments>http://blog.code-head.com/implementation-of-a-vector-data-structure-in-c#comments</comments>
		<pubDate>Thu, 23 Jul 2009 22:16:44 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[C Programming]]></category>

		<category><![CDATA[Data Structures]]></category>

		<category><![CDATA[Low Level]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=674</guid>
		<description><![CDATA[I use Python a lot but it&#8217;s very slow in some cases which I then use C because it can be 1,000s X faster than Python.
Here is a Vector that I just wrote to use in my new project:
vector.h

/**
 * Hamid Alipour
 */
&#160;
#ifndef __VECTORH__
#define __VECTORH__
&#160;
#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;
#include &#60;ctype.h&#62;
#include &#60;string.h&#62;
#include &#60;assert.h&#62;
&#160;
#define VECTOR_INIT_SIZE    4
#define [...]]]></description>
			<content:encoded><![CDATA[<p>I use Python a lot but it&#8217;s very slow in some cases which I then use C because it can be 1,000s X faster than Python.</p>
<p>Here is a Vector that I just wrote to use in my new project:</p>
<p>vector.h</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Hamid Alipour
 */</span>
&nbsp;
<span style="color: #339933;">#ifndef __VECTORH__</span>
<span style="color: #339933;">#define __VECTORH__</span>
&nbsp;
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;ctype.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#include &lt;assert.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define VECTOR_INIT_SIZE    4</span>
<span style="color: #339933;">#define VECTOR_HASSPACE(v)  (((v)-&gt;num_elems + 1) &lt;= (v)-&gt;num_alloc_elems)</span>
<span style="color: #339933;">#define VECTOR_INBOUNDS(i)	(((int) i) &gt;= 0 &amp;&amp; (i) &lt; (v)-&gt;num_elems)</span>
<span style="color: #339933;">#define VECTOR_INDEX(i)		((char *) (v)-&gt;elems + ((v)-&gt;elem_size * (i)))</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> _vector <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elems<span style="color: #339933;">;</span>
	size_t elem_size<span style="color: #339933;">;</span>
	size_t num_elems<span style="color: #339933;">;</span>
	size_t num_alloc_elems<span style="color: #339933;">;</span>
    <span style="color: #993333;">void</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>free_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> vector<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_init<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> size_t<span style="color: #339933;">,</span> size_t<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>free_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_dispose<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_copy<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> vector <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_insert<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> size_t index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_insert_at<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> size_t index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_push<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_pop<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_shift<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_unshift<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_get<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> size_t<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_remove<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> size_t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_transpose<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> size_t<span style="color: #339933;">,</span> size_t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> size_t vector_length<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> size_t vector_size<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_get_all<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_cmp_all<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cmp_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_qsort<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cmp_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> vector_grow<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*,</span> size_t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> vector_swap<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> size_t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">#endif</span></pre></div></div>

<p>And vector.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Hamid Alipour
 */</span>
&nbsp;
<span style="color: #339933;">#include &quot;vector.h&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_init<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> size_t elem_size<span style="color: #339933;">,</span> size_t init_size<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>free_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	v<span style="color: #339933;">-&gt;</span>elem_size <span style="color: #339933;">=</span> elem_size<span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>num_alloc_elems <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> init_size <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">?</span> init_size <span style="color: #339933;">:</span> VECTOR_INIT_SIZE<span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>elem_size <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>num_alloc_elems<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>free_func <span style="color: #339933;">=</span> free_func <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">NULL</span> <span style="color: #339933;">?</span> free_func <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_dispose<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	size_t i<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>free_func <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			v<span style="color: #339933;">-&gt;</span>free_func<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	free<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_copy<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v1<span style="color: #339933;">,</span> vector <span style="color: #339933;">*</span>v2<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	v2<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">=</span> v1<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">;</span>
	v2<span style="color: #339933;">-&gt;</span>num_alloc_elems <span style="color: #339933;">=</span> v1<span style="color: #339933;">-&gt;</span>num_alloc_elems<span style="color: #339933;">;</span>
	v2<span style="color: #339933;">-&gt;</span>elem_size <span style="color: #339933;">=</span> v1<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #339933;">;</span>
&nbsp;
	v2<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">=</span> realloc<span style="color: #009900;">&#40;</span>v2<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v2<span style="color: #339933;">-&gt;</span>num_alloc_elems <span style="color: #339933;">*</span> v2<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>v2<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	memcpy<span style="color: #009900;">&#40;</span>v2<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v1<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v2<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">*</span> v2<span style="color: #339933;">-&gt;</span>elem_size<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;">extern</span> <span style="color: #993333;">void</span> vector_insert<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #339933;">,</span> size_t index<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">void</span> <span style="color: #339933;">*</span>target<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> index <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</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: #339933;">!</span>VECTOR_INBOUNDS<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		target <span style="color: #339933;">=</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>VECTOR_HASSPACE<span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			vector_grow<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		target <span style="color: #339933;">=</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">++;</span> <span style="color: #808080; font-style: italic;">/* Only grow when adding a new item not when inserting in a spec indx */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	memcpy<span style="color: #009900;">&#40;</span>target<span style="color: #339933;">,</span> elem<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<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;">extern</span> <span style="color: #993333;">void</span> vector_insert_at<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #339933;">,</span> size_t index<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: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> index <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>VECTOR_HASSPACE<span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		vector_grow<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&lt;</span> v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #009900;">&#41;</span>
		memmove<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">-</span> index<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 1: we are passing index so insert won't increment this 2: insert checks INBONDS... */</span>
	v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">++;</span>
&nbsp;
	vector_insert<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">,</span> elem<span style="color: #339933;">,</span> index<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;">extern</span> <span style="color: #993333;">void</span> vector_push<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	vector_insert<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">,</span> elem<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_pop<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	memcpy<span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">--;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_shift<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	memcpy<span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	memmove<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">--;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_unshift<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<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: #339933;">!</span>VECTOR_HASSPACE<span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		vector_grow<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	memmove<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	memcpy<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> elem<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_transpose<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> size_t index1<span style="color: #339933;">,</span> size_t index2<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	vector_swap<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span>index1<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>index2<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> vector_grow<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> size_t size<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>size <span style="color: #339933;">&gt;</span> v<span style="color: #339933;">-&gt;</span>num_alloc_elems<span style="color: #009900;">&#41;</span>
		v<span style="color: #339933;">-&gt;</span>num_alloc_elems <span style="color: #339933;">=</span> size<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		v<span style="color: #339933;">-&gt;</span>num_alloc_elems <span style="color: #339933;">*=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
	v<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">=</span> realloc<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>num_alloc_elems<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">NULL</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;">extern</span> <span style="color: #993333;">void</span> vector_get<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> size_t index<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	assert<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> index <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>VECTOR_INBOUNDS<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		elem <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	memcpy<span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<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;">extern</span> <span style="color: #993333;">void</span> vector_get_all<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elems<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	memcpy<span style="color: #009900;">&#40;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>elem_size<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;">extern</span> <span style="color: #993333;">void</span> vector_remove<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> size_t index<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	assert<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> index <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>VECTOR_INBOUNDS<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	memmove<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>index <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">--;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_remove_all<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	v<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">=</span> realloc<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>num_alloc_elems<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">NULL</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;">extern</span> size_t vector_length<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> size_t vector_size<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> v<span style="color: #339933;">-&gt;</span>num_elems <span style="color: #339933;">*</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> vector_cmp_all<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elem<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cmp_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	size_t i<span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> <span style="color: #339933;">*</span>best_match <span style="color: #339933;">=</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cmp_func<span style="color: #009900;">&#40;</span>VECTOR_INDEX<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> best_match<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			best_match <span style="color: #339933;">=</span> VECTOR_INDEX<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	memcpy<span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> best_match<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<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;">extern</span> <span style="color: #993333;">void</span> vector_qsort<span style="color: #009900;">&#40;</span>vector <span style="color: #339933;">*</span>v<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cmp_func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	qsort<span style="color: #009900;">&#40;</span>v<span style="color: #339933;">-&gt;</span>elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>num_elems<span style="color: #339933;">,</span> v<span style="color: #339933;">-&gt;</span>elem_size<span style="color: #339933;">,</span> cmp_func<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> vector_swap<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elemp1<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>elemp2<span style="color: #339933;">,</span> size_t elem_size<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">void</span> <span style="color: #339933;">*</span>tmp <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	memcpy<span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span> elemp1<span style="color: #339933;">,</span> elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	memcpy<span style="color: #009900;">&#40;</span>elemp1<span style="color: #339933;">,</span> elemp2<span style="color: #339933;">,</span> elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	memcpy<span style="color: #009900;">&#40;</span>elemp2<span style="color: #339933;">,</span> tmp<span style="color: #339933;">,</span> elem_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It works <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I will write another post with some example usage soon&#8230;</p>
<p>Notice that, all the functions that return a value, return it through their arguments and not the &#8220;return&#8221; statement, this is because I wanted the client to be responsible for allocating/freeing memory for these variables and that makes everyone&#8217;s job easier.</p>
<p>As always, I&#8217;m open to criticism/ideas and please use it at your own risk.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=3L0ifCdi3i0:vI7bQCNf-xM: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=3L0ifCdi3i0:vI7bQCNf-xM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=3L0ifCdi3i0:vI7bQCNf-xM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=3L0ifCdi3i0:vI7bQCNf-xM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=3L0ifCdi3i0:vI7bQCNf-xM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=3L0ifCdi3i0:vI7bQCNf-xM: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=3L0ifCdi3i0:vI7bQCNf-xM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=3L0ifCdi3i0:vI7bQCNf-xM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=3L0ifCdi3i0:vI7bQCNf-xM: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/implementation-of-a-vector-data-structure-in-c/feed</wfw:commentRss>
		</item>
		<item>
		<title>The annoying PHP ZipArchive class</title>
		<link>http://blog.code-head.com/the-annoying-php-ziparchive-class</link>
		<comments>http://blog.code-head.com/the-annoying-php-ziparchive-class#comments</comments>
		<pubDate>Tue, 14 Jul 2009 05:04:18 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Annoying Stuff]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=664</guid>
		<description><![CDATA[This is very rare, PHP&#8217;s extensions are usually well done but this one, ZipArchive class is very annoying and I&#8217;m very surprised that it&#8217;s now in PHP&#8217;s distribution&#8230;
In my case, it doesn&#8217;t create the archive for some reason and it doesn&#8217;t throw any errors either.
http://us3.php.net/manual/en/class.ziparchive.php
I&#8217;m very disappointed and I wasted a lot of time and [...]]]></description>
			<content:encoded><![CDATA[<p>This is very rare, PHP&#8217;s extensions are usually well done but this one, ZipArchive class is very annoying and I&#8217;m very surprised that it&#8217;s now in PHP&#8217;s distribution&#8230;</p>
<p>In my case, it doesn&#8217;t create the archive for some reason and it doesn&#8217;t throw any errors either.</p>
<p><a href="http://us3.php.net/manual/en/class.ziparchive.php">http://us3.php.net/manual/en/class.ziparchive.php</a></p>
<p>I&#8217;m very disappointed and I wasted a lot of time and yes, all the permissions etc. are right.</p>
<p>So ended up using system calls; first create a temporary folder and then something like:</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;zip -r THE_ZIP_FILE.zip PATH_TO_THE_TMP_FOLDER&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And now the problem with this is that it&#8217;s not portable, it&#8217;s fine in my case though.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=S-keH5S4RRM:C9zapVpzDWI: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=S-keH5S4RRM:C9zapVpzDWI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=S-keH5S4RRM:C9zapVpzDWI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=S-keH5S4RRM:C9zapVpzDWI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=S-keH5S4RRM:C9zapVpzDWI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=S-keH5S4RRM:C9zapVpzDWI: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=S-keH5S4RRM:C9zapVpzDWI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=S-keH5S4RRM:C9zapVpzDWI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=S-keH5S4RRM:C9zapVpzDWI: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-annoying-php-ziparchive-class/feed</wfw:commentRss>
		</item>
		<item>
		<title>Viewing Actionscript within .fla file</title>
		<link>http://blog.code-head.com/viewing-actionscript-within-fla-file</link>
		<comments>http://blog.code-head.com/viewing-actionscript-within-fla-file#comments</comments>
		<pubDate>Wed, 08 Jul 2009 00:37:17 +0000</pubDate>
		<dc:creator>Codehead</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.code-head.com/?p=660</guid>
		<description><![CDATA[It&#8217;s very simple, hit F9  
I wish it was more obvious to beginners though.
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very simple, hit F9 <img src='http://blog.code-head.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I wish it was more obvious to beginners though.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=F-fHtdZljKg:5Q0Y6uNOTg0: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=F-fHtdZljKg:5Q0Y6uNOTg0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=F-fHtdZljKg:5Q0Y6uNOTg0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=F-fHtdZljKg:5Q0Y6uNOTg0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=F-fHtdZljKg:5Q0Y6uNOTg0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=F-fHtdZljKg:5Q0Y6uNOTg0: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=F-fHtdZljKg:5Q0Y6uNOTg0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?i=F-fHtdZljKg:5Q0Y6uNOTg0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/WebDevelopment-Seo-Codehead?a=F-fHtdZljKg:5Q0Y6uNOTg0: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/viewing-actionscript-within-fla-file/feed</wfw:commentRss>
		</item>
		<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>
	</channel>
</rss>
