<?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>Richard Warrender</title>
	<atom:link href="http://richardwarrender.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://richardwarrender.com</link>
	<description>Notes of a Software Developer (iPhone, iPad, Mac OS X &#38; Web)</description>
	<lastBuildDate>Mon, 10 Oct 2011 23:52:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Core Animation stops animation on app relaunch</title>
		<link>http://richardwarrender.com/2011/09/core-animation-stops-ani-on-app-relaunch/</link>
		<comments>http://richardwarrender.com/2011/09/core-animation-stops-ani-on-app-relaunch/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 12:31:44 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Core Animation]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[UIKit]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Core Animaton]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[multitasking]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=385</guid>
		<description><![CDATA[On one of my projects I discovered a bug in a never-ending animation I had set up. Whenever the app was suspended (such as when you multitask and open another app), on relaunching the app the animation was frozen. After some investigating, I discovered that you need to set a flag on the CABasicAnimation called removedOnCompletion [...]]]></description>
			<content:encoded><![CDATA[<p>On one of my projects I discovered a bug in a never-ending animation I had set up. Whenever the app was suspended (such as when you multitask and open another app), on relaunching the app the animation was frozen. After some investigating, I discovered that you need to set a flag on the <strong>CABasicAnimation</strong> called <em>removedOnCompletion</em> to <strong>NO</strong> otherwise the animation will get cleaned up when it gets suspended.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CABasicAnimation <span style="color: #002200;">*</span>dartWiggleAnimation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CABasicAnimation animationWithKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;position&quot;</span><span style="color: #002200;">&#93;</span>;
dartWiggleAnimation.fromValue <span style="color: #002200;">=</span>
   <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCGPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span>self.center.x<span style="color: #002200;">-</span>DART_WIGGLE_HALF, self.center.y<span style="color: #002200;">+</span>DART_CENTER_H_OFFSET<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
dartWiggleAnimation.toValue <span style="color: #002200;">=</span>
   <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCGPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span>self.center.x<span style="color: #002200;">+</span>DART_WIGGLE_HALF, self.center.y<span style="color: #002200;">+</span>DART_CENTER_H_OFFSET<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
dartWiggleAnimation.timingFunction <span style="color: #002200;">=</span>
   <span style="color: #002200;">&#91;</span>CAMediaTimingFunction functionWithName<span style="color: #002200;">:</span> kCAMediaTimingFunctionEaseInEaseOut<span style="color: #002200;">&#93;</span>; 
&nbsp;
dartWiggleAnimation.duration <span style="color: #002200;">=</span> <span style="color: #2400d9;">0.4</span>;
dartWiggleAnimation.repeatCount <span style="color: #002200;">=</span> HUGE_VALF;
dartWiggleAnimation.autoreverses <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
dartWiggleAnimation.removedOnCompletion <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>nextDart layer<span style="color: #002200;">&#93;</span> addAnimation<span style="color: #002200;">:</span>dartWiggleAnimation forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dartWiggle&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Does this seem like a bug or a feature?</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/09/core-animation-stops-ani-on-app-relaunch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reverting your library from a beta of iTunes</title>
		<link>http://richardwarrender.com/2011/09/reverting-itunes-beta-library/</link>
		<comments>http://richardwarrender.com/2011/09/reverting-itunes-beta-library/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 18:58:23 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[troubleshoot]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=377</guid>
		<description><![CDATA[As an iPhone and iPad developer, Apple often present you with beta versions to install which sometimes require you to also install a beta version of iTunes. Of course the contents of these beta versions are under strict non-disclosure agreements but the process of rolling back isn&#8217;t so I&#8217;ll quickly explain how to do it&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>As an iPhone and iPad developer, Apple often present you with beta versions to install which sometimes require you to also install a beta version of iTunes. Of course the contents of these beta versions are under strict non-disclosure agreements but the process of rolling back isn&#8217;t so I&#8217;ll quickly explain how to do it&#8230;</p>
<p>When you installed the beta, it will upgrade your iTunes library database but if you try to downgrade back to the old version at a later date you&#8217;ll be presented with an error message saying that iTunes cannot read your library.</p>
<p>Don&#8217;t panic! The beta version has just moved your library database to a backup folder and with a simple drag and drop you can have your old library database up and running again. Your old database should be found in <em>~/Music/iTunes/Previous iTunes Libraries</em> dated with when you upgraded. Just drag that back into <em>~/Music/iTunes </em>renaming it<em> to iTunes Library.itl (</em>you&#8217;ll probably need to delete the existing<em> iTunes Library.itl </em>file too as that belonged to the beta version and you just uninstalled that).</p>
<p>That&#8217;s all you need to do to get your old iTunes library working again. Just before you begin make sure you back up <strong>everything</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/09/reverting-itunes-beta-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WWDC Update: 5 key points for iPhone apps</title>
		<link>http://richardwarrender.com/2011/07/wwdc-update-5-key-points-for-iphone-apps/</link>
		<comments>http://richardwarrender.com/2011/07/wwdc-update-5-key-points-for-iphone-apps/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 17:22:21 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iCloud]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[gamecenter]]></category>
		<category><![CDATA[icloud]]></category>
		<category><![CDATA[ios5]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[notifications]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=364</guid>
		<description><![CDATA[It’s now been just over 3 weeks since the torrent of information unleashed at Apple’s World Wide Developer Conference refreshingly drenched the brains of designers, developers and engineers. I’ve resisted blogging about the public announcements to fully let the impact soak in and gage everyone’s reactions but now feels like a good time to talk [...]]]></description>
			<content:encoded><![CDATA[<p>It’s now been just over 3 weeks since the torrent of information unleashed at <a href="http://developer.apple.com/wwdc/about/">Apple’s World Wide Developer Conference</a> refreshingly drenched the brains of designers, developers and engineers. I’ve resisted blogging about the public announcements to fully let the impact soak in and gage everyone’s reactions but now feels like a good time to talk about where the future of computing is heading.<br />
<span id="more-364"></span></p>
<p><a href="http://events.apple.com.edgesuite.net/11piubpwiqubf06/event/">The keynote</a> was fantastic and had many interesting details about the upcoming <a href="http://www.apple.com/macosx/">OS X Lion</a> and <a href="http://www.apple.com/ios/ios5/">iOS 5</a> software which I recommend you read about as well as familiarise yourself with <a href="http://www.apple.com/icloud/">iCloud</a> &#8211; Apple’s hot solution to working with multiple devices. iCloud is actually much more than just a document syncing solution. It effectively challenges that old-fashioned idea that your document is a physical file where you move this file from computer-to-computer as you need to work on it. Instead your document is ready when you need it. It doesn’t matter if you’re mid-edit on your iMac at home… if you pop out for a bit and carry on editing the document on your iPhone it’s just there for you, just as you left it on your iMac. The idea is that it’s ready whenever you are and this is a huge but subtle shift in today’s thinking.</p>
<p>So if you ask yourself what needs to change in modern day computing for your document to always be ready, what needs to happen? The answer is it needs to save itself whenever anything significant happens and that is where Lion’s Auto Save comes in! By saving whenever possible you’re also committing changes to the cloud and this enables your document to be easily editable by another device… lets say an iPhone.</p>
<p>Most apps on the iPhone have auto saved in some form or another because originally apps could get closed at any moment by the iPhone itself from an incoming call, a request to free memory, or a user pressing the home button. Starting with iOS5 there are now API methods for letting this all happen automatically. This is great because by using Apple’s classes and methods you also get iCloud support almost for free! There is <a href="https://developer.apple.com/library/prerelease/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iOS5.html">a great overview of iCloud</a> at the Apple Developer Center but as it&#8217;s still under NDA so you&#8217;ll need to log in.</p>
<p>I could write a small book talking about just some of the new technology but I&#8217;m going to reduce it down to just 5 key points I&#8217;ve set myself as a personal aim to focus on in my apps.</p>
<p>Key points to take note of:</p>
<ol>
<li><strong>iCloud</strong> is big. Start integrating now. Every app should support it, even if it’s just remembering a page number, a post code, etc. iMessage is a great example of iCloud support as messages sync between devices.</li>
<li><strong>Twitter integration</strong> is smart, and saves all that OAuth panic and confusion. Integrate into apps whenever the user achieves something they might want to share. You might not use it but if your users do you&#8217;ve just advertised your app to all their followers.</li>
<li><strong>Notifications</strong> have <a href="http://www.apple.com/ios/ios5/features.html#notification">received a revamp with the Notification Center</a> which make them incredibly useful. More apps need to take advantage of these, even if it’s just to badge number in-app news.  Many developers find the need for server setup an extra hassle but it&#8217;s worth it and the <a href="http://www.apple.com/ios/ios5/features.html#newsstand">new Newsstand notifications</a> mean magazine apps can now automatically download new issues in the background &#8211; complete with the latest covers ready for reading on your morning commute.</li>
<li>Now the iPhone and iPad is <strong>PC-free</strong>, apps should focus on supporting all functions not just consuming data but generating it as well like the new calendar app.</li>
<li><strong>GameCenter</strong> &#8211; photos and turn-based multiplayer mean GameCenter takes one step closer to bringing gaming alive and adds another reason to bring users back into your app. The turn-based multiplayer looks like it has potential to be really addictive and should cater for busy lives by breaking game sessions out of an app&#8230; games can now last days if you want them to as you bounce moves back and forth between your friends.</li>
</ol>
<p>&nbsp;</p>
<p>So they are the 5 key points I&#8217;m going to be focusing on in my apps. Feel free to suggest others in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/07/wwdc-update-5-key-points-for-iphone-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The eve of Apple&#8217;s World Wide Developer Conference 2011</title>
		<link>http://richardwarrender.com/2011/06/the-eve-of-apples-world-wide-developer-conference-2011/</link>
		<comments>http://richardwarrender.com/2011/06/the-eve-of-apples-world-wide-developer-conference-2011/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 04:02:23 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[wwdc]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=356</guid>
		<description><![CDATA[I&#8217;m writing this in a hotel room from a block adjacent from the Moscone West Conference center, here in San Francisco, CA. The atmosphere is incredibly lively and for many developers it&#8217;s as close to the developer-version of Christmas you can get. Ha ok I know that sounds a bit over the top but there [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing this in a hotel room from a block adjacent from the Moscone West Conference center, here in San Francisco, CA. The atmosphere is incredibly lively and for many developers it&#8217;s as close to the developer-version of Christmas you can get. Ha ok I know that sounds a bit over the top but there is lots of optimism about Steve Jobs&#8217; keynote tomorrow. You can feel it!</p>
<p><a href="http://richardwarrender.com/wp-content/uploads/2011/06/IMG_0657e.jpg"><img class="alignleft size-medium wp-image-357" title="My WWDC 2011 Attendee Badge" src="http://richardwarrender.com/wp-content/uploads/2011/06/IMG_0657e-224x300.jpg" alt="" width="202" height="270" /></a> So today I picked up my WWDC attendee badge and hitched a ride on the small army of buses that <a href="http://iphonedevelopment.blogspot.com/">Jeff LaMarche</a> had arranged to go to Apple&#8217;s HQ in <a href="http://maps.google.com/maps?hl=en&amp;client=safari&amp;q=1+INFINITE+LOOP&amp;ie=UTF8&amp;hq=&amp;hnear=1+Infinite+Loop,+Cupertino,+California+95014&amp;gl=us&amp;z=16">1 Infinite Loop, Cupertino, CA</a>. It&#8217;s such a historic place in tech history and I was there! Not only has it been the main home of Apple since Steve Jobs returned to Apple but also features on the front of the Google Map icon on every single iPhone, iPad and iPod Touch.</p>
<div id="attachment_359" class="wp-caption alignright" style="width: 160px"><a href="http://richardwarrender.com/wp-content/uploads/2011/06/IMG_0373e.jpg"><img class="size-thumbnail wp-image-359" title="Richard Warrender standing outside 1 Infinite Loop, Cupertino CA." src="http://richardwarrender.com/wp-content/uploads/2011/06/IMG_0373e-150x150.jpg" alt="" width="150" height="150" /></a><p class="wp-caption-text">Me outside Apple HQ</p></div>
<p>I got my photo taken and chilled in the oddly named BJ&#8217;s bar opposite. I also visited the company store there and bought some Apple gear, I just need to work out how to fit the coffee mugs into my suitcase now! Just about to grab some food and chill in a bar with a number of other iPhone developers before getting an early night. Some people recommended getting up at 3am to get a good seat. Mmm, if only I hadn&#8217;t just tested out my new coffee mugs&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/06/the-eve-of-apples-world-wide-developer-conference-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating UNIX file permissions</title>
		<link>http://richardwarrender.com/2011/06/calculating-unix-file-permissions/</link>
		<comments>http://richardwarrender.com/2011/06/calculating-unix-file-permissions/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 00:45:23 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=340</guid>
		<description><![CDATA[A few years ago I wrote a simple but handy Mac app that calculates unix file permissions using a matrix of check boxes. I wrote it because I wanted to better understand how those octal values get calculated and to expand my experience of writing Mac apps. I was also learning some crazy assembly code [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://richardwarrender.com/wp-content/uploads/2011/06/Screen-shot-2011-06-02-at-17.43.44.png" alt="Permissions Mac App" title="Permissions Screenshot" width="429" height="250" class="alignleft size-full" />A few years ago I wrote a simple but handy Mac app that calculates unix file permissions using a matrix of check boxes. I wrote it because I wanted to better understand how those octal values get calculated and to expand my experience of writing Mac apps.</p>
<p>I was also learning some crazy assembly code at the time too so I was also making sense of putting bitwise operations to task. Rather than let this code languish on my hard drive, I thought I’d share&#8230;<br />
<span id="more-340"></span><br />
The main nib file contains a matrix with the the button cells set to a check box style. The whole matrix has an action attached that calls the AppController’s calculatePermission: method. This method is quite simple and I’ve carefully commented it for you so please feel free to check it out. It loops around the matrix and bitwise OR up the checkbox values and then converts this into a C string. I decided to use a C string because the text version of the permissions can only be ASCII values and we might as well be as efficient as possible.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> i,octal <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
<span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>permission<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">8</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#123;</span><span style="color: #bf1d1a;">&quot;___&quot;</span>, <span style="color: #bf1d1a;">&quot;__x&quot;</span>, <span style="color: #bf1d1a;">&quot;_w_&quot;</span>, <span style="color: #bf1d1a;">&quot;_wx&quot;</span>, <span style="color: #bf1d1a;">&quot;r__&quot;</span>, <span style="color: #bf1d1a;">&quot;r_x&quot;</span>, <span style="color: #bf1d1a;">&quot;rw_&quot;</span>, <span style="color: #bf1d1a;">&quot;rwx&quot;</span><span style="color: #002200;">&#125;</span>;
<span style="color: #a61390;">char</span> text<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">11</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;-&quot;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Loop through each row (user) - User, Group, All</span>
<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>i<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; i&lt;<span style="color: #2400d9;">3</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Loop through each column (permission bit) and OR up the results - r=4, w=2, x=1</span>
  <span style="color: #a61390;">int</span> c, row <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
  <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>c <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; c &lt; <span style="color: #2400d9;">3</span>; c<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>        
    <span style="color: #11740a; font-style: italic;">/*
       We get our checkbox toggle bit and left shift to move it along a column.
       Next we do a bitwise OR which allows us to mask it. The result is 1 if the first bit
       is 1 OR the second bit is 1 OR both bits are set to 1. Else, the result is 0
&nbsp;
       e.g. 0 &lt;&lt; 0 = 00000000 = 0
            1 &lt;&lt; 1 = 00000010 = 2
            1 &lt;&lt; 2 = 00000100 = 4
     */</span>
    bool isTicked <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>sender cellAtRow<span style="color: #002200;">:</span>i column<span style="color: #002200;">:</span> c<span style="color: #002200;">&#93;</span> state<span style="color: #002200;">&#93;</span>;
    row |<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>isTicked &lt;&lt; c<span style="color: #002200;">&#41;</span>; 
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Concat this string row to the last. We want a big permissions char array :)</span>
  <span style="color: #a61390;">strcat</span><span style="color: #002200;">&#40;</span>text, permission<span style="color: #002200;">&#91;</span>row<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
  row <span style="color: #002200;">*=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">2</span><span style="color: #002200;">-</span>i<span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// Shift row along into decimal 10's</span>
  octal <span style="color: #002200;">+=</span> row;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>I’ve <a href="https://github.com/rwarrender/Permissions">uploaded Permissions to GitHub</a> in the hope that someone might find it useful when they’re learning Cocoa. If you do find it helpful please post a quick comment. Feedback is always appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/06/calculating-unix-file-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jet-fuelled HTML5 in 3D</title>
		<link>http://richardwarrender.com/2011/05/jet-fuelled-html5-in-3d/</link>
		<comments>http://richardwarrender.com/2011/05/jet-fuelled-html5-in-3d/#comments</comments>
		<pubDate>Tue, 24 May 2011 18:04:40 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=319</guid>
		<description><![CDATA[Using the power of WebGL and some JavaScript Chris Milk, the US music video producer and some smart friends of his at Google have created some impressive visuals that play in real-time within a web browser without needing any plugins. These stunning graphics use the next round of HTML5 features that are sweeping across browsers [...]]]></description>
			<content:encoded><![CDATA[<p>Using the power of WebGL and some JavaScript <a href="http://www.chrismilk.com/">Chris Milk, the US music video producer</a> and some smart friends of his at Google have created <a href="http://www.ro.me/">some impressive visuals</a> that play in real-time within a web browser without needing any plugins. These stunning graphics use the next round of HTML5 features that are sweeping across browsers now.</p>
<p style="text-align: center;"><a href="http://www.ro.me/"><img class="size-large wp-image-322 aligncenter" title="3 Dreams of Black" src="http://richardwarrender.com/wp-content/uploads/2011/05/3-Dreams-of-Black-1024x435.jpg" alt="" width="620" height="264" /></a></p>
<p><span id="more-319"></span></p>
<p>WebGL was originally an experiment started by <a title="Vladimir Vukićević" href="http://en.wikipedia.org/wiki/Vladimir_Vuki%C4%87evi%C4%87">Vladimir Vukićević</a> at Mozilla and has grown to the point where it&#8217;s now ready to take flight and is being added to browsers such as Firefox, Chrome and Safari. It&#8217;s a very rich JavaScript API with DOM support that&#8217;s based on <a href="http://en.wikipedia.org/wiki/OpenGL_ES#OpenGL_ES_2.0">OpenGL ES 2.0</a>, the same API used by modern iPad and iPhones which is great because iPhone developers should feel right at home with shaders and framebuffer objects.</p>
<p>Currently WebGL has been added to Safari nightly builds but it hasn&#8217;t quite hit the main release yet so if you&#8217;d like to explore these demos you&#8217;ll need to fire up <a href="http://www.google.com/chrome">Google Chrome</a>, alternatively check out the video on the <a href="http://www.ro.me/tech/">tech side of the ROME site</a>. I feel the most impressive demos of this technology <a href="http://www.ro.me/tech/normal-mapping">show off lighting of a finely textured surface by way of normal mapping</a>, in this case using a 3D bust and an <a href="http://www.ro.me/tech/metaball-playground">implementation</a> of the <a href="http://en.wikipedia.org/wiki/Marching_cubes">Marching Cubes algorithm</a> to create metaballs.</p>
<p>Already, there are some interesting developments with this technology such as a <a href="http://www.favbrowser.com/webgl-ios-rage-from-id-software/">web version of id Software&#8217;s Rage</a> so it will be interesting to see what developers imagine in the coming months. That&#8217;s quite impressive for a scripting language that has it&#8217;s origins in DHTML!</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/05/jet-fuelled-html5-in-3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Impressive JavaScript PC Emulator</title>
		<link>http://richardwarrender.com/2011/05/impressive-js-pc-emulator/</link>
		<comments>http://richardwarrender.com/2011/05/impressive-js-pc-emulator/#comments</comments>
		<pubDate>Fri, 20 May 2011 08:25:14 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[busybox]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[typed arrays]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=310</guid>
		<description><![CDATA[Fabrice Bellard has written an impressive PC emulator that actually emulates a PC with a 32 bit x86 compatible CPU. This is some really imaginative use of pure JavaScript which I&#8217;m sure no-one would have every dreamed of as it allows you to run a virtual instance of Linux inside a browser window! It currently [...]]]></description>
			<content:encoded><![CDATA[<p>Fabrice Bellard has written an <a title="Impressive Javascript PC Emulator" href="http://bellard.org/jslinux/index.html">impressive PC emulator</a> that actually emulates a PC with a 32 bit x86 compatible CPU. This is some really imaginative use of pure JavaScript which I&#8217;m sure no-one would have every dreamed of as it allows you to run a virtual instance of Linux inside a browser window!</p>
<p>It currently only works in <a href="http://www.google.com/chrome/">Google Chrome 11</a> or <a href="http://www.mozilla.com/firefox/">Firefox 4</a> as it uses part of the <a title="Typed Arrays" href="http://www.khronos.org/registry/typedarray/specs/latest/">WebGL HTML5 spec</a> that Safari hasn&#8217;t implemented yet but is definitely worth playing around with. You can even compile C files!</p>
<p style="text-align: center;"><a href="http://bellard.org/jslinux/index.html"><img class="size-medium wp-image-314 aligncenter" title="LinuxJS in Action" src="http://richardwarrender.com/wp-content/uploads/2011/05/linuxjs-in-action.png" alt="" width="640" height="495" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/05/impressive-js-pc-emulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Export Symphony CMS Blueprint metadata</title>
		<link>http://richardwarrender.com/2011/03/symphony-blueprint-metadata/</link>
		<comments>http://richardwarrender.com/2011/03/symphony-blueprint-metadata/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 19:16:42 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sections]]></category>
		<category><![CDATA[symphony]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=298</guid>
		<description><![CDATA[Symphony is a powerful CMS system that is used by many of the world&#8217;s most recognisable brands. It&#8217;s a great system that lets the developer focus on XHTML and data they are creating rather than much of the back-end code. It does have it&#8217;s flaws though and one of them is that it&#8217;s very easy [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://symphony-cms.com/">Symphony</a> is a powerful CMS system that is used by many of the world&#8217;s most recognisable brands. It&#8217;s a great system that lets the developer focus on XHTML and data they are creating rather than much of the back-end code. It does have it&#8217;s flaws though and one of them is that it&#8217;s very easy for Symphony &#8216;sections&#8217; and &#8216;pages&#8217; to get out of sync between production and staging servers.</p>
<p>Sure, the pages themselves can be version-controlled but much of the metadata about the pages such as which datasources are attached are stored in the database and previously this data was only really accessible by clicking on each page within Symphony individually. Now this is fine if you have just a couple of pages but on some of the sites I&#8217;ve worked on this involved 50 pages or more with almost as many sections&#8230;</p>
<p>My solution was to create a Symphony extension called Blueprint Metadata that pulled this metadata out of the database and export it as an XML file conveniently time-stamped containing the server hostname. This allows you to quickly &#8216;diff&#8217; the changes between two servers and quickly see the differences so you can apply them manually. I wrote this extension quite a few years ago but still find myself using this even today and have decided to make it open source under a very flexible BSD license.</p>
<p>Feel free to grab the <a href="https://github.com/rwarrender/blueprint_metadata">Blueprint Metadata extension</a> on Github now.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/03/symphony-blueprint-metadata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Email yourself a log file</title>
		<link>http://richardwarrender.com/2011/01/email-yourself-a-log-file/</link>
		<comments>http://richardwarrender.com/2011/01/email-yourself-a-log-file/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 23:33:06 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=283</guid>
		<description><![CDATA[If you ever find yourself deep within the console of a remote Unix/Linux server, locked down by a thousand firewalls and in quick need of saving a log file for later analysis then your best friend could be the mail command! Just type the following, replacing me@example.com with your email address, naturally cat secret.log &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever find yourself deep within the console of a remote Unix/Linux server, locked down by a thousand firewalls and in quick need of saving a log file for later analysis then your best friend could be the mail command! Just type the following, replacing me@example.com with your email address, naturally <img src='http://richardwarrender.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> secret.log <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Secret API Log File&quot;</span> me<span style="color: #000000; font-weight: bold;">@</span>example.com</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2011/01/email-yourself-a-log-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pub Darts now with Facebook Support</title>
		<link>http://richardwarrender.com/2010/11/pub-darts-now-with-facebook/</link>
		<comments>http://richardwarrender.com/2010/11/pub-darts-now-with-facebook/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 22:01:32 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[app store]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[boss mode]]></category>
		<category><![CDATA[bug fix]]></category>
		<category><![CDATA[dartboard]]></category>
		<category><![CDATA[darts]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[iOS 4]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[pub darts]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=254</guid>
		<description><![CDATA[Hey, just to let you know Pub Darts 1.2 is now up in the App Store. The biggest feature this new version supports is Facebook integration. Yes thats right&#8230; you can now log in and pull a &#8220;friend&#8217;s&#8221; profile picture straight onto the dartboard ready to let off some steam. Mmm, now if only you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://richardwarrender.com/wp-content/uploads/2010/11/Throw-darts-at-someone.png"><img src="http://richardwarrender.com/wp-content/uploads/2010/11/Throw-darts-at-someone-200x300.png" alt="Richard Warrender&#039;s photo in Pub Darts" title="Richard Warrender&#039;s photo in Pub Darts" width="200" height="300" class="alignright size-medium wp-image-259" /></a>Hey, just to let you know <a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8">Pub Darts</a> 1.2 is now up in the App Store.</p>
<p>The biggest feature this new version supports is Facebook integration. Yes thats right&#8230; you can now log in and pull a &#8220;friend&#8217;s&#8221; profile picture straight onto the dartboard ready to let off some steam. Mmm, now if only you could download and try it out for free&#8230; wait you can because I made it free for a short while!<br />
Here&#8217;s the <a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8">link for Pub Darts</a>. </p>
<p>So what else is in this free update?<br />
Well I&#8217;ll tell you. This is what some people have been begging me for&#8230;</p>
<ul>
<li>Ability to refresh dartboard<br />
(You can now remove the tiny dart holes)</li>
<li>Dart sound effects<br />
(Satisfying thuds as a dart hits the board &#8211; woop!)</li>
<li>Bug fixes related to using camera and albums<br />
(Needed fixing particularly for large images)</li>
</ul>
<p>Just in case you can&#8217;t find it, to access Facebook navigate to&#8230;<br />
Settings > Boss Image > Camera > Grab From Facebook</p>
<p>Let me know what you&#8217;d like to see in the next update. Either in the comments or an email. Of course, you could always leave <a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8">a really positive review</a> if you enjoy it <img src='http://richardwarrender.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/11/pub-darts-now-with-facebook/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Core Data Objects in Wrong Sections</title>
		<link>http://richardwarrender.com/2010/10/core-data-objects-in-wrong-sections/</link>
		<comments>http://richardwarrender.com/2010/10/core-data-objects-in-wrong-sections/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 17:55:49 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Core Data]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iOS 4]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[key-paths]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=213</guid>
		<description><![CDATA[NSFetchedResultsController is a really handy class. Use one of the default Core Data templates in Xcode and you&#8217;ll very quickly have a nice list of managed objects in a table view. With a few more lines of code you can get the NSFetchedResultsController to group your objects by sections. You do this by specifying a key-path [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html" target="_blank">NSFetchedResultsController</a> is a really handy class. Use one of the default Core Data templates in Xcode and you&#8217;ll very quickly have a nice list of managed objects in a table view. With a few more lines of code you can get the NSFetchedResultsController to group your objects by sections. You do this by specifying a key-path in the class&#8217;s constructor method but there is another step that if overlooked will cause some confusion.</p>
<p>In a sample app I&#8217;ve created a food table that lists food in categories.</p>
<p>FetchedResultsController method grouping sections using a key-path:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSFetchedResultsController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>fetchedResultsController <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>fetchedResultsController <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">return</span> fetchedResultsController;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Create and configure a fetch request with the food entity.</span>
	<span style="color: #400080;">NSFetchRequest</span> <span style="color: #002200;">*</span>fetchRequest <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSFetchRequest</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSEntityDescription</span> <span style="color: #002200;">*</span>entity <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSEntityDescription</span> entityForName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;RWFood&quot;</span> inManagedObjectContext<span style="color: #002200;">:</span>managedObjectContext<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>fetchRequest setEntity<span style="color: #002200;">:</span>entity<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Create the sort descriptors array.</span>
	<span style="color: #400080;">NSSortDescriptor</span> <span style="color: #002200;">*</span>nameDescriptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSSortDescriptor</span> alloc<span style="color: #002200;">&#93;</span> initWithKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;name&quot;</span> ascending<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>sortDescriptors <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span>nameDescriptor, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>fetchRequest setSortDescriptors<span style="color: #002200;">:</span>sortDescriptors<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Create and initialize the fetch results controller.</span>
	NSFetchedResultsController <span style="color: #002200;">*</span>aFetchedResultsController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>NSFetchedResultsController alloc<span style="color: #002200;">&#93;</span> initWithFetchRequest<span style="color: #002200;">:</span>fetchRequest managedObjectContext<span style="color: #002200;">:</span>managedObjectContext sectionNameKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;category&quot;</span> cacheName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Food&quot;</span><span style="color: #002200;">&#93;</span>;
	self.fetchedResultsController <span style="color: #002200;">=</span> aFetchedResultsController;
	fetchedResultsController.delegate <span style="color: #002200;">=</span> self;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Memory management.</span>
	<span style="color: #002200;">&#91;</span>aFetchedResultsController release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>fetchRequest release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>nameDescriptor release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sortDescriptors release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> fetchedResultsController;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><a href="http://richardwarrender.com/wp-content/uploads/2010/10/food-in-wrong-order.png"><img class="alignleft size-thumbnail wp-image-226" title="Oranges are not a vegetable!" src="http://richardwarrender.com/wp-content/uploads/2010/10/food-in-wrong-order-150x150.png" alt="Screenshot of Food sample app in wrong order." width="150" height="150" /></a>Save and quit the app a few times and you&#8217;ll see the objects seem to be in the wrong sections. If you look closer you&#8217;ll see that the objects are actually sorted in ascending name order. On looking at the code, it seems this is exactly what we asked the program to do! After some testing it also seems to show up more often if the table is a grouped one.</p>
<p>As per the <a href="http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html" target="_blank">docs</a>, after you specify a key-path to group each section with you also need to make sure the first sort descriptor is sorting this key-path. Add a sort descriptor and everything will work as expected.</p>
<p>Revised fetchedResultsController method with missing sort descriptor:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSFetchedResultsController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>fetchedResultsController <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>fetchedResultsController <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">return</span> fetchedResultsController;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Create and configure a fetch request with the plant entity.</span>
	<span style="color: #400080;">NSFetchRequest</span> <span style="color: #002200;">*</span>fetchRequest <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSFetchRequest</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSEntityDescription</span> <span style="color: #002200;">*</span>entity <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSEntityDescription</span> entityForName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;RWPlant&quot;</span> inManagedObjectContext<span style="color: #002200;">:</span>managedObjectContext<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>fetchRequest setEntity<span style="color: #002200;">:</span>entity<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Create the sort descriptors array.</span>
        <span style="color: #400080;">NSSortDescriptor</span> <span style="color: #002200;">*</span>typeDescriptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSSortDescriptor</span> alloc<span style="color: #002200;">&#93;</span> initWithKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;type&quot;</span> ascending<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSSortDescriptor</span> <span style="color: #002200;">*</span>nameDescriptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSSortDescriptor</span> alloc<span style="color: #002200;">&#93;</span> initWithKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;name&quot;</span> ascending<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>sortDescriptors <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span>typeDescriptor, nameDescriptor, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>fetchRequest setSortDescriptors<span style="color: #002200;">:</span>sortDescriptors<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Create and initialize the fetch results controller.</span>
	NSFetchedResultsController <span style="color: #002200;">*</span>aFetchedResultsController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>NSFetchedResultsController alloc<span style="color: #002200;">&#93;</span> initWithFetchRequest<span style="color: #002200;">:</span>fetchRequest managedObjectContext<span style="color: #002200;">:</span>managedObjectContext sectionNameKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;type&quot;</span> cacheName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Plants&quot;</span><span style="color: #002200;">&#93;</span>;
	self.fetchedResultsController <span style="color: #002200;">=</span> aFetchedResultsController;
	fetchedResultsController.delegate <span style="color: #002200;">=</span> self;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Memory management.</span>
	<span style="color: #002200;">&#91;</span>aFetchedResultsController release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>fetchRequest release<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>categoryDescriptor release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>nameDescriptor release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sortDescriptors release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> fetchedResultsController;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/10/core-data-objects-in-wrong-sections/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Quick Spreadsheet to plist Technique</title>
		<link>http://richardwarrender.com/2010/09/spreadsheet-to-plist/</link>
		<comments>http://richardwarrender.com/2010/09/spreadsheet-to-plist/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 18:14:50 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Core Data]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plist]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=187</guid>
		<description><![CDATA[Imagine you have a huge list of names in a spreadsheet and you&#8217;d like to get this data into an Apple plist file to use in your iPhone/Mac app or import into a Core Data model. Such a long list of data would take forever to cut and paste so here is a really quick [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine you have a huge list of names in a spreadsheet and you&#8217;d like to get this data into an Apple plist file to use in your iPhone/Mac app or import into a Core Data model. Such a long list of data would take forever to cut and paste so here is a really quick way to build that plist.</p>
<p><span id="more-187"></span></p>
<p>First, export your spreadsheet as a .csv file. Use Unicode UTF8 encoding if possible. Lets say I saved this file as <strong>StudentNames.csv</strong> in my Documents folder.</p>
<p>Next, create a new .php file and paste in the following code. I called mine <strong>student-exporter.php</strong> and placed it in my Documents folder also.</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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;(<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;StudentNames.csv&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgetcsv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</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: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now open the Terminal app on your Mac and type the following into the console:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Documents
php <span style="color: #660033;">-f</span> student-exporter.php <span style="color: #000000; font-weight: bold;">&gt;</span> Students.plist</pre></div></div>

<p>This should create a Students.plist file that will open in Xcode. However this is using the <a title="Wikipedia page on NextSTEP property list format." href="http://en.wikipedia.org/wiki/Property_list#NeXTSTEP">old NextSTEP text plist format</a> which was deprecated when Mac OS X 10.0 came out. To convert into the more compact binary format, type the following into the console:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">plutil <span style="color: #660033;">-convert</span> binary1 Students.plist</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/09/spreadsheet-to-plist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get emailed when uploads complete</title>
		<link>http://richardwarrender.com/2010/09/get-mailed-when-uploads-complete/</link>
		<comments>http://richardwarrender.com/2010/09/get-mailed-when-uploads-complete/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 18:51:37 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=170</guid>
		<description><![CDATA[Sometimes I have to send a client a really large file or app that&#8217;s too large to post to Basecamp. The solution is to upload to a web server over night and email the client a link when it&#8217;s done. Not wanting to tie my laptop down overnight here is a great solution that emails [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I have to send a client a really large file or app that&#8217;s too large to post to <a href="http://basecamphq.com/">Basecamp</a>. The solution is to upload to a web server over night and email the client a link when it&#8217;s done. Not wanting to tie my laptop down overnight here is a great solution that emails you when it&#8217;s done.</p>
<p>Lets say your file is called NinjaApp-1.0.ipa and you use SSH/SFTP on your server to copy everything&#8230;<br />
1. Drop your file onto a spare Mac or server.<br />
2. Type the following into a terminal window:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> NinjaApp-<span style="color: #000000;">1.0</span>.ipa user<span style="color: #000000; font-weight: bold;">@</span>webserver.com:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>.
<span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Upload done&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Upload Complete&quot;</span> me<span style="color: #000000; font-weight: bold;">@</span>example.com</pre></div></div>

<p>That&#8217;s it! You&#8217;ll get an email when it&#8217;s done.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/09/get-mailed-when-uploads-complete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom fonts on iPad and iPhone</title>
		<link>http://richardwarrender.com/2010/08/custom-fonts-on-ipad-and-iphone/</link>
		<comments>http://richardwarrender.com/2010/08/custom-fonts-on-ipad-and-iphone/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 20:48:54 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[UIKit]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[iOS 4]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[uikit]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=147</guid>
		<description><![CDATA[Just incase you didn&#8217;t realise, with iOS 3.2 (iPad) and above you can load in custom fonts and use them with a standard UIFont object. There are a few catches&#8230; The font must be in the following format: - OpenType Format (OTF) TrueType Format (TTF) Once you&#8217;ve dragged your chosen font file into an Xcode project, [...]]]></description>
			<content:encoded><![CDATA[<p>Just incase you didn&#8217;t realise, with iOS 3.2 (iPad) and above you can load in custom fonts and use them with a standard UIFont object. There are a few catches&#8230; The font must be in the following format: -</p>
<ul>
<li>OpenType Format (<a href="http://en.wikipedia.org/wiki/OpenType">OTF</a>)</li>
<li>TrueType Format (<a href="http://en.wikipedia.org/wiki/TrueType">TTF</a>)</li>
</ul>
<p>Once you&#8217;ve dragged your chosen font file into an Xcode project, the next step is to add a line into the application&#8217;s <strong>Info.plist</strong> file. Add a new key <strong>UIAppFonts</strong> and make it an array. Expand the array and add a new string for each font, making the string the file&#8217;s full name including an extension.</p>
<p style="text-align: center;"><img class="size-full wp-image-148 aligncenter" title="Example of UIAppFonts in the Info.plist of an iPhone project" src="http://richardwarrender.com/wp-content/uploads/2010/08/Screen-shot-2010-08-18-at-21.11.54.png" alt="Xcode Screenshot" width="373" height="99" /></p>
<p>You&#8217;re all set up now to use the font. That would be great if you knew which font it was! Here is a great little snippet for looping through all the fonts loaded into the system. Scan through the list and find your font.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Get all the fonts on the system</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>familyNames <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont familyNames<span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>familyName <span style="color: #a61390;">in</span> familyNames <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;Family: %s <span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span>familyName UTF8String<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span>;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>fontNames <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont fontNamesForFamilyName<span style="color: #002200;">:</span>familyName<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fontName <span style="color: #a61390;">in</span> fontNames <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;<span style="color: #2400d9;">\t</span>Font: %s <span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span>fontName UTF8String<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>To use your font now, just use the standard UIFont constructor&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.titleLabel.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Inkpen Medium&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">31.0</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Some points to note: -</p>
<ul>
<li>You can also use the font inside UIWebViews.</li>
<li>Interface Builder for XCode 3.2 has a bug that won&#8217;t let you choose the font. You have to do it in code.</li>
<li>Loading in too many fonts will slow your loading time down and will hurt your users&#8217; eyes.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/08/custom-fonts-on-ipad-and-iphone/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Re-ordering Core Data Objects on iOS4</title>
		<link>http://richardwarrender.com/2010/08/re-ordering-core-data-objects-on-ios4/</link>
		<comments>http://richardwarrender.com/2010/08/re-ordering-core-data-objects-on-ios4/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 06:59:00 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Core Data]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iOS 4]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=139</guid>
		<description><![CDATA[The Core Data framework on the iPhone is incredibly powerful. It&#8217;s also incredibly efficient and part of that is because a collection of objects only have the order that you implicitly give them. For example you typically might give an Event object a timestamp and when you pull out all the events you might sort [...]]]></description>
			<content:encoded><![CDATA[<p>The Core Data framework on the iPhone is incredibly powerful. It&#8217;s also incredibly efficient and part of that is because a collection of objects only have the order that you implicitly give them. For example you typically might give an Event object a timestamp and when you pull out all the events you might sort on that timestamp.</p>
<p>The NSFetchedResultsController is the main power house when dealing with such a scenario and is great for the master part of a master/detail data relationship. It&#8217;s main purpose is to manage the results returned from a fetch request similar to the above and provide data for a UITableView via delegate methods. It reacts on the model level so if you delete an Event object, the NSFetchedResultsController informs it&#8217;s delegate and so updates the UITableView automatically. It&#8217;s very clever indeed!</p>
<p>As I found out earlier yesterday, the problem comes when you want to re-order the objects in a user-defined way. Instead of sorting on a timestamp, I wanted the user to be able to specify that one object should occur before the other&#8230; I&#8217;m working on an app that lets you place waypoints down on a map. Timestamps in waypoints aren&#8217;t much use. It&#8217;s much more critical that they have a specific order.</p>
<p>After some Googling I came across a useful article on <a href="http://www.cimgf.com/2010/06/05/re-ordering-nsfetchedresultscontroller/">CocoaIsMyGirlfriend</a>. This helped me 90% of the way but I had problems when re-ordering. When you re-order the objects, the UITableView would move cells about seemingly at random. This is because NSFetchedResultsController is <strong>model-driven</strong>. When you re-order something using the tableview methods the view is already correct (because you’ve dragged and dropped the cell there - <strong>it&#8217;s a user-driven change</strong>) and so when the delegate detects your index changes, it walks all over your view believing the cells to be in their original position. The trick is to ‘disable’ the UI updates with a boolean in your delegate methods. Set the boolean just before your re-indexing and unset it afterwards.</p>
<p>For an example, see this <a href="http://stackoverflow.com/questions/1077568/how-to-implement-re-ordering-of-coredata-records">stack overflow link on re-ordering</a>.</p>
<p>Also have a look at what the Apple docs say on <a href="http://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40008228-CH1-SW14">user-driven updates</a> on the NSFetchedResultsController.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/08/re-ordering-core-data-objects-on-ios4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pub Darts now with Instructions!</title>
		<link>http://richardwarrender.com/2010/07/pub-darts-now-with-instructions/</link>
		<comments>http://richardwarrender.com/2010/07/pub-darts-now-with-instructions/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 20:35:25 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[app store]]></category>
		<category><![CDATA[bug fix]]></category>
		<category><![CDATA[casual]]></category>
		<category><![CDATA[darts]]></category>
		<category><![CDATA[icon]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[ios4]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone 4]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[pub]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=119</guid>
		<description><![CDATA[When I first launched Pub Darts last March, I got many great positive messages from people who love throwing darts at their boss’s picture! I also got much negative feedback from people who found the throwing mechanism difficult or not as intuitive as I thought it was. Therefore adding instructions to version 1.1 was very [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://itunes.apple.com/gb/app/pub-darts/id308909274?mt=8"></a><a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8"><img class="alignleft size-thumbnail wp-image-131" style="border: 0px;" title="Pub Darts icon" src="http://richardwarrender.com/wp-content/uploads/2010/08/Screen-shot-2010-08-14-at-21.30.161-150x150.png" alt="Pub Darts icon" width="150" height="150" /></a>When I first <a href="http://richardwarrender.com/2009/03/iphone-app-throw-darts-at-your-boss/">launched Pub Darts last March</a>, I got many great positive messages from people who love throwing darts at their boss’s picture! I also got much negative feedback from people who found the throwing mechanism difficult or not as intuitive as I thought it was. Therefore adding instructions to version 1.1 was very important to avoiding those 1 star reviews!</p>
<p>However due to work commitments it has had to sit on the back-burner but with the recent release of the iPhone 4, I couldn’t help but update Pub Darts with gorgeous high resolution artwork. I also managed to add in some instructions, make a new icon, fix a few bugs, allow games to save themselves when you quit and completely redo the shadows to be more ‘iPhone-like’. This free update can be grabbed immediately from your iPhone by updating in the App Store application.</p>
<p>More updates are coming soon. Feel free to suggest some features you’d like to see. If you’ve yet to experience Pub Darts on your iPhone, <a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8">grab it for free now</a>.</p>
<p><img class="size-medium wp-image-123 alignnone" title="Instructions showing finger control in Pub Darts" src="http://richardwarrender.com/wp-content/uploads/2010/08/pubdarts-instructions1-320x480-200x300.png" alt="Pub Darts Screenshot" width="200" height="300" /> <img class="size-medium wp-image-124 alignnone" title="Instructions showing score area in Pub Darts" src="http://richardwarrender.com/wp-content/uploads/2010/08/pubdarts-instructions2-320x480-200x300.png" alt="Pub Darts Screenshot" width="200" height="300" /></p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/07/pub-darts-now-with-instructions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Take Audi iPad Magazine for a Drive</title>
		<link>http://richardwarrender.com/2010/07/take-audi-ipad-magazine-for-a-drive/</link>
		<comments>http://richardwarrender.com/2010/07/take-audi-ipad-magazine-for-a-drive/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 18:53:34 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[app store]]></category>
		<category><![CDATA[audi]]></category>
		<category><![CDATA[audi magazine]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[portable pixels]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/blog/?p=5</guid>
		<description><![CDATA[It&#8217;s such a good feeling when something you&#8217;ve worked so hard on gets unleashed onto the App Store. It&#8217;s even more of a great feeling when you find out your app has already broken into the Top 50 chart of most-downloaded free apps. Achieving more than 15,000 downloads in the first two weeks, I&#8217;m immensely [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s such a good feeling when something you&#8217;ve worked so hard on gets unleashed onto the App Store. It&#8217;s even more of a great feeling when you find out your app has already broken into the Top 50 chart of most-downloaded free apps. Achieving more than <a title="Audi Press release" href="http://www.audi.co.uk/about-audi/latest-news/audi-magazine-turns-new-page-with-groundbreaking-ipad-app.html">15,000 downloads in the first two weeks</a>, I&#8217;m immensely proud to have been the lead developer of<a href="http://itunes.apple.com/gb/app/audi-magazine/id379915828?mt=8" target="_blank"> Audi Magazine for iPad</a>. Download it for free now!</p>
<p><object type="application/x-shockwave-flash" style="width:645px; height:387px;" data="http://www.youtube.com/v/oajwblJo_sQ?fs=1"><param name="movie" value="http://www.youtube.com/v/oajwblJo_sQ?fs=1" /><param name="allowFullScreen" value="true" /></object></p>
<p>As a team, we spent considerable time making sure the rotating mechanism worked just right and making sure the app loads in less than half a second. I&#8217;m looking forward to starting on the next issue soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2010/07/take-audi-ipad-magazine-for-a-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone App: Throw Darts at your Boss</title>
		<link>http://richardwarrender.com/2009/03/iphone-app-throw-darts-at-your-boss/</link>
		<comments>http://richardwarrender.com/2009/03/iphone-app-throw-darts-at-your-boss/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 17:50:09 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[app store]]></category>
		<category><![CDATA[beer]]></category>
		<category><![CDATA[boss mode]]></category>
		<category><![CDATA[casual]]></category>
		<category><![CDATA[dartboard]]></category>
		<category><![CDATA[darts]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[pub]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=55</guid>
		<description><![CDATA[Hooray. My iPhone game, Pub Darts is in the App Store. It&#8217;s a slick dartboard game with the added bonus of being able snap your boss/greedy banker and throw darts at their image. Just don&#8217;t let them catch you Buy it now for only £1.19 ($1.99). For a short time only it&#8217;s now completely free! Grab [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-58 alignright" title="Pub Darts with darts thrown at a photo" src="http://richardwarrender.com/wp-content/uploads/2010/08/mzl.yoohbhdn.320x480-75-200x300.jpg" alt="Pub Darts screenshot" width="200" height="300" /> <img class="size-medium wp-image-57 alignright" title="Pub Darts winning screen" src="http://richardwarrender.com/wp-content/uploads/2010/08/mzl.kofebihx.320x480-75-200x300.jpg" alt="Pub Darts screenshot" width="200" height="300" />Hooray. My iPhone game, Pub Darts is in the <a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8">App Store</a>. It&#8217;s a slick dartboard game with the added bonus of being able snap your boss/greedy banker and throw darts at their image. Just don&#8217;t let them catch you <img src='http://richardwarrender.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span style="text-decoration: line-through;"><a href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8">Buy it now</a> for only £1.19 ($1.99)</span>. For a short time only it&#8217;s now completely free! <a title="Pub Darts for iPhone" href="http://itunes.apple.com/app/pub-darts/id308909274?mt=8" target="_blank">Grab it now</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2009/03/iphone-app-throw-darts-at-your-boss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Xdebug on Mac OS X</title>
		<link>http://richardwarrender.com/2008/02/installing-xdebug-on-mac-os-x/</link>
		<comments>http://richardwarrender.com/2008/02/installing-xdebug-on-mac-os-x/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 18:16:25 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=32</guid>
		<description><![CDATA[Xdebug is an incredibly powerful PHP extension that helps you debug scripts by providing a lot of valuable debugging information. It saves you from having to write your own debugging function for catching errors, at least during the development stage of a web application and certainly provides a lot more information than the standard PHP [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://xdebug.org/" target="_blank">Xdebug</a> is an incredibly powerful PHP extension that helps you debug scripts by providing a lot of valuable debugging information. It saves you from having to write your own debugging function for catching errors, at least during the development stage of a web application and certainly provides a lot more information than the standard PHP error messages!</p>
<p>Xdebug also provides the following: -</p>
<ul>
<li>Stack traces and function traces in error messages with:
<ul>
<li>Full parameter display for user defined functions</li>
<li>Function name, file name and line indications</li>
</ul>
</li>
<li>Support for member functions</li>
<li>Memory allocation</li>
<li>Protection for infinite recursions</li>
<li>Profiling information for PHP scripts</li>
<li>Code coverage analysis</li>
<li>Capabilities to debug your scripts interactively with a debug client</li>
</ul>
<p>From the above you can see it&#8217;s a very powerful tool that every web developer should have installed on his or her machine and is in-fact included with quite a few commercial IDE programs. Surprisingly, <a href="http://xdebug.org/" target="_blank">Xdebug</a> is actually open-source, so without further ado&#8230; I&#8217;ll show you how you can easily install it on your Apple Mac using <a href="http://code.activestate.com/komodo/remotedebugging/" target="_blank">pre-built binaries</a>&#8230;</p>
<h2>Equipment</h2>
<p>This tutorial assumes you have the following already set up: -</p>
<ul>
<li>Apple Mac OS 10.4</li>
<li>Apache (Using Apple&#8217;s version that came with OS X)</li>
<li>PHP 5 Module (I use PHP 5 from <a href="http://www.entropy.ch/" target="_blank">www.entropy.ch</a>)</li>
<li>Some PHP files you can test and debug with</li>
</ul>
<h2>Instructions</h2>
<p>Xdebug doesn&#8217;t provide any pre-built binaries for Mac OS X, which means we would have to download the source code and compile Xdebug ourselves. Luckily a commercial IDE called <a href="http://www.activestate.com/komodo-ide" target="_blank">Komodo IDE</a> (made by ActiveState who you might remember as the company that makes Perl for Windows), distributes Xdebug with their program and have kindly made their Xdebug binaries available for download. Navigate to the <a href="http://code.activestate.com/komodo/remotedebugging/" target="_blank">remote debugging page</a> on their website and click on the PHP Remote Debugging option. Make sure you choose Mac OS X / x86 if you have an Intel Mac.<br />
Once downloaded, extract the contents and click on the folder corresponding to your PHP version (I chose 5.2). You should see a single file called xdebug.so. This is our PHP extension&#8230; drag it into your user folder.</p>
<p>Now we need to copy the extension into our PHP extensions folder. Drop into the Terminal application and if you used the Entropy PHP 5 extension, you&#8217;ll find the PHP folder at /usr/local/php5. The extensions folder is in lib/php/extensions.</p>
<p>At the terminal type:</p>
<pre>cd /usr/local/php5/lib/php/extensions</pre>
<p>List the contents and you should see a folder called no-debug-non-zts-20060613 or similar, change directory into here. We&#8217;ll now move the xdebug.so file into this folder and rename it xdebug. Note: You&#8217;ll get prompted for your password since we&#8217;re editing system files.</p>
<pre>ls
cd no-debug-non-zts-20060613
sudo mv ~/xdebug.so xdebug</pre>
<p>Nearly there, we now need to create an .ini file to tell PHP to load in the extension. Change directory to /usr/local/php5/php.d and using vi or your favourite editor create a file called <em>80-extension-xdebug.ini</em>. Note: You&#8217;ll get prompted for your password since we&#8217;re editing system files.</p>
<pre>cd /usr/local/php5/php.d
sudo vi 80-extension-xdebug.ini</pre>
<p>Copy and paste the following into the text file you&#8217;ve just created, adjusting the path to where your extensions directory is located.</p>
<pre>[xdebug]
zend_extension="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug"</pre>
<p>If you have <a href="http://macromates.com/" target="_blank">TextMate</a>, you can add the following line to the config file. This makes clickable error messages that load up the offending PHP file in <a href="http://macromates.com/" target="_blank">TextMate</a> and jump to the line containing the error. This is very handy indeed!</p>
<pre>xdebug.file_link_format = "txmt://open?url=file://%f&amp;line=%l"</pre>
<p>Once your ready to save the config file, close vi by typing &#8216;:x&#8217; followed by the return key. Restart Apache using your favourite method or simply reboot the whole machine.<br />
Test your new Xdebug configuration by creating a PHP file, which obviously has an error in it such as calling a function that doesn&#8217;t exist. Test the PHP file and you should see a lovely coloured error message with a stack trace! You&#8217;re all ready to go!</p>
<h2>Extras</h2>
<p>If you&#8217;re interested in getting the most out of Xdebug, I recommend checking out some of the <a href="http://xdebug.org/docs/" target="_blank">documentation</a> on the Xdebug site. Of particular interest is using the <a href="http://xdebug.org/docs/profiler" target="_blank">profiler</a> and the <a href="http://xdebug.org/docs/basic" target="_blank">basics</a>, which are always good to master.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2008/02/installing-xdebug-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Problem with PHP mail() and Additional Headers</title>
		<link>http://richardwarrender.com/2007/09/problem-with-php-mail-and-additional-headers/</link>
		<comments>http://richardwarrender.com/2007/09/problem-with-php-mail-and-additional-headers/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 19:47:48 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[email headers]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=48</guid>
		<description><![CDATA[With the PHP mail() function, you can specify additional headers for the emails that you send. This is a very powerful feature, which lets you do things such as add addresses to blind carbon copy or specify which email address the email is coming from. It’s great but the PHP manual says this about additional [...]]]></description>
			<content:encoded><![CDATA[<p>With the PHP mail() function, you can specify additional headers for the emails that you send. This is a very powerful feature, which lets you do things such as add addresses to blind carbon copy or specify which email address the email is coming from.</p>
<p>It’s great but the PHP manual says this about additional headers: –</p>
<p><em><strong>additional_headers (optional)</strong></em></p>
<p><em> </em></p>
<p><em>String to be inserted at the end of the email header.</em></p>
<p><em>This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).</em></p>
<p>Yes, so according to the manual multiple headers should be separated with CRLF (\r\n). However, if you try this on a Linux web server (sample code provided below) you will probably get some of your headers stuck in the body of the email! There is a quick and easy solution though&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Recipient</span>
<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'dave@test.com'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Subject of email</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Message from Eddie'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Message body</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hi there, this is Eddie, and I\'m feeling just
great, guys, and I know I\'m just going to get a bundle of kicks out of any
programme you care to run through me'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Additional headers</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'To: dave@test.com'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'From: eddie@theheartofgold.com'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Mail it</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Email sent'</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;">echo</span> <span style="color: #0000ff;">'Email not sent'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Apparently on Linux web servers, it’s best to use LF (\n) line endings for separating headers instead. This can be done two ways. The first way is to alter the server’s sendmail path in PHP.ini file to first push the email through dos2unix (which converts the line endings automatically) and then pipe it to send mail.</p>
<pre>sendmail_path = "/usr/bin/dos2unix | /usr/sbin/sendmail -t -i"</pre>
<p>The other option is to alter your PHP code so that instead of appending the line endings on as strings use the PHP_EOL constant which was introduced in PHP 5.0.2. Echoing PHP_EOL on a Windows server will result in “\r\n” whilst echoing the constant on a Linux server will result in “\n”&#8230; which in my opinion is a more elegant solution. <img src='http://richardwarrender.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2007/09/problem-with-php-mail-and-additional-headers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Secret to cURL in PHP on Windows&#8230;</title>
		<link>http://richardwarrender.com/2007/05/the-secret-to-curl-in-php-on-windows/</link>
		<comments>http://richardwarrender.com/2007/05/the-secret-to-curl-in-php-on-windows/#comments</comments>
		<pubDate>Mon, 14 May 2007 10:48:37 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=43</guid>
		<description><![CDATA[cURL is a great library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers using many different types of protocols. In particular, it’s used heavily in PHP to communicate to Payment Gateways and fetch XML feeds from other sites whilst being ‘transparent’ to web page visitors. The [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://curl.haxx.se/" target="blank">cURL</a> is a great library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers using many different types of protocols. In particular, it’s used heavily in PHP to communicate to Payment Gateways and fetch XML feeds from other sites whilst being ‘transparent’ to web page visitors.</p>
<p>The particular secret I would like to share involves establishing connections to secure sites (SSL-enabled ones in particular). When you browse to an SSL–enabled site in your web browser, a few things happen&#8230; One of the things that happen is that your browser checks to see if the site’s security certificate is trusted. It does this by checking the entity that signed the certificate against it’s built in book of trusted signatures and if it finds a match, onto the next step. However, if your browser can’t find a match the certificate will be invalid and it will complain that the site could potentially be a fake or insecure.</p>
<p><!--SnipSnip--></p>
<p>The ‘book of trusted signatures’ is known as a <a href="http://en.wikipedia.org/wiki/Certificate_authority" target="_blank">Certificate Authority</a> bundle and usually comes built in with most web browsers. If you install cURL (the standalone version that can be run from the command–line), chances are it will come with the cURL Certificate Authority bundle and you won’t need to do a thing as the cURL functions within PHP will use this as it’s book of trusted signatures. However, on Windows the cURL functions within PHP are pre–built and included in the standard PHP setup, thus do not include this bundle. Chances are if you don’t know this you’ll probably spend a good amount of your time screaming at your webpage as it mocks you with error number 60! I know I spent quite a good few hours wondering why it worked on my Linux PC but not on the Windows server!</p>
<pre>CURL Error 60: SSL certificate problem, verify that the CA cert is OK.
Details: error:14090086:SSL routines
SSL3_GET_SERVER_CERTIFICATE:certificate verify failed</pre>
<p>Luckily the fix is quite easy&#8230;</p>
<ol>
<li><del datetime="2010-08-20T09:20:54+00:00">Download <a href="http://curl.haxx.se/latest.cgi?curl=win32-ssl" target="_blank">standalone cURL for Windows</a> (make sure it is the SSL version).</del><br />Download <a href="http://curl.haxx.se/docs/caextract.html" target="_blank">the .pem file</a> from the cURL site and rename the extension to .crt</li>
<li>Extract curl-ca-bundle.crt from the download and copy to your web server folder.</li>
<li>Add the following line to your code: -
<pre>curl_setopt($ch, CURLOPT_CAINFO, "c:/path/to/ca-bundle.crt");</pre>
</li>
<li>Remember to change $ch to the variable you’ve assigned your curl connection to and “c:/path/to/ca-bundle.crt” to the location of where you have copied the ca-bundle.crt.</li>
<li>Check the server has permission to read this file.</li>
</ol>
<p>If you are getting started with cURL, here is some sample code I’ve written that should get you started. It outputs the contents of the secure server to a string, which is echoed out to your page.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Set up cURL connection</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://www.verisign.com/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ca</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'c:/path/to/ca-bundle.crt'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</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;">// Apply various settings</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Don’t return the header, just the html</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_CAINFO<span style="color: #339933;">,</span> <span style="color: #000088;">$ca</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Set the location of the CA-bundle</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Return contents as a string</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span></pre></div></div>

<p>That’s it! You should now be able to connect successfully to SSL-enabled websites using the cURL functions of PHP on your Windows server.</p>
<p><strong>UPDATE 2010/08/20</strong>: Apparently the certificates aren&#8217;t shipped with the archived versions any more. To get the latest certificate bundle that&#8217;s been extracted from the Mozilla browser you can <a href="http://curl.haxx.se/docs/caextract.html">download the .pem file</a> from the cURL site and rename the extension to .crt.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2007/05/the-secret-to-curl-in-php-on-windows/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Validating Credit Card Numbers</title>
		<link>http://richardwarrender.com/2006/12/validating-card-numbers/</link>
		<comments>http://richardwarrender.com/2006/12/validating-card-numbers/#comments</comments>
		<pubDate>Sat, 16 Dec 2006 22:11:59 +0000</pubDate>
		<dc:creator>Richard Warrender</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[e–commerce]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://richardwarrender.com/?p=160</guid>
		<description><![CDATA[Lately, I’ve been working on an e–commerce website and discovered a handy algorithm for validating card numbers. The Luhn algorithm (also known as mod 10) is a checksum formula and is used to protect against accidental errors rather than malicious attacks. The algorithm is particularly useful for checking to see if the card number ‘looks’ [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I’ve been working on an e–commerce website and discovered a handy algorithm for validating card numbers. The Luhn algorithm (also known as mod 10) is a checksum formula and is used to protect against accidental errors rather than malicious attacks.</p>
<p>The algorithm is particularly useful for checking to see if the card number ‘looks’ right before sending it off to the payment provider for processing. This reduces the amount of rejected card payments, which is always a good thing. <img src='http://richardwarrender.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>More details of <a href="http://en.wikipedia.org/wiki/Luhn_algorithm" target="_blank">how the algorithm works</a> can be found on  Wikipedia and my annotated PHP implementation can be found below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* PHP function for validating card numbers */</span>
<span style="color: #000000; font-weight: bold;">function</span> checkLuhn<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cardNumber</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Copyright (c) Richard Warrender. Licenced under the LGPL.</span>
    <span style="color: #666666; font-style: italic;">// http://richardwarrender.com/</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Get total amount of digits to process</span>
    <span style="color: #000088;">$digitCount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>String<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$cardNumber</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Checksum must be zero to begin with</span>
    <span style="color: #000088;">$checksum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Loop round card number extracting digits</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span><span style="color: #000088;">$digitCount</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Extract digit number</span>
            <span style="color: #000088;">$digits</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cardNumber</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Check to see if this the luhn number, we need to double it</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">// Double luhn digit</span>
                    <span style="color: #000088;">$digit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$digits</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">// If greater or equal to 10, then use sum of digits</span>
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$digit</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #666666; font-style: italic;">// Get first digit</span>
                            <span style="color: #000088;">$firstDigit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$digit</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #666666; font-style: italic;">// Get second digit</span>
                            <span style="color: #000088;">$secondDigit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$digit</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #666666; font-style: italic;">/// Add together and replace original luhn digit</span>
                            <span style="color: #000088;">$digit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$firstDigit</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$secondDigit</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">// Reload back into array</span>
                    <span style="color: #000088;">$digits</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$digit</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #666666; font-style: italic;">// Keep a running total for use in checksum</span>
            <span style="color: #000088;">$checksum</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$digits</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$checksum</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</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;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://richardwarrender.com/2006/12/validating-card-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

