<?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>Pryde Design</title>
	<atom:link href="http://www.pryde-design.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pryde-design.co.uk</link>
	<description>Web Design You Can Afford</description>
	<lastBuildDate>Mon, 26 Jul 2010 11:31:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Display featured services columns in WordPress</title>
		<link>http://www.pryde-design.co.uk/2010/07/display-featured-services-columns-in-wordpress/</link>
		<comments>http://www.pryde-design.co.uk/2010/07/display-featured-services-columns-in-wordpress/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 11:31:40 +0000</pubDate>
		<dc:creator>Andrew Pryde</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.pryde-design.co.uk/?p=323</guid>
		<description><![CDATA[On a recent client project I needed client editable columns at the bottom of the WordPress front page. There seemed no logical way to do it within the TinyMCE editor without using a plugin and tables for layout (bah EVIL) so I decided to use custom fields and the following code. I am sure there [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent client project I needed client editable columns at the bottom of the WordPress front page. There seemed no logical way to do it within the TinyMCE editor without using a plugin and tables for layout (bah EVIL) so I decided to use custom fields and the following code. I am sure there are more robust and prettier ways of doing this but here is my solution.

<pre class="brush: php;">
  &lt;?php if (is_front_page()) : ?&gt;
    &lt;ul class=&quot;featuredServices&quot;&gt;
    &lt;?php for ($i = 1; $i &lt;= 3; $i++) : ?&gt;
      &lt;li class=&quot;&lt;?php echo ($i == 3) ? &quot;col-last&quot; : &quot;col&quot;; ?&gt;&quot;&gt;
        &lt;h3&gt;
          &lt;a href=&quot;&lt;?php echo get_post_meta(get_the_ID(), &quot;Col$i Link&quot;, $single) ?&gt;&quot;&gt;
            &lt;?php echo get_post_meta(get_the_ID(), &quot;Col$i Title&quot;, $single) ?&gt;
          &lt;/a&gt;
        &lt;/h3&gt;
        &lt;p&gt;
          &lt;?php echo get_post_meta(get_the_ID(), &quot;Col$i Text&quot;, $single) ?&gt;
        &lt;/p&gt;
      &lt;/li&gt;
    &lt;?php endfor; ?&gt;
    &lt;/ul&gt;
  &lt;?php endif; ?&gt;
</pre>

<p>All the site editor has to do is edit the custom fields named Col1-3 Title, Text and Link and the code displays the data as an unordered list which can be styled as columns. An improvement would be do add the ability to do a varying number of columns as the number of columns is hard-coded into the theme but it wasn't necessarily for this project and would just have added another custom field to confuse the editor.</p>

<p>Please let me know what you think via the comments and if you have any suggestions for improving the code / doing it in a different way that would be great too.</p>

<p>- <a href="http://www.twitter.com/Prydie">@Prydie</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pryde-design.co.uk/2010/07/display-featured-services-columns-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Redirect / Refresh Function</title>
		<link>http://www.pryde-design.co.uk/2010/07/php-redirect-refresh-function/</link>
		<comments>http://www.pryde-design.co.uk/2010/07/php-redirect-refresh-function/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 08:00:26 +0000</pubDate>
		<dc:creator>Andrew Pryde</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pryde-design.co.uk/?p=304</guid>
		<description><![CDATA[Often I find myself redirecting users between pages using varying methods depending where in the program flow the redirect is required (i.e. have the headers been sent). I decided to write a function which took the effort out of redirecting or refreshing (with a delay) a page. &#60;?php function redirect($location, $delay = 0) { if [...]]]></description>
			<content:encoded><![CDATA[<p>Often I find myself redirecting users between pages using varying methods depending where in the program flow the redirect is required (i.e. have the headers been sent). I decided to write a function which took the effort out of redirecting or refreshing (with a delay) a page.</p>

<pre class="brush: php;">
&lt;?php
function redirect($location, $delay = 0) {
	if (!headers_sent()) {
		if ($delay &gt; 0) {
			header(&quot;Refresh: $delay; url=$location&quot;);
		} else { header(&quot;Location: $location&quot;); }
	} else {
		?&gt;
		&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
			$(function () { 
				setTimeout(function() { 
					window.location.replace('&lt;?php echo $location; ?&gt;');
				}, &lt;?php echo $delay*1000; ?&gt;); 
			});
		&lt;/script&gt;
		&lt;noscript&gt;
			&lt;meta http-equiv=&quot;refresh&quot; content=&quot;&lt;?php echo $delay; ?&gt;;url=&lt;?php echo $location; ?&gt;&quot;&gt;
		&lt;/noscript&gt;
		&lt;?php
	}
}
?&gt;
</pre>

<p>The script first tries to redirect the page using the header() function. If the headers have not been sent and then falls back to jQuery, resorting finally to a meta refresh if javascript is disabled.</p>]]></content:encoded>
			<wfw:commentRss>http://www.pryde-design.co.uk/2010/07/php-redirect-refresh-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Differentiate jQuery $.ajax requests</title>
		<link>http://www.pryde-design.co.uk/2010/06/differentiate-jquery-ajax-requests/</link>
		<comments>http://www.pryde-design.co.uk/2010/06/differentiate-jquery-ajax-requests/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 14:55:28 +0000</pubDate>
		<dc:creator>Andrew Pryde</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pryde-design.co.uk/?p=288</guid>
		<description><![CDATA[To ensure that your PHP application works both with and without Javascript enabled in the users browser it is often necessary to return different content depending on whether Javascript is enabled or not. For example often it is useful to return data via JSON when Javascript is enabled however it is unhelpful to display JSON [...]]]></description>
			<content:encoded><![CDATA[<p>To ensure that your PHP application works both with and without Javascript enabled in the users browser it is often necessary to return different content depending on whether Javascript is enabled or not. For example often it is useful to return data via JSON when Javascript is enabled however it is unhelpful to display JSON to a user.</p>

<h2>jQuery + Apache</h2>
<p>jQuery (and most other major Javascript libraries) when executing AJAX requests use a specific header to show that they are doing so. This header can be requested and accessed as a variable as long PHP is installed as an Apache module. This method requires no change to your Javascript (jQuery) code however if PHP isn't installed as an Apache module there is a slightly less elegant workaround below that does require you to edit your Javascript.

<pre class="brush: php;">
&lt;?php
$headers = apache_request_headers();
if( !empty($headers['X-Requested-With']) &amp;&amp; ($headers['X-Requested-With'] == 'XMLHttpRequest')) { 
	header(&quot;Content-type: application/json&quot;); }
}
?&gt;
</pre>

<p>The above code firstly requests the headers and stores them in the variable $headers and then if the header is present sets the content type to application/json so that the browser treats the data as JSON. We use two clauses in the IF statement to avoid PHP displaying a warning about $headers['X-Requested-With'] being undeclared when Javascript is disabled.</p>

<p>Then when returning data (such as error information) you can use the same if statement to return a JSON encoded array if Javascript is enabled or just simple HTML if not.</p>

<h2>jQuery with another webserver</h2>
<p>PHP does not (to my knowledge) provide a platform independent method of getting the request headers. Therefore we can simply add another data field to our jQuery $.ajax request to be used as a differentiator. 

<pre class="brush: jscript;">
$(&quot;.button&quot;).click(function() {
	var firstName = $(&quot;input#firstName&quot;).val();
	var lastName = $(&quot;input#lastName&quot;).val();
	var email = $(&quot;input#email&quot;).val();
	var dataString = 'firstName=' + firstName + '&amp;lastName=' + lastName + '&amp;email=' + email + '&amp;js=1';
	$.ajax({
		type: &quot;POST&quot;,
		url: &quot;add.php&quot;,
		data: dataString,
		success: function(result) {
			// do something
		}
	});
    return false;
});
</pre>

<p>By adding &#038;js=1 to the request in the Javascript we can use the $_POST['js'] variable in PHP to differentiate between jQuery $.ajax requests and browser requests.</p>

<pre class="brush: php;">
if (!empty($_POST['js'])) { 
	header(&quot;Content-type: application/json&quot;); 
}
</pre>

<p>I hope you found this useful, if you have any comments or suggestions (especially on a more universal method of reading request headers) please let me know in the comments.</p>

<p>- Andrew Pryde</p>]]></content:encoded>
			<wfw:commentRss>http://www.pryde-design.co.uk/2010/06/differentiate-jquery-ajax-requests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving WordPress &#8211; Localhost to Live</title>
		<link>http://www.pryde-design.co.uk/2010/06/moving-wordpress-localhost-to-live/</link>
		<comments>http://www.pryde-design.co.uk/2010/06/moving-wordpress-localhost-to-live/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 00:46:01 +0000</pubDate>
		<dc:creator>Andrew Pryde</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.pryde-design.co.uk/?p=260</guid>
		<description><![CDATA[I watched Chris Coyier's excellent screencast #87 Moving up with MAMP (you certainly should too) on the subject of transferring a WordPress blog from a local server (or other development server) to a production server. Though he covered a lot of ground and set out a process perfect for less advanced users, especially those with [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.pryde-design.co.uk/wp-content/uploads/2010/06/WPLocalLive.jpg" alt="" title="WPLocalLive" width="252" height="188" class="postThumb size-full wp-image-268" />
<p>I watched Chris Coyier's excellent screencast <a href="http://css-tricks.com/video-screencasts/87-moving-up-with-mamp/">#87 Moving up with MAMP</a> (you certainly should too) on the subject of transferring a WordPress blog from a local server (or other development server) to a production server. Though he covered a lot of ground and set out a process perfect for less advanced users, especially those with no experience of the Terminal there are a few tricks that more advanced users will be able to use to save a lot of time and headaches.</p>
<div class="clear"></div> 
<h3>1. Moving files</h3> 
<p>The only files that you need to upload are those specific to your installation of WordPress which are contained within the wp-content directory (with one notable exception but we will get to that later). The rest of the files can be fetched straight from the WordPress servers eliminating the lengthy period of time it takes even the better FTP clients to upload all the core WordPress files. This is done by connecting to the production server via SSH and issuing the following commands.</p>

<pre class="brush: plain;">
wget http://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
</pre>

<p>You can then go ahead and upload the contents of the wp-content directory via FTP. However one file in particular will be missing - the .htaccess file used by WordPress to create the permalink structure of your site. You may wish to upload this from your WordPress directory but because the filename is prefixed with a . you are  unlikely to be able to see it without changing the settings of your FTP client. The easiest thing is simply to ensure that when the site is uploaded you have WordPress rewrite these rules by disabling and then re-enabling permalinks in the WordPress settings panel.</p>

<h3>2. References to the development domain in the DB</h3> 
<p>In the WordPress database multiple references are made in different records and tables to WordPress' location (i.e. the domain it resides on). When installing on a local development machine these settings are of course different from those of your production server and it is these settings which you will find in the database. This can be avoided however by editing your /etc/hosts file on OSX and Linux (or \Windows\system32\drivers\etc\hosts file on Windows) so that locally the production domain points to your development server.</p>

<p>On Linux / Mac open Terminal and type "sudo nano /etc/hosts", enter your password and add the following at the bottom of the file.</p>
<pre class="brush: plain;">
127.0.0.1 www.productiondomain.com
</pre>
<p>On windows just browse to the \Windows\system32\drivers\etc\ folder and open the hosts file with Notepad and add the same line.</p>

<p>This enables you to configure WordPress as if you were using the production domain and your computer will just redirect your requests for www.productiondomain.com to your local server.</p>

<p>If you haven't done this are your database is littered with references to your development domain no need to fear. All you need to do is find and replace the instances of your local development domain within the exported database dump you will be uploading to the production server. This can be done by executing the following command on the database dump file in Terminal.</p>

<pre class="brush: plain;">
sed -i.bak 's/localhost/www.productiondomain.com/g' db.sql
</pre>

<p>What this does is replace all instances of the string "localhost" with the string "www.productiondomain.com" so that all your database records will reference the new domain rather than your local development version. This command only available on OSX and Linux but one could also use the find and replace functionality of your favourite text editor as long as the database wasn't to large.</p>

<p>Anyhow, I hope you find this useful and that it speeds up the process a little. Let me know what you think in the comments and if there are any particular requests I will expand upon some more of the minutia of moving WordPress from a localhost to live.</p>]]></content:encoded>
			<wfw:commentRss>http://www.pryde-design.co.uk/2010/06/moving-wordpress-localhost-to-live/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Cl.ly TextExpander URL shortener</title>
		<link>http://www.pryde-design.co.uk/2010/06/cl-ly-url-shortener/</link>
		<comments>http://www.pryde-design.co.uk/2010/06/cl-ly-url-shortener/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 20:09:35 +0000</pubDate>
		<dc:creator>Andrew Pryde</dc:creator>
				<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://www.pryde-design.co.uk/?p=209</guid>
		<description><![CDATA[I have been testing out TextExpander and for the most part have been really impressed by its time saving goodness. I like the inbuilt bit.ly snippet which enables you to shorten any URL copied to your clipboard and insert the shortened URL into any text area on your mac. However I have been using the [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.pryde-design.co.uk/wp-content/uploads/2010/06/CloudAppPostLogo2.jpg" alt="" title="CloudAppPostLogo" width="250" height="188" class="postThumb size-full wp-image-239" />

<p>I have been testing out <a href="http://www.smileonmymac.com/TextExpander/" target="_blank">TextExpander</a> and for the most part have been really impressed by its time saving goodness. I like the inbuilt bit.ly snippet which enables you to shorten any URL copied to your clipboard and insert the shortened URL into any text area on your mac. However I have been using the cl.ly service from <a href="http://twitter.com/getcloudapp" target="_blank">@getcloudapp</a> which produces URLs only <del datetime="2010-06-18T18:52:08+00:00">16</del> 17 characters long (nice for saving space in tweets) and so I decided to code my own cl.ly URL shortener in Applescript for use in TextExpander. Here is the result.</p>
<div class="clear"></div>
<pre class="brush: plain;">set Username to &quot;user@email.com&quot;
set Pword to &quot;passwordhere&quot;
set the ClipURL to (the clipboard as string)

ignoring case
	if ((characters 1 through 4 of ClipURL as string) is not &quot;http&quot;) then
		return &quot;Malformed URL.&quot;
	else
		set curlCMD to &quot;curl --digest -u '&quot; &amp; Username &amp; &quot;:&quot; &amp; Pword &amp; &quot;' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{ \&quot;item\&quot;: { \&quot;name\&quot;: \&quot;&quot; &amp; ClipURL &amp; &quot;\&quot;, \&quot;redirect_url\&quot;: \&quot;&quot; &amp; ClipURL &amp; &quot;\&quot; } }' http://my.cl.ly/items&quot;

		-- Run the script and get the result:
		set clURL to (do shell script curlCMD)
		set oset to offset of &quot;http://cl.ly/&quot; in clURL
		set clURL to text (oset) thru (oset + 16) of clURL
		return clURL
	end if
end ignoring
</pre>

<h3>Implementation</h3>
<p>To implement this function create a new text expander snippet and change its content type to AppleScript (this is so it doesn't paste the code when you trigger the abbreviation but executes it). Then paste in the above code filling the email and password variables with your account details (not got one? Get one <a href="http://my.cl.ly/register" target="_blank">here</a>).</p>

<p>This is by no means a perfect solution. For a start you have to enter your credentials in plaintext into the script for it to run (a security concern and not great for distribution).<del datetime="2010-06-18T18:52:08+00:00"> Secondly due to AppleScirpt’s complete lack of text phrasing functionality if <a href="http://twitter.com/getcloudapp" target="_blank">@getcloudapp</a> changes the length of their URL which they are likely to do as there are only 226,920 permutations of 3 character case-sensitive alpha-numeric strings, the script will fail with very little grace.</del></p>

<p><strong>Update:</strong> They filled the URL space (all 226,920 permutations) and now the URLs are 17 characters long. The script has been updated accordingly. They may fill the URL space happen again however there are now 13,388,280 permutations of 4 character case sensitive alphanumeric strings available so we are safe for now.</p>

<p>Anyway, please let me know what you think via commenting bellow as I am looking at ways of improving this and suggestions are most welcome.</p>]]></content:encoded>
			<wfw:commentRss>http://www.pryde-design.co.uk/2010/06/cl-ly-url-shortener/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Binomial Distribution Probability Calculator</title>
		<link>http://www.pryde-design.co.uk/2010/05/python-binomial-distribution-probability-calculator/</link>
		<comments>http://www.pryde-design.co.uk/2010/05/python-binomial-distribution-probability-calculator/#comments</comments>
		<pubDate>Fri, 14 May 2010 21:18:36 +0000</pubDate>
		<dc:creator>Andrew Pryde</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pryde-design.co.uk/?p=246</guid>
		<description><![CDATA[A set of functions for calculating combinations and for outputting the binomial distribution for any given probability and number of trials written in Python. This does not output cumulative frequency tables but it would be easy to implement (leave a comment if you are interested and I will write the code if there is enough [...]]]></description>
			<content:encoded><![CDATA[A set of functions for calculating combinations and for outputting the binomial distribution for any given probability and number of trials written in Python. This does not output cumulative frequency tables but it would be easy to implement (leave a comment if you are interested and I will write the code if there is enough interest).

<pre class="brush: python;">
#!/usr/bin/env python
# Python Script to work caculate the binomial distrobution of a given probability to a given accuracy
# By Andrew Pryde - http://www.pryde-design.co.uk

# Function for finding the factorial of a number
def fact(x): 
	return (1 if x==0 else x * fact(x-1))

# Function for n &quot;Choose&quot; r (nCr)	
def nCr(n, r):
	return (fact(n)/(fact(r)*fact(n-r)))	

# Binomial function iteself	
def B( n, p, a ):
	r=0
	print &quot;R : Probability&quot;
	while r&lt;=n:
		print r, &quot;:&quot;, round(nCr(n, r)*(p**r)*((1-p)**(n-r)), a)
		r=r+1
	return

# Set the variables 	
n = input(&quot;Please enter n: &quot;)
p = input(&quot;Please enter p: &quot;)
a = input(&quot;Please enter decimal accuracy: &quot;)

# Call the function with users variables		
B(n, p, a)
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.pryde-design.co.uk/2010/05/python-binomial-distribution-probability-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
