<?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>The Code Train &#187; Tips &amp; Tricks</title>
	<atom:link href="http://thecodetrain.co.uk/category/tips-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecodetrain.co.uk</link>
	<description>Where Neil Crosby talks about coding on the train...</description>
	<lastBuildDate>Wed, 18 Aug 2010 18:22:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Deep Linking into YouTube Videos</title>
		<link>http://thecodetrain.co.uk/2010/01/deep-linking-into-youtube-videos/</link>
		<comments>http://thecodetrain.co.uk/2010/01/deep-linking-into-youtube-videos/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 23:08:48 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=352</guid>
		<description><![CDATA[<p>Just a very quick post today to highlight something I only became aware of a couple of days ago because of <a href="http://jakearchibald.com">Jake Archibald</a>, when he posted a youtube link on an internal mailing list &#8211; it&#8217;s possible to deep link into an arbitrary point within YouTube videos.</p>

<p>I had thought that this was something most other interested people would have known about already, and that I was slow on the uptake as usual, but it turns out that when I mentioned this to <a href="http://adrianocastro.net">Adriano Castro</a> today he wasn&#8217;t aware.  So, I present to you a method for deep linking into YouTube videos.</p>

<ol>
<li><p>Take one YouTube URL.</p>

<pre><code>http://www.youtube.com/watch?v=4Ust9YBlEfY
</code></pre></li>
<li><p>Watch it, and find a place within it that you&#8217;d like to link to.</p>

<p>In this instance, I want to link 28 seconds in.</p></li>
<li><p>Add a fragment to the URL with the format #t=<em>minutes</em>m<em>seconds</em></p>

<p>In this instance, the URL would become:</p>

<pre><code>http://www.youtube.com/watch?v=4Ust9YBlEfY#t=0m28
</code></pre></li>
<li><p>That&#8217;s all there is to it. <a href="http://www.youtube.com/watch?v=4Ust9YBlEfY#t=0m28">Simples</a>.</p></li>
</ol>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Just a very quick post today to highlight something I only became aware of a couple of days ago because of <a href="http://jakearchibald.com">Jake Archibald</a>, when he posted a youtube link on an internal mailing list &#8211; it&#8217;s possible to deep link into an arbitrary point within YouTube videos.</p>

<p>I had thought that this was something most other interested people would have known about already, and that I was slow on the uptake as usual, but it turns out that when I mentioned this to <a href="http://adrianocastro.net">Adriano Castro</a> today he wasn&#8217;t aware.  So, I present to you a method for deep linking into YouTube videos.</p>

<ol>
<li><p>Take one YouTube URL.</p>

<pre><code>http://www.youtube.com/watch?v=4Ust9YBlEfY
</code></pre></li>
<li><p>Watch it, and find a place within it that you&#8217;d like to link to.</p>

<p>In this instance, I want to link 28 seconds in.</p></li>
<li><p>Add a fragment to the URL with the format #t=<em>minutes</em>m<em>seconds</em></p>

<p>In this instance, the URL would become:</p>

<pre><code>http://www.youtube.com/watch?v=4Ust9YBlEfY#t=0m28
</code></pre></li>
<li><p>That&#8217;s all there is to it. <a href="http://www.youtube.com/watch?v=4Ust9YBlEfY#t=0m28">Simples</a>.</p></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2010/01/deep-linking-into-youtube-videos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using WordPress&#8217;s &#8220;Upgrade Automatically&#8221; Feature</title>
		<link>http://thecodetrain.co.uk/2009/12/using-wordpresss-upgrade-automatically-feature/</link>
		<comments>http://thecodetrain.co.uk/2009/12/using-wordpresss-upgrade-automatically-feature/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:41:12 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[commandline]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=339</guid>
		<description><![CDATA[<p>Yup, it&#8217;s time for the WordPress upgrade dance, yet again &#8211; <a href="http://wordpress.org/development/2009/12/wordpress-2-9/">2.9 Carmen</a> has just been released and everyone using WordPress is being &#8220;urged&#8221; to upgrade.</p>

<p>Now, I&#8217;m slightly ashamed to admit it, but up until last week I hadn&#8217;t been upgrading regularly. It had seemed like in order to be able to use WordPress&#8217;s &#8220;Upgrade Automatically&#8221; functionality I had to either enable FTP (ewwww), or FTPS (seemed like a lot of effort, and needed the SSH extension for PHP installing). So, I&#8217;d ended up doing an upgrade every now and then manually. Not the best plan in the world.</p>

<p>So, last week I decided to take another look and see if there wasn&#8217;t a more sensible way to enable WordPress to run its &#8220;Upgrade Automatically&#8221; code.  Turns out there is &#8211; just make sure the directory you&#8217;re running WordPress under is owned by the same user that your web server is running as. Do this, and suddenly &#8220;Upgrade Automatically&#8221; works, and you&#8217;re a happy camper.</p>

<p>And how to do that? Simple.  First, find out which user your web server is running as:</p>

<pre><code>ps aux | grep apache
</code></pre>

<p>Generally, the answer will be <code>www-data</code>. Then, once you&#8217;ve worked out who the server&#8217;s owner is, change the owner of your WordPress directory tree:</p>

<pre><code>chown -R www-data:www-data /path/to/wordpress/
</code></pre>

<p>Then, when you go back into WordPress you&#8217;ll be able to click on the &#8220;Upgrade Automatically&#8221;, and WordPress will actually upgrade itself.  Hooray! (Of course, don&#8217;t forget to back up before you do this. I am not responsible for your data, follow instructions at your own risk, Santa Claus is real, etc.)</p>

<p>Hopefully this is of use to someone out there. It&#8217;s certainly made me happier about the whole upgrade dance.</p>

<h2>Update</h2>

<p>As Chris so rightly points out below, leaving things open to the web server to change willy nilly can be a little silly, so after running the update do another <code>chown</code>, this time changing the ownership back to your username and group.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Yup, it&#8217;s time for the WordPress upgrade dance, yet again &#8211; <a href="http://wordpress.org/development/2009/12/wordpress-2-9/">2.9 Carmen</a> has just been released and everyone using WordPress is being &#8220;urged&#8221; to upgrade.</p>

<p>Now, I&#8217;m slightly ashamed to admit it, but up until last week I hadn&#8217;t been upgrading regularly. It had seemed like in order to be able to use WordPress&#8217;s &#8220;Upgrade Automatically&#8221; functionality I had to either enable FTP (ewwww), or FTPS (seemed like a lot of effort, and needed the SSH extension for PHP installing). So, I&#8217;d ended up doing an upgrade every now and then manually. Not the best plan in the world.</p>

<p>So, last week I decided to take another look and see if there wasn&#8217;t a more sensible way to enable WordPress to run its &#8220;Upgrade Automatically&#8221; code.  Turns out there is &#8211; just make sure the directory you&#8217;re running WordPress under is owned by the same user that your web server is running as. Do this, and suddenly &#8220;Upgrade Automatically&#8221; works, and you&#8217;re a happy camper.</p>

<p>And how to do that? Simple.  First, find out which user your web server is running as:</p>

<pre><code>ps aux | grep apache
</code></pre>

<p>Generally, the answer will be <code>www-data</code>. Then, once you&#8217;ve worked out who the server&#8217;s owner is, change the owner of your WordPress directory tree:</p>

<pre><code>chown -R www-data:www-data /path/to/wordpress/
</code></pre>

<p>Then, when you go back into WordPress you&#8217;ll be able to click on the &#8220;Upgrade Automatically&#8221;, and WordPress will actually upgrade itself.  Hooray! (Of course, don&#8217;t forget to back up before you do this. I am not responsible for your data, follow instructions at your own risk, Santa Claus is real, etc.)</p>

<p>Hopefully this is of use to someone out there. It&#8217;s certainly made me happier about the whole upgrade dance.</p>

<h2>Update</h2>

<p>As Chris so rightly points out below, leaving things open to the web server to change willy nilly can be a little silly, so after running the update do another <code>chown</code>, this time changing the ownership back to your username and group.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2009/12/using-wordpresss-upgrade-automatically-feature/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Locking my Mac when I want to step away from it</title>
		<link>http://thecodetrain.co.uk/2009/07/locking-my-mac-when-i-want-to-step-away/</link>
		<comments>http://thecodetrain.co.uk/2009/07/locking-my-mac-when-i-want-to-step-away/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 08:40:34 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[scratching an itch]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=280</guid>
		<description><![CDATA[<p>I&#8217;ve noticed a few people asking recently &#8220;How do you lock your Mac desktop when you want to nip out?&#8221;.  It&#8217;s a reasonable question — after all, security of your machine and the data on it should be at the forefront of your mind if you decide to leave your machine whilst you go and do something else.</p>

<p>The way I do this is to use a &#8220;hot corner&#8221;. In OSX you can set up your Mac to perform different tasks when you move your mouse up to any one of the four corners.  If you open <code>System Preferences</code>, then <code>Exposé and Spaces</code> and make sure you&#8217;ve got the <code>Spaces</code> tab open you&#8217;ll see an <code>Active Screen Corners</code> section at the top of the window.  I have the bottom right hand corner set to <code>Start Screen Saver</code>.  Because I have set <code>Require password to wake this computer from sleep or screen saver</code> in the <code>Security</code> section of <code>System Preferences</code>, when I throw my mouse into the bottom right hand corner of the screen it automatically locks itself for me.  </p>

<p>It&#8217;s a simple solution that works well for me.</p>

<p>Another way you can lock your machine is to use the <code>Keychain Access</code> application (<code>/Applications/Utilities/Keychain Access.app</code>).  If you load this and then open <code>Preferences</code> you&#8217;ll see a <code>Show Status in Menu Bar</code> option on the <code>General</code> tab. If you tick this you&#8217;ll see an unlocked padlock appear in your menu bar. From now on if you want to lock your machine you can click on the padlock icon and then select <code>Lock Screen</code>.  I personally don&#8217;t use this solution because it requires more dexterity than just throwing the mouse into a corner of the screen, but it&#8217;s another option that you might lie to use.</p>

<p>So, there you have it — two different ways of locking your Mac&#8217;s screen under OSX.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve noticed a few people asking recently &#8220;How do you lock your Mac desktop when you want to nip out?&#8221;.  It&#8217;s a reasonable question — after all, security of your machine and the data on it should be at the forefront of your mind if you decide to leave your machine whilst you go and do something else.</p>

<p>The way I do this is to use a &#8220;hot corner&#8221;. In OSX you can set up your Mac to perform different tasks when you move your mouse up to any one of the four corners.  If you open <code>System Preferences</code>, then <code>Exposé and Spaces</code> and make sure you&#8217;ve got the <code>Spaces</code> tab open you&#8217;ll see an <code>Active Screen Corners</code> section at the top of the window.  I have the bottom right hand corner set to <code>Start Screen Saver</code>.  Because I have set <code>Require password to wake this computer from sleep or screen saver</code> in the <code>Security</code> section of <code>System Preferences</code>, when I throw my mouse into the bottom right hand corner of the screen it automatically locks itself for me.  </p>

<p>It&#8217;s a simple solution that works well for me.</p>

<p>Another way you can lock your machine is to use the <code>Keychain Access</code> application (<code>/Applications/Utilities/Keychain Access.app</code>).  If you load this and then open <code>Preferences</code> you&#8217;ll see a <code>Show Status in Menu Bar</code> option on the <code>General</code> tab. If you tick this you&#8217;ll see an unlocked padlock appear in your menu bar. From now on if you want to lock your machine you can click on the padlock icon and then select <code>Lock Screen</code>.  I personally don&#8217;t use this solution because it requires more dexterity than just throwing the mouse into a corner of the screen, but it&#8217;s another option that you might lie to use.</p>

<p>So, there you have it — two different ways of locking your Mac&#8217;s screen under OSX.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2009/07/locking-my-mac-when-i-want-to-step-away/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Turning `diff` up to eleven</title>
		<link>http://thecodetrain.co.uk/2009/01/turning-diff-up-to-eleven/</link>
		<comments>http://thecodetrain.co.uk/2009/01/turning-diff-up-to-eleven/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 11:10:32 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[feci]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=191</guid>
		<description><![CDATA[<p>Yesterday, I had a problem.  I had two files that were almost the same, but one of them had a few chunks of new data in it, and there were a couple of places where there were lines that only had a word or two changed in them.  What I wanted was just the new data in the second file, and I didn&#8217;t care about the stuff that had just changed a bit.</p>

<p>Obviously, this sounded like a job for the <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?diff"><code>diff</code></a> command.</p>

<p>Unfortunately, I found the man page a little more difficult than normal to decipher and had to call upon the massively oversized brain of <a href="http://benjaminhawkeslewis.com/">Ben Hawkes-Lewis</a> to see if we could work out together how to do what I wanted.  After a bit of fumbling, it turned out that we wanted to use the <a href="http://www.mingw.org/cgi-bin/info2html/info2html?(diff.info.gz)Line+Group+Formats">line group format</a> options.  Here&#8217;s what we came up with that solved my problem:</p>

<pre><code>diff --new-group-format="%&gt;" --old-group-format="" \
--changed-group-format="" --unchanged-group-format="" \
original.file file-with-extra-data.file
</code></pre>

<p>Hopefully this will be of use to someone else at some point too.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I had a problem.  I had two files that were almost the same, but one of them had a few chunks of new data in it, and there were a couple of places where there were lines that only had a word or two changed in them.  What I wanted was just the new data in the second file, and I didn&#8217;t care about the stuff that had just changed a bit.</p>

<p>Obviously, this sounded like a job for the <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?diff"><code>diff</code></a> command.</p>

<p>Unfortunately, I found the man page a little more difficult than normal to decipher and had to call upon the massively oversized brain of <a href="http://benjaminhawkeslewis.com/">Ben Hawkes-Lewis</a> to see if we could work out together how to do what I wanted.  After a bit of fumbling, it turned out that we wanted to use the <a href="http://www.mingw.org/cgi-bin/info2html/info2html?(diff.info.gz)Line+Group+Formats">line group format</a> options.  Here&#8217;s what we came up with that solved my problem:</p>

<pre><code>diff --new-group-format="%&gt;" --old-group-format="" \
--changed-group-format="" --unchanged-group-format="" \
original.file file-with-extra-data.file
</code></pre>

<p>Hopefully this will be of use to someone else at some point too.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2009/01/turning-diff-up-to-eleven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get more than the last 10 Recently Played Tracks from last.fm</title>
		<link>http://thecodetrain.co.uk/2008/12/how-to-get-more-than-the-last-10-recently-played-tracks-from-lastfm/</link>
		<comments>http://thecodetrain.co.uk/2008/12/how-to-get-more-than-the-last-10-recently-played-tracks-from-lastfm/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 12:07:58 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scratching an itch]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=168</guid>
		<description><![CDATA[<p>I don&#8217;t have time for a full entry today, so here&#8217;s a quick tip for <a href="http://last.fm">last.fm</a> users who are making use of their &#8220;Recently Played Tracks&#8221; RSS to do cool things.</p>

<p>It turns out that you can increase the number of tracks returned by the feed simply by adding a <code>limit=somenumber</code> parameter to the URL.  So, for me to grab the last 20 songs that I&#8217;ve scrobbled, I would ask for:</p>

<pre><code>http://ws.audioscrobbler.com/1.0/user/NeilCrosby/recenttracks.rss?limit=20
</code></pre>

<p>I use this as a way of getting a decent sampling of my recent tracks to use on <a href="http://NeilCrosby.com">NeilCrosby.com</a>, as I found the default 10 was too limiting since my &#8220;Stream of Consciousness&#8221; stream normally covers a few days worth of information, whereas my last 10 tracks would only cover an hour or so of data.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t have time for a full entry today, so here&#8217;s a quick tip for <a href="http://last.fm">last.fm</a> users who are making use of their &#8220;Recently Played Tracks&#8221; RSS to do cool things.</p>

<p>It turns out that you can increase the number of tracks returned by the feed simply by adding a <code>limit=somenumber</code> parameter to the URL.  So, for me to grab the last 20 songs that I&#8217;ve scrobbled, I would ask for:</p>

<pre><code>http://ws.audioscrobbler.com/1.0/user/NeilCrosby/recenttracks.rss?limit=20
</code></pre>

<p>I use this as a way of getting a decent sampling of my recent tracks to use on <a href="http://NeilCrosby.com">NeilCrosby.com</a>, as I found the default 10 was too limiting since my &#8220;Stream of Consciousness&#8221; stream normally covers a few days worth of information, whereas my last 10 tracks would only cover an hour or so of data.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2008/12/how-to-get-more-than-the-last-10-recently-played-tracks-from-lastfm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
