<?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>matt-helps</title>
	<atom:link href="http://www.matt-helps.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.matt-helps.com</link>
	<description>insight on all things techie</description>
	<lastBuildDate>Fri, 07 Jun 2013 11:22:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Automatic Backup of MySQL database to S3</title>
		<link>http://www.matt-helps.com/automatic-backup-of-mysql-database-to-s3</link>
		<comments>http://www.matt-helps.com/automatic-backup-of-mysql-database-to-s3#comments</comments>
		<pubDate>Fri, 07 Jun 2013 11:05:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=261</guid>
		<description><![CDATA[Most of my websites run on Amazon&#8217;s EC2 servers and in setting up a new one today I thought I had better come up with a better backup strategy. In the past I&#8217;ve just asked EC2 to create either AMI or EBS snapshots, but they aren&#8217;t done automatically and it&#8217;s not a very elegant solution. [...]]]></description>
				<content:encoded><![CDATA[<p>Most of my websites run on Amazon&#8217;s EC2 servers and in setting up a new one today I thought I had better come up with a better backup strategy.  In the past I&#8217;ve just asked EC2 to create either AMI or EBS snapshots, but they aren&#8217;t done automatically and it&#8217;s not a very elegant solution.  </p>
<p>Much better would be simply to backup to S3.  This is easily done through a little script that sits in your /etc/cron.daily so that it is automatically called once every day.  But I&#8217;d like to have more than just one backup &#8211; I&#8217;d like some kind of automatic rotation of backups.  In the end I came up with the a reasonably cute idea, and that is to keep between 28 and 31 backups: ie, all the data that I&#8217;m backup up is pushed into a folder named after the day-of-the-month in an S3 bucket, so today (7th June 2013) all my backups are going into a folder named something like s3://mybackups/07   </p>
<p>In a month&#8217;s time (7th July 2013) this backup will be overwritten by the July 7th backup.  That&#8217;s not a bad solution really.  If you want longer backups you can hack the below script and have  two scripts &#8211; one for a one-backup-per-day strategy and also another copy of the script that stores by month name which essentially rotates by month.  That would give you daily backups for the past month, and monthly backups for the past year.  Useful.</p>
<p>In terms of your standard webserver you want to backup your /var/www (or wherever you keep your htdocs), along with any config info, so I also backup /etc/apache2 /etc/php5 /etc/mysql /etc/cron.daily.  Of course on top of that you&#8217;ll need a backup of your database which you can get by calling mysqldump.  Then compress the lot and chuck it up to s3.  You&#8217;ll want to use s3cmd for this.  Thankfully I found a script which I modified to do the rotations and use s3cmd to upload the resulting backups (original source: <a href="http://stnor.wordpress.com/2011/08/01/backing-up-ec2-mysql-and-configuration-files-to-s3/">http://stnor.wordpress.com/2011/08/01/backing-up-ec2-mysql-and-configuration-files-to-s3/</a>)</p>
<p>So first you&#8217;ll need a copy of s3cmd installing.  On ubuntu/debian that is a fairly straight-forward:</p>
<pre class="wp-code-highlight prettyprint linenums:1">
sudo apt-get install s3cmd
s3cmd --configure
</pre>
<p>This is important: Do NOT configure s3cmd with your root AWS credentials &#8211; yes it will work, but would you store your root server password in a plaintext file?  No, and your AWS credentials  give the holder access to unlimited resources, your billing details, your machine images, everything.  Just watch this <a href="http://www.youtube.com/watch?v=ySl1gdH_7bY">2-minute you-tube video on creating AWS users &#038; groups with restricted access</a>, create a new user/group that only has access to S3 and use those credentials to configure s3.  It&#8217;s not hard, it&#8217;ll take you just a few minutes to do.  Then wait a couple more minutes for these new credentials to propagate through amazon&#8217;s systems and you&#8217;re ready to carry on.  Ok, safety first rant over!  Let&#8217;s continue.</p>
<p>Then modify the following script to suit your purposes:</p>
<ol>
<li>1. Specify the names of your mysql databases in that you need backing up in DATABASES </li>
<li>2. Add mysql login details for each DB in the format: databasename_USER and databasename_PW</li>
<li>3. Specify which directories to backup in DIRECTORIES &#8211; for me that is config stuff and my /var/www</li>
<li>4. Specify the name of the s3 bucket you&#8217;re going to backup into in the S3_BUCKET_URL</li>
</ol>
<p>The script also assumes you have tar and gzip installed, but I&#8217;ll assume you can figure that bit out for yourself.</p>
<pre class="wp-code-highlight prettyprint linenums:1">
## Specify data base schemas to backup and credentials
DATABASES=&quot;wp myotherdb&quot;

## Syntax databasename as per above _USER and _PW
wp_USER=username
wp_PW=password
myotherdb_USER=username
myotherdb_PW=password

## Specify directories to backup (it&#039;s clever to use relaive paths)
DIRECTORIES=&quot;/var/www root etc/cron.daily etc/cron.monthly etc/apache2 etc/mysql etc/php5&quot; 

## Initialize some variables
DATE=$(date +%d)
BACKUP_DIRECTORY=/tmp/backups
S3_CMD=&quot;s3cmd&quot;

## Specify where the backups should be placed
S3_BUCKET_URL=s3://mybackupbucket/$DATE/

## The script
cd /
mkdir -p $BACKUP_DIRECTORY
rm -rf $BACKUP_DIRECTORY/*

## Backup MySQL:s
for DB in $DATABASES
do
BACKUP_FILE=$BACKUP_DIRECTORY/${DB}.sql
USER=$(eval echo \$${DB}_USER)
PASSWORD=$(eval echo \$${DB}_PW)
/usr/bin/mysqldump -v -u $USER --password=$PASSWORD -h localhost -r $BACKUP_FILE $DB 2&gt;&amp;1
gzip $BACKUP_FILE 2&gt;&amp;1
$S3_CMD put ${BACKUP_FILE}.gz $S3_BUCKET_URL 2&gt;&amp;1
done

## Backup of config directories
for DIR in $DIRECTORIES
do
BACKUP_FILE=$BACKUP_DIRECTORY/$(echo $DIR | sed &#039;s/\//-/g&#039;).tgz
tar zcvf ${BACKUP_FILE} $DIR 2&gt;&amp;1
$S3_CMD put ${BACKUP_FILE} $S3_BUCKET_URL 2&gt;&amp;1
done
</pre>
<p>Then, assuming you&#8217;ve called it something like backupToS3.sh, make it executable and test it:</p>
<pre class="wp-code-highlight prettyprint linenums:1">
chmod +x backupToS3.sh
sudo ./backupToS3.sh
</pre>
<p>Once you&#8217;ve ironed out any issues simply copy it over to /etc/cron.daily so that it runs daily:</p>
<pre class="wp-code-highlight prettyprint linenums:1">
sudo cp backupToS3.sh /etc/cron.daily
</pre>
<p>Now, the above script does daily backups, but if you want to do monthly backups you simply need to make a copy of the file (since you&#8217;ll likely want a daily and monthly backup rotation) and edit the DATE variable to use months rather than day-of-the-month.  If you use the month number you&#8217;ll probably want to either prefix the month number with the word &#8220;month&#8221;, or pop them into a subdirectory called &#8220;monthly&#8221;, alternatively you could use the month name, for instance:</p>
<pre class="wp-code-highlight prettyprint linenums:1">
DATE=$(date +%m)        // month number
DATE=$(date +%b)        // 3-letter month name
DATE=$(date +%B)        // full month name
DATE=$(date +%m-%B)     // month number, dash, full month name
</pre>
<p>Then make it executable and test it as you did the previous script, and then copy it into cron.monthly:</p>
<pre class="wp-code-highlight prettyprint linenums:1">
sudo cp monthlyBackupToS3.sh /etc/cron.monthly
</pre>
<p>Presumably this will then fire on the first of the month (I haven&#8217;t checked), but you could always put it in cron.daily so that monthly backup is from the last day of its month (for previous months, the present month would be up to date).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/automatic-backup-of-mysql-database-to-s3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Browser auto-fit fix</title>
		<link>http://www.matt-helps.com/android-browser-auto-fit-fix</link>
		<comments>http://www.matt-helps.com/android-browser-auto-fit-fix#comments</comments>
		<pubDate>Thu, 06 Jun 2013 10:14:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[android browser]]></category>
		<category><![CDATA[auto-fit]]></category>
		<category><![CDATA[dolphin]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[fudge]]></category>
		<category><![CDATA[transparent pixel]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=254</guid>
		<description><![CDATA[The built in Android browser for versions 4.something onwards have an annoying little feature called auto-fit turned on automatically. What this does is fix the width of the primary text column to be as wide as the device when zoomed in which leads to some awful artefacts &#8211; many times the text appears to only [...]]]></description>
				<content:encoded><![CDATA[<p>The built in Android browser for versions 4.something onwards have an annoying little feature called auto-fit turned on automatically.  What this does is fix the width of the primary text column to be as wide as the device when zoomed in which leads to some awful artefacts &#8211; many times the text appears to only fill half or a third of the column it was designed for.</p>
<p>The fixes that people are fudging in aren&#8217;t very safe at all: the suggestion is to put set a transparent 1&#215;1 pixel .gif file as the background of the relevant tags, and one solution I saw applied to to every tag using the * selector.</p>
<p>The problem with using this technique is that:</p>
<p>1.  It&#8217;s another file to download.<br />
2.  The performance hit on redraw times in IE8 and lower essentially breaks your website if you&#8217;re using it for every p tag, (or worse for them all)</p>
<p>The problem is that CSS doesn&#8217;t allow detection of auto-fit, or Android (rightly, and Android Chrome doesn&#8217;t have auto-fit either).  So here was my solution:</p>
<pre class="wp-code-highlight prettyprint linenums:1">/* work around mobile device auto-fitting */
@media only screen and (max-device-width: 800px) {
   #content p {
        background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==); 
        background-repeat:repeat;
    }
}
</pre>
<p>On my website, &#8216;#content&#8217; is where the &#8216;p&#8217; tags reside that are being auto-fitted, naturally you&#8217;d need to change this.  &#8216;body&#8217; will work, yes, but the more specific the lower the impact on redraw time. </p>
<p>What this does is :</p>
<p>1. Embed the 1&#215;1 pixel directly into the style-sheet as a data-insert rather than having the browser do another file load, and<br />
2. Only target smaller devices (since auto-fit only applies to smaller devices), hence ruling out the IE8 which is desktop only.  </p>
<p>Alternatively you could apply this to everything and then override it in your IE8 stylesheet, but why inflict this fudge on desktop users at all?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/android-browser-auto-fit-fix/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Using PHP DOMDocument to remove nodes</title>
		<link>http://www.matt-helps.com/code-snippet-using-php-domdocument-to-remove-nodes</link>
		<comments>http://www.matt-helps.com/code-snippet-using-php-domdocument-to-remove-nodes#comments</comments>
		<pubDate>Mon, 25 Mar 2013 15:20:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=242</guid>
		<description><![CDATA[I needed to strip out some DOM nodes from a HTML file. I would use SED but some of the tags are multiline, and SED/regexes really don&#8217;t understand HTML/XML and get really confused if you&#8217;re using nested tags of the same type. In the end I decided to use PHP&#8217;s built in DOMDocument functions. It [...]]]></description>
				<content:encoded><![CDATA[<p>I needed to strip out some DOM nodes from a HTML file.  I would use SED but some of the tags are multiline, and SED/regexes really don&#8217;t understand HTML/XML and get really confused if you&#8217;re using nested tags of the same type.  In the end I decided to use PHP&#8217;s built in DOMDocument functions.   It is fairly strict and refuses to load if the HTML isn&#8217;t perfectly formed, so first I ran it through PHP&#8217;s tidy &#8211; this isn&#8217;t installed by default but you can add it in with a:</p>
<p><code>sudo apt-get install php5-tidy</code></p>
<p>So first fix the malformed HTML:</p>
<p><code>$html = file_get_contents("myfile.html");<br />
$config = array(<br />
&nbsp;&nbsp;&nbsp;&nbsp;'indent'         => true,<br />
&nbsp;&nbsp;&nbsp;&nbsp;'output-xhtml'   => true,<br />
&nbsp;&nbsp;&nbsp;&nbsp;'wrap'           => 0);<br />
$tidy = tidy_parse_string($html, $config, 'UTF8');<br />
$tidy->cleanRepair();</code></p>
<p>And then load it into DOMDocument:</p>
<p><code>$doc = new DOMDocument();<br />
$doc->loadHTML($tidy)</code></p>
<p>Then it&#8217;s just a matter of ripping out the tags you don&#8217;t want.  Note how we&#8217;re iterating through the $nodes variable &#8211; it MUST be done this way if you&#8217;re planning on removing the nodes (as I am) because as they&#8217;re removed they also disappear from the collection.  A foreach will do some odd stuff &#8211; probably terminate after the first node, and a for-loop will have you missing every other node.  Instead, just remove the first child until there are no children:</p>
<p><code>$nodes = $doc->getElementsByTagName("script");<br />
while ($nodes->length > 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;$node = $nodes->item(0);<br />
&nbsp;&nbsp;&nbsp;&nbsp;remove_node($node);<br />
}<br />
function remove_node(&#038;$node) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;$pnode = $node->parentNode;<br />
&nbsp;&nbsp;&nbsp;&nbsp;remove_children($node);<br />
&nbsp;&nbsp;&nbsp;&nbsp;$pnode->removeChild($node);<br />
}<br />
function remove_children(&#038;$node) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;while ($node->firstChild) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ($node->firstChild->firstChild) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remove_children($node->firstChild);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$node->removeChild($node->firstChild);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/code-snippet-using-php-domdocument-to-remove-nodes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu recovery mode: mounting read-only filesystem</title>
		<link>http://www.matt-helps.com/ubuntu-recovery-mode-mounting-read-only-filesystem</link>
		<comments>http://www.matt-helps.com/ubuntu-recovery-mode-mounting-read-only-filesystem#comments</comments>
		<pubDate>Tue, 20 Nov 2012 09:46:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[grub]]></category>
		<category><![CDATA[mount -o remount]]></category>
		<category><![CDATA[read-only]]></category>
		<category><![CDATA[recovery mode]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[xorg.conf]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=235</guid>
		<description><![CDATA[I recently made some changes to my /etc/X11/xorg.conf file which backfired and Ubuntu (12.10 in this case) would crash while loading the operating system. It should be simple enough to undo the last change you made to a system file when booting into recovery mode, but alas it is not straightforward because when booting into [...]]]></description>
				<content:encoded><![CDATA[<p>I recently made some changes to my /etc/X11/xorg.conf file which backfired and Ubuntu (12.10 in this case) would crash while loading the operating system.</p>
<p>It should be simple enough to undo the last change you made to a system file when booting into recovery mode, but alas it is not straightforward because when booting into recovery mode the filesystem is mounted as read-only!  Oh dear!</p>
<p>1.  Boot into &#8220;Ubuntu (Recovery Mode)&#8221;<br />
2.  From the recovery menu drop to a root shell.<br />
3.  Enter the following command to remount your filesystem as read-write:</p>
<p><code>mount -o remount,rw /</code></p>
<p>4.  Make the required changes to your operating system and then exit/reboot/whatever.</p>
<p>Hope that helps someone out there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/ubuntu-recovery-mode-mounting-read-only-filesystem/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>apache2ctl status no permission for /server-status</title>
		<link>http://www.matt-helps.com/apache2ctl-status-no-permission-for-server-status</link>
		<comments>http://www.matt-helps.com/apache2ctl-status-no-permission-for-server-status#comments</comments>
		<pubDate>Thu, 09 Feb 2012 20:29:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[/server-status]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[apache2ctl]]></category>
		<category><![CDATA[forbidden]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=219</guid>
		<description><![CDATA[Today I was having a real problem. Every minute on my linux box I call apache2ctl status via a cronjob and this gives me various stats on how many servers are used/free. Useful. But upon moving some old websites off the server the above call began to fail &#8211; I&#8217;d get the error message Forbidden [...]]]></description>
				<content:encoded><![CDATA[<p>Today I was having a real problem.  Every minute on my linux box I call </p>
<p><code>apache2ctl status </code></p>
<p>via a cronjob and this gives me various stats on how many servers are used/free.  Useful.  But upon moving some old websites off the server the above call began to fail &#8211;  I&#8217;d get the error message</p>
<p><code>Forbidden<br />
You don't have permission to access /server-status on this server.</code></p>
<p>There are lots of solutions around the web (some about SELinux, some about setting allow/deny in an apache config file under the location /server-status namespace), none of which actually solved my problem.  They did give enough hints for me to work out what was going on!  You see when you make the above call to apache2ctl it then (through mod_status) requests /server-status <b>on the default website</b> on your webserver.  Now if you only have one site then that should be pretty easy to work out which one it is going to, but if you&#8217;re hosting multiple sites then its not quite as obvious.  For me it was the first site in the /etc/apache2/sites-enabled directory, (or you can find which one it is by visiting the webserver via its IP address rather than through a domain name as it is the domain name that is used to direct the browser call to a specific site that you host &#8211; if you visit your webserver via its IP address it doesn&#8217;t really know what to serve you so you&#8217;re sent to the default site).</p>
<p>So my default site was refusing to serve /server-status.  I couldn&#8217;t think why this was until I visited my .htaccess file and realised that I was using mod_rewrite to rewrite any www.mysite.com calls to mysite.com like so:</p>
<p><code>RewriteEngine On<br />
RewriteCond %{HTTP_HOST} !^mysite\.com$<br />
RewriteRule (.*) http://mysite.com/$1 [R=301,L]</code></p>
<p>The answer then was to pop in an exclusion for /server-status so that it would be unaffected by mod_rewrite:</p>
<p><code>RewriteEngine On<br />
RewriteCond %{HTTP_HOST} !^mysite\.com$<br />
RewriteCond %{REQUEST_URI}  !^/server-status<br />
RewriteRule (.*) http://mysite.com/$1 [R=301,L]</code></p>
<p>And hey presto it works!  Hurrah!</p>
<p><strong>UPDATE</strong>: I&#8217;ve found a better version.  I host the site on a virtual server (amazon&#8217;s ec2 stuff) and that means I often need to test a new instance of the server using either the IP address or a funny amazon made up name like ec2-99-98-97-96.compute-7.amazonaws.com, but if I stick that in the address bar of a browser the .htaccess reroutes it to mysite.com (the one that is live), so really I just need to slice off the www from any HTTP_HOST that is found and keep an exception in there for /server-status so that <em>apache2ctl status</em> doesn&#8217;t complain.  Here&#8217;s what it looks like now:</p>
<p><code>RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]<br />
RewriteCond %{REQUEST_URI} !^/server-status<br />
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]</code></p>
<p>If you wanted to be ultra portable you could put an <em>if</em> around it:</p>
<p><code>&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]<br />
RewriteCond %{REQUEST_URI} !^/server-status<br />
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]<br />
&lt;/IfModule&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/apache2ctl-status-no-permission-for-server-status/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dnscurl.pl name lookup timed out (Amazon Route53)</title>
		<link>http://www.matt-helps.com/dnscurl-pl-lookup-timed-out-amazon-route53</link>
		<comments>http://www.matt-helps.com/dnscurl-pl-lookup-timed-out-amazon-route53#comments</comments>
		<pubDate>Wed, 09 Nov 2011 13:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[create hosted zone]]></category>
		<category><![CDATA[Curl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Route53]]></category>
		<category><![CDATA[time out]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=214</guid>
		<description><![CDATA[Had some problems this morning migrating one of my domains routing over to route53, and google can&#8217;t find anyone talking about this issue so (as is my policy) I thought I had better make the information available for other people facing the same issue. I was attempting to use dnscurl.pl to create a hosted zone [...]]]></description>
				<content:encoded><![CDATA[<p>Had some problems this morning migrating one of my domains routing over to route53, and google can&#8217;t find anyone talking about this issue so (as is my policy) I thought I had better make the information available for other people facing the same issue.  I was attempting to use dnscurl.pl to create a hosted zone but would come back with the error:</p>
<p><code>curl: (6) name lookup timed out<br />
Ouch, curl --progress-bar -I --max-time 5 --url https://route53.amazonaws.com/date --insecure failed with exit status 6</code></p>
<p>I couldn&#8217;t work out whether it mean that some sort of insecurity had made it fail (please use quotes to show where the command ends in future!).  So I ran the command above (from curl onwards) on its own to see what would happen:</p>
<p><code>curl --progress-bar -I --max-time 5 --url https://route53.amazonaws.com/date --insecure</code></p>
<p>&#8230;and sure enough, back came the error: </p>
<p><code>curl: (6) name lookup timed out</code></p>
<p>Ok, so its time out or the site isn&#8217;t up at all, not a security related issue.  I then browsed to https://route53.amazonaws.com/2011-05-05 (correct at the time of publishing) and found that it took more than 5 seconds, but that it did eventually connect.  It came back with:</p>
<p><code>UnknownOperationException/</code></p>
<p>So the site is working and up, but that it was taking quite a while.  In the above curl command we&#8217;re just giving it 5 seconds to respond which isn&#8217;t too long in the world of requests really, so I altered the above command to set the time-out to be 15 seconds rather than 5 and it worked fine (http code 200):</p>
<p><code>curl --progress-bar -I --max-time 15 --url https://route53.amazonaws.com/date --insecure</code></p>
<p>So somewhere in dnscurl.pl there&#8217;s a line similar to the above one but it only allows 5 seconds for a response, absolutely not long enough, so we need to change it to something more sensible, perhaps 20 or 30 seconds will do.  I&#8217;ve never played with perl, but how different can it be right?  I openned dnscurl.pl in an editor and found what looked like the right reference to CURL on line 190 (your results may vary), which looks like this:</p>
<p><code>my $curl_output_lines = run_cmd_read($CURL, "--progress-bar", "-I", "--max-time", "5", "--url", $url, "--insecure");</code></p>
<p>Simply changing the number 5 to a 30 seemed to solve the problem because the next time I called dnscurl.pl it all worked splendiferously. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/dnscurl-pl-lookup-timed-out-amazon-route53/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>monodroid: System.NullReferenceException in aresgen.exe</title>
		<link>http://www.matt-helps.com/monodroid-system-nullreferenceexception-in-aresgen-exe</link>
		<comments>http://www.matt-helps.com/monodroid-system-nullreferenceexception-in-aresgen-exe#comments</comments>
		<pubDate>Wed, 13 Jul 2011 15:48:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[aresgen.exe]]></category>
		<category><![CDATA[ImageView]]></category>
		<category><![CDATA[monodroid]]></category>
		<category><![CDATA[NullReferenceException]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=211</guid>
		<description><![CDATA[Just in case anyone else gets this uninformative error on their monodroid packaging, I got mine when I included an ImageView in my layout and this highlighted two problems. 1. I got the useless message because I hadn&#8217;t created an AndroidManifest.xml file, new projects don&#8217;t have them by default, so right-click on the project, go [...]]]></description>
				<content:encoded><![CDATA[<p>Just in case anyone else gets this uninformative error on their monodroid packaging, I got mine when I included an ImageView in my layout and this highlighted two problems.  </p>
<p>1. I got the useless message because I hadn&#8217;t created an AndroidManifest.xml file, new projects don&#8217;t have them by default, so right-click on the project, go to properties, then Android Manifest, and create one.  Fill in some details, the file needs to exist anyway, but you can get away with not having one until you put an ImageView in there.</p>
<p>2. Then when you rebuild the project you&#8217;ll get a sensible message out of aresgen.exe, which for me was an incorrectly spelt resource name.  My .png file was in the correct directory (Resources/Drawable) but I&#8217;d misspelled it by one letter.</p>
<p>Hope this saves someone else 30 minutes of searching around for answers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/monodroid-system-nullreferenceexception-in-aresgen-exe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Snippet: 301 redirect with args</title>
		<link>http://www.matt-helps.com/code-snippet-301-redirect-with-args</link>
		<comments>http://www.matt-helps.com/code-snippet-301-redirect-with-args#comments</comments>
		<pubDate>Wed, 06 Jul 2011 14:13:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[News Comment]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=207</guid>
		<description><![CDATA[If you ever need to redirect one domain name to another (using apache) and you need to do it in code you can simply create a .htacess file in the root of the folder that needs to be redirected and pop the standard 301 redirect in there. That doesn&#8217;t really help though if you want [...]]]></description>
				<content:encoded><![CDATA[<p>If you ever need to redirect one domain name to another (using apache) and you need to do it in code you can simply create a .htacess file in the root of the folder that needs to be redirected and pop the standard 301 redirect in there.  That doesn&#8217;t really help though if you want all the subdirectories of your old domain name to map to the new one, in which case pop the following in:</p>
<p><code>RewriteEngine On<br />
RewriteRule ^.*$ http://example.com/$0 [R=301,L]</code></p>
<p>Obviously switch example.com for your domain name and any requests which hit this folder or below will be redirected and keep the subfolders, filename and any arguments that were passed on.  You can also do some interesting things with the user agent.  For instance, if you want to only forward search engines you can add a rewrite condition such as the following which will only redirect altavista and lycos&#8217; search engine bots.  This is called cloaked forwarding and is usually against the terms and conditions of the search engines (ie, they will penalise you if they think you&#8217;re forwarding their bots but not users), so don&#8217;t do it unless you really hate that user agent!</p>
<p><code>RewriteEngine on<br />
RewriteCond %{HTTP_USER_AGENT} AltaVista [OR]<br />
RewriteCond %{HTTP_USER_AGENT} lycos<br />
RewriteRule ^.*$ http://example.com/$0 [R=301,L]</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/code-snippet-301-redirect-with-args/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a (free!) Amazon EC2 Micro instance for SVN</title>
		<link>http://www.matt-helps.com/using-a-free-amazon-ec2-micro-instance-for-svn</link>
		<comments>http://www.matt-helps.com/using-a-free-amazon-ec2-micro-instance-for-svn#comments</comments>
		<pubDate>Tue, 05 Jul 2011 10:00:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[amazon ec2]]></category>
		<category><![CDATA[free tier]]></category>
		<category><![CDATA[micro instance]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=205</guid>
		<description><![CDATA[Amazon do a free low power/memory/everything server called a Micro Instance. This is perfect for a bunch of websites that don&#8217;t get used much or even as an SVN server. Did I mention it was free? Setting up SVN looks tricky at the outset, but it really isn&#8217;t. Assuming you&#8217;ve already got an AWS account&#8230;: [...]]]></description>
				<content:encoded><![CDATA[<p>Amazon do a free low power/memory/everything server called a Micro Instance.  This is perfect for a bunch of websites that don&#8217;t get used much or even as an SVN server.  Did I mention it was free?</p>
<p>Setting up SVN looks tricky at the outset, but it really isn&#8217;t.  Assuming you&#8217;ve already got an AWS account&#8230;:</p>
<p>1. At the AWS management console &#8220;Launch Instance&#8221;, go to &#8220;community AMI&#8217;s&#8221; and select Alestic&#8217;s latest 32-bit Ubuntu build (you can find a list at alestic.com &#8211; click on the region you want (ie US-East 1), and then copy the AMI-1234567 and paste it into the search box on the &#8220;community AMI&#8221; AWS page.  There should be a star next to it to indicate that it will be free micro instance.  Click select to use that AMI.  </p>
<p>2.  Make sure the instance type is micro.  If you can&#8217;t select a micro instance then you need to use a different AMI (or a different region).  Then follow the options and set up the server as you would normally.  I won&#8217;t cover that here (there are plenty of tutorials out there for setting up an instance), though do get yourself an elastic IP and assign it to the new instance.</p>
<p>3.  Now your instance is running you need to open up TCP port 3690 for the SVN service to hear from the outside.  Find the security group that your instance is using, select it, click on the &#8220;inbound&#8221; tab,  and add a new rule: TCP, 3690, 0.0.0.0/0   and then click &#8220;add rule&#8221; and then &#8220;apply rule changes&#8221;.</p>
<p>4.  SSH into your instance and run the command &#8220;sudo apt-get install subversion&#8221; to install svn</p>
<p>5.  Create the directory to be used for subversion, for example &#8220;mkdir ~/svn&#8221;.  Your projects will go inside this folder.  The newer instances may require you sudo the commands if they don&#8217;t work &#8211; if you do use sudo you&#8217;ll need to change the permissions or ownership on the svn folder and subfolders. </p>
<p>6.  Create the project: &#8220;sudo svnadmin create ~/svn/myproject&#8221;, again you may need to set the permissions here &#8220;sudo chmod -R g+rws ~/svn&#8221; </p>
<p>7.  Under the new project directory (in the conf subfolder), edit svnserve.conf, remove the # before &#8220;anon-access&#8221; and change it to &#8220;none&#8221;, then remove the # before &#8220;auth-access&#8221; and &#8220;password-db&#8221; lines.  Remove the # before the &#8220;realm=&#8221; and give it a custom name.</p>
<p>8.  Edit passwd, add a line entry with the user name(s) and password(s) to be used for access.</p>
<p>9.  The SVN server will work locally, but we need it to respond to remote instructions, so set up the service by calling &#8220;svnserve -d -r ~/svn&#8221;    Now in your SVN client of choice commandline (why?), TortoiseSVN (windows) or RabbitSVN (linux) you can access via the SVN protocol: svn://[elastic ip address]/[project name]  using the username and password you set in the passwd file in step 8.</p>
<p>If your instance is rebooted you&#8217;ll need to SSH back in and repeat step 9.  In order to have it start automagically at boot up follow <a href="http://odyniec.net/articles/ubuntu-subversion-server/">Michał Wojciechowski&#8217;s instructions</a> under &#8220;Svnserve Initialization Script&#8221; which worked for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/using-a-free-amazon-ec2-micro-instance-for-svn/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>The wonder of xargs</title>
		<link>http://www.matt-helps.com/the-wonder-of-xargs</link>
		<comments>http://www.matt-helps.com/the-wonder-of-xargs#comments</comments>
		<pubDate>Thu, 30 Jun 2011 16:18:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[commandline pipe]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[repetitive commands]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://www.matt-helps.com/?p=202</guid>
		<description><![CDATA[If you&#8217;re ever sat at the linux commandline and had a repetitive task to complete on some files or directories then you&#8217;ll find &#8220;xargs&#8221; together with &#8220;find&#8221; a very useful combination. Find will return a list of files and directories, one per line which can be piped into xargs so that the same command can [...]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re ever sat at the linux commandline and had a repetitive task to complete on some files or directories then you&#8217;ll find &#8220;xargs&#8221; together with &#8220;find&#8221; a very useful combination.</p>
<p>Find will return a list of files and directories, one per line which can be piped into xargs so that the same command can be repeated on each file found, for instance:</p>
<p><code>find *.png</code></p>
<p>Will find .png files in the current directory.  If you wanted to change the permissions on just these .png files you could then pipe the output into xargs:</p>
<p><code>find *.png | xargs chmod 775 -v</code></p>
<p>The other day I wanted to change the permissions for a subfolder called &#8220;logs&#8221; that was in 10+ folders:</p>
<p><code>find . -maxdepth 2 -name "logs" | xargs chmod 755 -v</code></p>
<p>Naturally, one should test the find to see what is returned before piping the result into an xargs, especially if you&#8217;re doing something that cannot be easily undone (like rm for instance).</p>
<p>The final thing that is worth knowing about is argument replacement.  All the above examples assume that it is ok to put the result of the find command on the end of the xargs command, but if you were doing a rename operation or a copy this wouldn&#8217;t be the case.  In the case below I&#8217;ve used the -I xargs command to define an identifier which will be swapped for the result from find:</p>
<p><code>find . -maxdepth 2 -name "logs" | xargs -I xxx mv xxx xxx.l</code></p>
<p>So if one of the lines coming from find is &#8220;subfolder/logs&#8221; then the mv command executed will be:</p>
<p><code>mv subfolder/logs subfolder/logs.l</code></p>
<p>A useful tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matt-helps.com/the-wonder-of-xargs/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->