<?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></title>
	<atom:link href="http://blog.gemmapeter.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gemmapeter.co.uk</link>
	<description>Gem&#039;s ponderings on PHP programming and other stuff</description>
	<lastBuildDate>Mon, 12 Jul 2010 12:39:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>DRM sudden outbreak of common sense</title>
		<link>http://blog.gemmapeter.co.uk/2010/07/12/drm-sudden-outbreak-of-common-sense/</link>
		<comments>http://blog.gemmapeter.co.uk/2010/07/12/drm-sudden-outbreak-of-common-sense/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 12:39:43 +0000</pubDate>
		<dc:creator>Gem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.gemmapeter.co.uk/?p=346</guid>
		<description><![CDATA[An update to one of my previous posts from 5 years ago on the DRM vs Copyright issue. It seems that Brazil&#8217;s copyright reforms are planning to include parts that not only allow breaking DRM for fair use but also penalize people who put DRM on a work that restrict rights of users accorded to [...]]]></description>
			<content:encoded><![CDATA[<p>An update to one of my previous posts from 5 years ago on the <a href="http://blog.gemmapeter.co.uk/2005/11/18/drm-vs-copyright/">DRM vs Copyright</a> issue.</p>
<p>It seems that Brazil&#8217;s copyright reforms are planning to include parts that not only allow breaking DRM for fair use but also penalize people who put DRM on a work that restrict rights of users accorded to them by law.</p>
<p>Link: <a href="http://www.michaelgeist.ca/content/view/5180/125/">Brazil&#8217;s Approach on Anti-Circumvention: Penalties For Hindering Fair Dealing</a> (via <a href="http://www.boingboing.net/2010/07/10/brazils-copyright-la.html">Boing Boing</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemmapeter.co.uk/2010/07/12/drm-sudden-outbreak-of-common-sense/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missile Mayhem</title>
		<link>http://blog.gemmapeter.co.uk/2010/04/29/missile-mayhem/</link>
		<comments>http://blog.gemmapeter.co.uk/2010/04/29/missile-mayhem/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 15:06:31 +0000</pubDate>
		<dc:creator>Gem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.gemmapeter.co.uk/?p=329</guid>
		<description><![CDATA[Or how to I set up my USB missile launcher to be controlled over the internet with Linux. Get missile launcher to work with pymissile. Run pymissile with the &#8211;network option. This will allow you to connect to it using UDP on port 20000 and send commands at it. To test this use the netcat [...]]]></description>
			<content:encoded><![CDATA[<p>Or how to I set up my USB missile launcher to be controlled over the internet with Linux.</p>
<p>Get missile launcher to work with <a href="http://code.google.com/p/pymissile/">pymissile</a>.</p>
<p>Run pymissile with the &#8211;network option. This will allow you to connect to it using UDP on port 20000 and send commands at it.</p>
<p>To test this use the netcat command on the same machine:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nc <span style="color: #660033;">-u</span> 127.0.0.1 <span style="color: #000000;">20000</span></pre></div></div>

<p>Commands are typed as &#8220;&lt;command&gt;:&lt;enter&gt;&#8221;</p>
<pre>w or up - move up
x or down - move down
a or left - move left
d or right - move right
f or space - fire
s - stop moving
q - move diagonally up-left
e - move diagonally up-right
z - move diagonally down-left
k - move diagonally down-right
r - fire all missiles sequentially
v - fire randomly
esc - close daemon</pre>
<p>Available commands can be found in the class MissileNetwork class in the <a href="http://code.google.com/p/pymissile/source/browse/trunk/missile.py#323">source code</a></p>
<p>Then I set up a web server (lighttpd because it&#8217;s only a netbook) on the local machine and forwarded port 80 through the NAT. The webserver runs a PHP script that sends UDP packets. The sample code was grabbed from the <a href="http://php.net/manual/en/function.fsockopen.php">fsockopen</a> documentation and modified to fit.</p>
<p>The web frontend uses the function below and some AJAX to send requests.</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: #000000; font-weight: bold;">function</span> send_command<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;udp://127.0.0.1&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20000</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ERROR: <span style="color: #006699; font-weight: bold;">$errno</span> - <span style="color: #006699; font-weight: bold;">$errstr</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</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: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$command}</span>:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then I set up the webcam to stream live on UStream so people could see where they were aiming.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemmapeter.co.uk/2010/04/29/missile-mayhem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mock PHP 5 exam</title>
		<link>http://blog.gemmapeter.co.uk/2009/07/25/mock-php-5-exam/</link>
		<comments>http://blog.gemmapeter.co.uk/2009/07/25/mock-php-5-exam/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 19:24:11 +0000</pubDate>
		<dc:creator>Gem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.gemmapeter.co.uk/?p=224</guid>
		<description><![CDATA[I have been considering going for the Zend PHP 5 certification and bought myself some Zend PHP 5 Practice Exams to see what I need to study up on. Here is one of the questions I came across. Which of the following functions are part of PHP's internal Iterator interface? Answers: (choose 5) rewind() valid() [...]]]></description>
			<content:encoded><![CDATA[<p>I have been considering going for the Zend PHP 5 certification and bought myself some <a href="http://shop.zend.com/en/php-certification/zend-php-certification-online-practice-testing.html">Zend PHP 5 Practice Exams</a> to see what I need to study up on.</p>
<p>Here is one of the questions I came across.</p>
<pre>
Which of the following functions are part of PHP's internal Iterator interface?

Answers: (choose 5)
    rewind()
    valid()
    next()
    key()
    current()
</pre>
<p>Maybe they had problems passing candidates that couldn&#8217;t count to five.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemmapeter.co.uk/2009/07/25/mock-php-5-exam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do I unit test this?</title>
		<link>http://blog.gemmapeter.co.uk/2009/02/20/how-do-i-unit-test-this/</link>
		<comments>http://blog.gemmapeter.co.uk/2009/02/20/how-do-i-unit-test-this/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 17:25:43 +0000</pubDate>
		<dc:creator>Gem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.gemmapeter.co.uk/?p=200</guid>
		<description><![CDATA[Came across a tricky bug a few weeks ago whilst working on some extremely fragile code. This was the code: settings.php $mail_settings = array&#40; 'server' =&#62; 'mail.example.com', 'port' =&#62; 25 &#41;; index.php function send_email&#40;$recipient, $message&#41; &#123; include_once&#40;'settings.php'&#41;; $foo = new MailSender&#40;$mail_settings&#41;; $foo-&#62;send&#40;$message, $recipient&#41;; //this was line number in the error message &#125; &#160; send_email&#40;'admin@example.com', 'Admin [...]]]></description>
			<content:encoded><![CDATA[<p>Came across a tricky bug a few weeks ago whilst working on some extremely fragile code.</p>
<p>This was the code:</p>
<hr />
<p>settings.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mail_settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'server'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mail.example.com'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<hr />
<p>index.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> send_email<span style="color: #009900;">&#40;</span><span style="color: #000088;">$recipient</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'settings.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MailSender<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mail_settings</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$recipient</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//this was line number in the error message</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
send_email<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin@example.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Admin message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
send_email<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user@example.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'User message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<hr />
<p>The tricky part was debugging it, it threw an error on the second call of the send_email function. That&#8217;s odd it ran fine the first time and the only thing I could see that had changed was the input to the function, surely that must be the problem? I commented out the second function call error went away, commented it back in and the error was back. This fitted with my hypothesis that the input on the second one was causing the error. But after looking inside the MailSender class I couldn&#8217;t see any reason why the function would error there.</p>
<p>I called Kev to give the problem a fresh set of eyes because sometimes when you are working on things like this you end up not being able to see the thing you&#8217;re looking for if you stare at the code for too long.</p>
<p>We took apart the function. We created a new file and replaced each function call with the code which was inside the function and were surprised when it worked perfectly. We were confused as to how the exact same code when placed inside a function would have any different effect.</p>
<p>After looking in the wrong places for a while we finally decided to re-examine our assumptions about what the commenting out was telling us. It wasn&#8217;t telling us that the problem is in how we were calling the function the second time around, it was the fact that we were calling the function twice.</p>
<p>After realising that it was obvious what was causing the error.</p>
<ul>
<li>Mailsender needs $mail_settings to work</li>
<li>variables from settings.php were included with an include once</li>
<li>include once will not include a file that has already been included</li>
<li>the second function call will not have access to variables from settings.php since they are a) out of scope from first function call b) won&#8217;t be included again due to the include once</li>
</ul>
<p>After changing the include_once to an include the function worked as expected.</p>
<p>This made me think of some questions. How would I unit test this? Should I create a unit test that runs each function n times? How could I ensure that the test wouldn&#8217;t fail at n+1 times? How can I be sure my test will be accurate without running the function an infinite amount of times?</p>
<p>Of course the real solution would be to remove the hidden dependencies caused by creating variables in an included file but to do that to this particular inherited project would require a complete rewrite.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemmapeter.co.uk/2009/02/20/how-do-i-unit-test-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tomb Raider: Underworld First Impressions</title>
		<link>http://blog.gemmapeter.co.uk/2008/11/22/tomb-raider-underworld-first-impressions/</link>
		<comments>http://blog.gemmapeter.co.uk/2008/11/22/tomb-raider-underworld-first-impressions/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 19:24:50 +0000</pubDate>
		<dc:creator>Gem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.gemmapeter.co.uk/?p=185</guid>
		<description><![CDATA[Yesterday I bought myself the latest instalment of the Tomb Raider series for the Wii. I spent a while playing it then I came across got stuck in the Level Puppet No Longer in the last room with the ceiling ring where I couldn&#8217;t progress in the game because the switch to open the door [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I bought myself the latest instalment of the Tomb Raider series for the Wii.</p>
<p>I spent a while playing it then I came across got stuck in the Level Puppet No Longer in the last room with the ceiling ring where I couldn&#8217;t progress in the game because the switch to open the door had vanished  (see forum posts <a href="http://forums.eidosgames.com/showthread.php?t=82944">here</a> and <a href="http://www.tombraiderforums.com/showthread.php?p=3241042">here</a>).</p>
<p>I restarted the game and treked back to that point. This time the switch was there and I was able to complete the level.</p>
<p>Later on in the Mexico level I came across another similar bug. One of the switches needed to operate the giant cogs in the floor was missing, instead only a yellow cuboid floated in mid air where it should have been. Fortunately I had a save at the beginning of the level and when I reloaded and got to that point again the switch was there.</p>
<p>Also later there was a bit by where you stop the Archimedes screw from moving the blue glowing liquid into the pool in the main chamber. The column that you&#8217;re supposed to shoot down, initially it did not allow me to shoot it, I could aim and fire at it but it had no effect and I couldn&#8217;t get the red crosshairs on it as is normally the case with shootable objects.</p>
<p>In conclusion BUGGIEST. TOMB RAIDER. EVAR. I hope I don&#8217;t run into any more.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gemmapeter.co.uk/2008/11/22/tomb-raider-underworld-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
