<?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>Ash Searle's Blog &#187; Tip</title>
	<atom:link href="http://hexmen.com/blog/category/tip/feed/" rel="self" type="application/rss+xml" />
	<link>http://hexmen.com/blog</link>
	<description>On programming, and other things...</description>
	<lastBuildDate>Mon, 03 Jan 2011 16:21:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Concatenating arrays in&#160;PHP</title>
		<link>http://hexmen.com/blog/2008/11/concatenating-arrays-in-php/</link>
		<comments>http://hexmen.com/blog/2008/11/concatenating-arrays-in-php/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 11:46:48 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=69</guid>
		<description><![CDATA[Just a quick post so I know where to look the next time I forget how to concatenate arrays in PHP. Use array_merge to concatenate two numerically-indexed arrays; not array_push and not the array union operator: +. $first = array('doh', 'ray', 'me'); $second = array('fah', 'soh', 'lah', 'te', 'do'); echo "Union: ", var_export($first + $second, [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick post so I know where to look the next time I forget how to concatenate arrays in PHP.</p>
<p>Use <a href="http://php.net/array_merge"><code>array_merge</code></a> to concatenate two numerically-indexed arrays; not <a href="http://php.net/array_push"><code>array_push</code></a> and not <a href="http://php.net/language.operators.array">the array union operator: <code>+</code></a>.</p>
<pre><code class="php">
$first = array('doh', 'ray', 'me');
$second = array('fah', 'soh', 'lah', 'te', 'do');

echo "Union: ", var_export($first + $second, true), "n";
echo "Merge: ", var_export(array_merge($first, $second), true), "n";

// array_push returns int, not an array:
array_push($first, $second);
echo "Push: ", var_export($first, true), "n";
</code></pre>
<p>The output:</p>
<pre>
Union: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 'te',
  4 => 'do',
)
Merge: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 'fah',
  4 => 'soh',
  5 => 'lah',
  6 => 'te',
  7 => 'do',
)
Push: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 =>
  array (
    0 => 'fah',
    1 => 'soh',
    2 => 'lah',
    3 => 'te',
    4 => 'do',
  ),
)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2008/11/concatenating-arrays-in-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Google: Where art thou time&#160;conversion?</title>
		<link>http://hexmen.com/blog/2008/10/google-where-art-thou-time-conversion/</link>
		<comments>http://hexmen.com/blog/2008/10/google-where-art-thou-time-conversion/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 14:51:20 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=60</guid>
		<description><![CDATA[I love the fact you can use Google to perform basic calculations and conversions. Once you know your currency codes, currency conversion couldn&#8217;t be simpler: 100 USD in GBP And Maths? As well as your basic arithmetic operators, it also handles has pretty natural syntax for &#8220;to the power of&#8221;. e.g. (2143/22) ^ (1/4). Trigonometry [...]]]></description>
			<content:encoded><![CDATA[<p>I love the fact you can use Google to perform basic calculations and conversions.</p>
<p>Once you know your currency codes, currency conversion couldn&#8217;t be simpler: <a href="http://www.google.com/search?q=100+gbp+in+usd&#038;btnG=Search">100 USD in GBP</a></p>
<p>And <span style="border-bottom: 1px dashed; cursor: help" title="I'm English!">Maths</span>?  As well as your basic arithmetic operators, it also handles has pretty natural syntax for &#8220;to the power of&#8221;. e.g. <a href="http://www.google.com/search?q=%282143%2F22%29+%5E+%281%2F4%29&#038;btnG=Search">(2143/22) ^ (1/4)</a>.  Trigonometry function use radians, so it also lets you use PI as a constant: <a href="http://www.google.com/search?q=sin%28PI%2F6%29&#038;btnG=Search">sin(PI/6)</a></p>
<p>They&#8217;ve even got a (really) nice way of handling percentages &#8211; you can even keep your commas and currencies in place &#8211; so calculating VAT is as simple as <a href="http://www.google.co.uk/search?q=£4%2C399.99+*+17.5%25&#038;btnG=Google+Search">£4,399.99 * 17.5%</a> (Note: I switched to the UK site for that one&#8230; If you run it on google.com the answer automatically gets converted to US dollars!  Of course, they let you override that by adding &#8221; in GBP&#8221; to the query string.)</p>
<p>You can do <a href="http://www.google.co.uk/search?q=13+stones+10+pounds+in+kg&#038;btnG=Search">weight conversions</a>, <a href="http://www.google.co.uk/search?q=20%2C000+leagues+in+feet&#038;btnG=Search">distances</a>, <a href="http://www.google.co.uk/search?hl=en&#038;q=2174KB+in+MB&#038;btnG=Search">storage capacity</a>&#8230; the list goes on.</p>
<p>So how come they don&#8217;t do time conversion?  I don&#8217;t mean <a href="http://www.google.co.uk/search?q=7200+minutes+in+days&#038;btnG=Search">minutes into days</a>, I mean converting one time zone into another.</p>
<p>I&#8217;m looking forward to reading about <a href="http://www.engadget.com/2008/10/14/live-from-apples-spotlight-turns-to-notebooks-event/">Apple&#8217;s new Macbooks</a>, and I know there&#8217;s a conference at 10AM Pacific Time, or 1PM Eastern Time&#8230; but I don&#8217;t know what time that is where I am.  I&#8217;m gutted Google can&#8217;t handle <a href="http://www.google.co.uk/search?q=10am+pst+in+gmt&#038;btnG=Search">10AM PST IN GMT</a>.</p>
<p>Oh well&#8230; I guess I&#8217;ll just have to wait.</p>
<p>Update: I&#8217;ve just discovered <a href="http://www.google.co.uk/thingstodo">Google&#8217;s things-to-do page</a> (UK only?) Amongst other things, it explains how to get the <em>current</em> time for any location: simply prefix the place-name with &#8220;time &#8221; &#8211; e.g. <a href="http://www.google.com/search?q=time+london">time london</a>.  That may be helpful if you know your geography?  Personally, I&#8217;ve no idea which cities are in PST, and I&#8217;d only be guessing that maybe New York is in EST?  (Google says EDT for New York &#8211; is it daylight savings time at the moment?)</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2008/10/google-where-art-thou-time-conversion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting git to work on OS X&#160;Tiger</title>
		<link>http://hexmen.com/blog/2008/08/getting-git-to-work-on-os-x-tiger/</link>
		<comments>http://hexmen.com/blog/2008/08/getting-git-to-work-on-os-x-tiger/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 11:58:10 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=58</guid>
		<description><![CDATA[If you haven&#8217;t heard of git yet, it&#8217;s quickly becoming the preferred version-control system for tons of open-source projects, including the twin suns of ruby on rails and prototype. In fact, if you keep your eye on the github blog you&#8217;ll see a steady stream of well-known projects moving over to git, as diverse as [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t heard of <a href="http://en.wikipedia.org/wiki/Git_(software)">git</a> yet, it&#8217;s quickly becoming the preferred version-control system for tons of open-source projects, including the twin suns of <a href="http://github.com/rails/rails/tree/master">ruby on rails</a> and <a href="http://github.com/sstephenson/prototype/tree/master">prototype</a>.</p>
<p>In fact, if you keep your eye on the <a href="http://github.com/blog">github blog</a> you&#8217;ll see a steady stream of well-known projects moving over to git, as diverse as the <a href="http://github.com/joshuaclayton/blueprint-css/tree/master">Blueprint CSS framework</a> and the <a href="http://github.com/ghc-hq/ghc/tree/master">Haskell compiler</a>.</p>
<p>Basically, if <em>git</em> was a stock-market commodity, analysts would be issuing <strong>strong buy</strong> recommendations left, right and centre.  Git&#8217;s <a href="http://en.wikipedia.org/wiki/The_Tipping_Point">tipping-point</a> has arrived.</p>
<h3>How to play</h3>
<p><em>If you&#8217;ve arrived here via search-engine, it&#8217;s probably because you&#8217;re trying to work around errors like <strong>Can&#8217;t locate Error.pm</strong> or <strong>Can&#8217;t locate SVN/Core.pm</strong>.  Read on&#8230;</em></p>
<p>I already had macports installed, but if you haven&#8217;t, follow the <a href="http://www.macports.org/install.php">macports install instructions</a> &#8211; we&#8217;ll be using macports to download and install git as it&#8217;s supposed to be simpler than building from source.</p>
<p>If you&#8217;ve had macports installed a while, make sure it&#8217;s up to date:</p>
<pre><code>
$ sudo port selfupdate
</code></pre>
<p>We want to use git to connect to subversion repositories as well, so we&#8217;ll just check that&#8217;s possible:</p>
<pre><code>
$ port list variant:svn
git-core        @1.6.0  devel/git-core
subversion      @1.5.1  devel/subversion
</code></pre>
<p>I already had subversion installed but through trial-and-error found I needed to reinstall it with perl-bindings (git must be using perl scripts to talk to subversion&#8230;)  Note: I&#8217;m using the <code>-f</code> flag to force it to reinstall, you might want to try without first, just to see what conflicts it brings up:</p>
<pre><code>
$ sudo port uninstall -f subversion-perlbindings
$ sudo port install -f subversion-perlbindings
</code></pre>
<p>Next, we install git:</p>
<pre><code>
# This may take a while to install with all its dependencies:
$ sudo port install git-core +svn
</code></pre>
<p>And finally, we check it works:</p>
<pre><code>
$ mkdir myproject; cd myproject;

# Check your PATH's set properly, this should output:
# fatal: Not a git repository
$ git svn

# If that's OK... clone a repository:
$ git svn clone <em>http://example.com/svn/project/trunk</em>
</code></pre>
<h3>Can&#8217;t locate Error.pm</h3>
<p>If you&#8217;re getting <em>Can&#8217;t locate Error.pm</em> or <em>Can&#8217;t locate SVN/Core.pm</em> you should immediately try:</p>
<pre><code>
$ PATH=/opt/local/bin:$PATH git svn</code></pre>
<p>If that works, you know it&#8217;s just a PATH problem.  It&#8217;s something to do with Apple&#8217;s perl install having slightly kooky ideas about where to store perl libraries.</p>
<p>If you&#8217;re still getting complaints about Error.pm, you need to install the CPAN module &#8211; and we&#8217;re going to use the /opt/local/bin instance of cpan, to make sure things go in the right place for us:</p>
<pre><code>
$ sudo /opt/local/bin/cpan -i lib::Error
</code></pre>
<p>Cross your fingers, and try again:</p>
<pre><code>
$ PATH=/opt/local/bin:$PATH
$ git svn clone <em>http://example.com/svn/project/trunk</em>
</code></pre>
<p>If things are working, git will spend a while cloning the subversion repository by pulling out every single revision so you can have a complete set of revisions (including deltas), ready for you to refer to with lightning-speed regardless of internet connectivity.  Which is nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2008/08/getting-git-to-work-on-os-x-tiger/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SVN log message encoding&#160;problem</title>
		<link>http://hexmen.com/blog/2008/08/svn-log-message-encoding-problem/</link>
		<comments>http://hexmen.com/blog/2008/08/svn-log-message-encoding-problem/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 11:03:12 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[Subversion]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=55</guid>
		<description><![CDATA[It&#8217;s good practice to put useful commentary in the log message whenever you commit code to a repository. Today, I wrote a log message about centigrade and farenheit conversions, using the proper degree symbol °, but this triggered an encoding problem, resulting in an error message: macbook:~/projects/smarty ash$ svn ci plugins/function.temperature.php svn: Commit failed (details [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s good practice to put useful commentary in the log message whenever you commit code to a repository.</p>
<p>Today, I wrote a log message about centigrade and farenheit conversions, using the proper degree symbol °, but this triggered an encoding problem, resulting in an error message:</p>
<pre>
macbook:~/projects/smarty ash$ svn ci plugins/function.temperature.php
svn: Commit failed (details follow):
<b>svn: Can't convert string from native encoding to 'UTF-8':</b>
svn: Tweak: altered temperature title attribute so it contains both farenheight AND
centigrade.  e.g. "88?\194?\176F or 17?\194?\176C".  The order is switched depending on user
preference.
--This line, and those below, will be ignored--

M    function.temperature.php

svn: Your commit message was left in a temporary file:
svn:    '/Users/ash/projects/propagandr/smarty/plugins/svn-commit.tmp'
</pre>
<p>It didn&#8217;t take long to realize although my editor (vim) was configured to use UTF-8, the subversion command-line client had no way of knowing that.</p>
<p>One way of stopping this happening again would be to set my locale permanently so the character-type is UTF-8 (e.g. <code>export LC_CTYPE=en.UTF-8</code>.)  But, as a short-term one-off fix, avoiding retyping the log message (and a little off-topic: remembering subversion ignores filenames mentioned in log messages, forcing you to reenter them on the command-line again) &#8211; the simple fix was:</p>
<pre>ash$ <code>LC_CTYPE=en_GB.UTF-8 svn ci -F plugins/svn-commit.tmp plugins/function.temperature.php</code></pre>
<p>Worked like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2008/08/svn-log-message-encoding-problem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tweaking PNG transparency with&#160;ImageMagick</title>
		<link>http://hexmen.com/blog/2008/07/tweaking-png-transparency-with-imagemagick/</link>
		<comments>http://hexmen.com/blog/2008/07/tweaking-png-transparency-with-imagemagick/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 12:21:32 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=54</guid>
		<description><![CDATA[This took me way too long to find out, so I thought I&#8217;d blog here and hopefully save someone else some time. ImageMagick is a great swiss-army-knife type tool, with a shed-load of options for converting and combining images. Unfortunately, the sheer number of options can make it a bit time-consuming and frustrating trying to [...]]]></description>
			<content:encoded><![CDATA[<p>This took me way too long to find out, so I thought I&#8217;d blog here and hopefully save someone else some time.</p>
<p><a href="http://imagemagick.org">ImageMagick</a> is a great swiss-army-knife type tool, with a <a href="http://imagemagick.org/script/command-line-options.php">shed-load of options</a> for converting and combining images.  Unfortunately, the sheer number of options can make it a bit time-consuming and frustrating trying to find the one you want.</p>
<p>My aim was simple: given a PNG, make the <em>whole thing</em> semi-transparent.</p>
<p>Searching Google using &#8220;transparent&#8221; and &#8220;opacity&#8221; drew a blank &#8211; all I got was instructions on how to set transparency for certain <em>colours</em> &#8211; not what I wanted to do.</p>
<p>The word I was missing was &#8220;alpha&#8221;, and the magic incantation for changing the opacity of the whole image is:</p>
<pre><code>
convert input.png -channel Alpha -evaluate Divide 2 output.png
</code></pre>
<p>In my case, I wanted to set the PNG to be 50% transparent (hence &#8220;Divide 2&#8243;.)  Of course, you can change that number to whatever works for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2008/07/tweaking-png-transparency-with-imagemagick/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

