<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>omes.org - Oops I did it again...</title>
	<atom:link href="http://omes.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://omes.org</link>
	<description>Coding, science and personal blog.</description>
	<lastBuildDate>Fri, 25 Feb 2011 20:42:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Old session counter in PHP</title>
		<link>http://omes.org/old-session-counter-in-php/</link>
		<comments>http://omes.org/old-session-counter-in-php/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 19:02:41 +0000</pubDate>
		<dc:creator>omes</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://omes.org/?p=32</guid>
		<description><![CDATA[I just wanted to share some old code I got lying around. It&#8217;s a session counter in PHP basically what it does is to increase a variable with one each time a page with the code is refreshed/visited. I even &#8230; <a href="http://omes.org/old-session-counter-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just wanted to share some old code I got lying around. It&#8217;s a session counter in PHP basically what it does is to increase a variable with one each time a page with the code is refreshed/visited. I even have a <a href="http://omes.org/sessiontest/">live example</a> of it.</p>
<p>The code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Start sessions!</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>
<span style="color: #666666; font-style: italic;">// Is $_SESSION[&quot;count&quot;] set? If yes, increase by one, if not set to one.</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;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++</span> <span style="color: #339933;">:</span>  <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;This page has been loaded: {<span style="color: #006699; font-weight: bold;">$_SESSION</span>[&quot;</span><span style="color: #990000;">count</span><span style="color: #0000ff;">&quot;]} time(s).&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;br /&gt; Reload the page. It's a simple counter using sessions to keep the count.</pre></div></div>

<p>Each time you refresh the page the the count will increase with one. Remove the cookie to start from 1 again.</p>
]]></content:encoded>
			<wfw:commentRss>http://omes.org/old-session-counter-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bypass Google Images intermediary page</title>
		<link>http://omes.org/bypass-google-images-intermediary-page/</link>
		<comments>http://omes.org/bypass-google-images-intermediary-page/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 18:33:56 +0000</pubDate>
		<dc:creator>omes</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://omes.org/?p=38</guid>
		<description><![CDATA[Ever wanted the Google Image search results to go directly to your page? Look no further! This goes into your page, and it will make make the users&#8217; browser refresh once your page is loaded under the picture that google &#8230; <a href="http://omes.org/bypass-google-images-intermediary-page/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever wanted the Google Image search results to go directly to your page?</p>
<p>Look no further! This goes into your page, and it will make make the users&#8217; browser refresh once your page is loaded under the picture that google displays.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>top.<span style="color: #660066;">location</span> <span style="color: #339933;">!=</span> location<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  top.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>I might make some pictures for show and tell later.</p>
]]></content:encoded>
			<wfw:commentRss>http://omes.org/bypass-google-images-intermediary-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XOR-Swap</title>
		<link>http://omes.org/xor-swap/</link>
		<comments>http://omes.org/xor-swap/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 13:58:04 +0000</pubDate>
		<dc:creator>omes</dc:creator>
				<category><![CDATA[Optimization]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://omes.org/?p=17</guid>
		<description><![CDATA[I&#8217;m having a lot of fun writing a for-fun play-money online casino these days. Every day you learn something new, and about a week ago I learned about XOR-Swap. The idea is very simple, yet very effective. The website I&#8217;m &#8230; <a href="http://omes.org/xor-swap/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m having a lot of fun writing a for-fun play-money online casino these days. Every day you learn something new, and about a week ago I learned about <a href="http://en.wikipedia.org/wiki/XOR_swap_algorithm">XOR-Swap</a>. The idea is very simple, yet very effective. The website I&#8217;m working on is written in PHP, so I&#8217;ll present the code in that language as well, but it&#8217;ll work in any language that can do <a href="http://en.wikipedia.org/wiki/Exclusive_or">eXclusive OR</a>.</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>
a <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">44</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span>^<span style="color: #339933;">=</span><span style="color: #000088;">$b</span>^<span style="color: #339933;">=</span><span style="color: #000088;">$a</span>^<span style="color: #339933;">=</span><span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//$a = 44;</span>
<span style="color: #666666; font-style: italic;">//$b = 10;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you&#8217;re having trouble reading that it might be a bit easier to write it all out.</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>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">44</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span>^<span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$b</span>^<span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span>^<span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//$a = 10;</span>
<span style="color: #666666; font-style: italic;">//$b = 44;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You might be thinking; &#8220;<em>why not do just assign a temporary variable instead</em>&#8220;, and that works great too. However you won&#8217;t feel warm and fuzzy inside. You won&#8217;t be able to show off with your one-line ninja code either. Assigning a temporary variable and XOR-Swap is about equal in performance &#8211; I&#8217;ve benchmarked this. A temporary variable will leave a footprint equal to the size of your variable, but memory is cheap, right? However using something like <code>list($a, $b) = array($b, $a);</code> is a lot slower &#8211; if you think about it that makes sense as you actually have to populate the array before assigning it to the variables in the list. When I say a lot slower, I mean a lot slower. I might post benchmarks for this in a later post.</p>
<p>One thing you have to worry about is if the the two variables you&#8217;re XOR-Swapping are not the same <a href="http://en.wikipedia.org/wiki/Type_system">type</a> or if they are of unequal length. XOR-Swapping <code>$a = "hello"; $b = "world";</code> will work, but <code>$a = "hello"; $b = "world!";</code> will break.</p>
]]></content:encoded>
			<wfw:commentRss>http://omes.org/xor-swap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posts coming to a blog near you!</title>
		<link>http://omes.org/posts-coming-to-a-blog-near-you/</link>
		<comments>http://omes.org/posts-coming-to-a-blog-near-you/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 13:37:25 +0000</pubDate>
		<dc:creator>omes</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://omes.org/?p=13</guid>
		<description><![CDATA[It took me a year, but I promise I&#8217;ll start writing some posts on this blog in the very near future. I don&#8217;t know if anyone will find what I write useful or even interesting, but if you do I &#8230; <a href="http://omes.org/posts-coming-to-a-blog-near-you/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It took me <a href="http://omes.org/first-post/">a year,</a> but I promise I&#8217;ll start writing some posts on this blog in the <em>very</em> near future.</p>
<p>I don&#8217;t know if anyone will find what I write useful or even interesting, but if you do I would love to hear about it! Feel free to drop a me a personal message or write a comment. I&#8217;m looking for some work, so if you need somebody to do freelance for you hit me up!</p>
]]></content:encoded>
			<wfw:commentRss>http://omes.org/posts-coming-to-a-blog-near-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First post!</title>
		<link>http://omes.org/first-post/</link>
		<comments>http://omes.org/first-post/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 23:19:25 +0000</pubDate>
		<dc:creator>omes</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://omes.org/wordpress/?p=3</guid>
		<description><![CDATA[Those who wait for something good Might find themselves waiting forever&#8230;]]></description>
			<content:encoded><![CDATA[<p>Those who wait for something good</p>
<p>Might find themselves waiting forever&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://omes.org/first-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

