<?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>chrisadams.me.uk &#187; Coding</title>
	<atom:link href="http://chrisadams.me.uk/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisadams.me.uk</link>
	<description>Hoping to think more clearly, through thinking out loud</description>
	<lastBuildDate>Sun, 29 Aug 2010 09:29:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>There&#8217;s no need to type your password when you restart Apache, really&#8230;</title>
		<link>http://chrisadams.me.uk/2010/08/14/no-need-to-type-your-password-with-apache/</link>
		<comments>http://chrisadams.me.uk/2010/08/14/no-need-to-type-your-password-with-apache/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 23:08:13 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ssg]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=380</guid>
		<description><![CDATA[When you're developing with PHP on a mac, if you're not using MAMP, you'll often end up having to do a lot of manual restarts when you make changes to how you've set up Apache (assuming you haven't joined all the cool kids and moved onto Nginx yet...). This usually involves calling up a terminal [...]]]></description>
			<content:encoded><![CDATA[<p>When you're developing with PHP on a mac, if you're not using MAMP, you'll often end up having to do a lot of manual restarts when you make changes to how you've set up Apache (assuming you haven't joined all the cool kids and moved onto Nginx yet...). This usually involves calling up a terminal window and typing in the usual Apache restart command on OS X:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #c20cb9; font-weight: bold;">sudo</span> apachectl restart</pre></div></div>

<p>This isn't a really destructive command, and having to type in your admin password every time when doing this in development on your own computer gets old quickly. It's also error prone. Surely there's a better way?</p>
<p>Fortunately, when browsing the <a href="http://geoffhankerson.com/node/109">Aegir OS X install documentation</a>, I came across as handy fix to this problem. The Aegir hackers let Aegir handle server restarts in a fairly elegant fashion, by tweaking the <code>sudoers</code> file on your mac, which is basically a short list of who is allowed to do what on your machine. I've borrowed a few tricks, and adaprted them to use in my sudoers file here, and after showing it in full, I'll explain how it works.</p>
<p>Bear in mind, you can't edit the <code>sudoers</code> file directly - you need to use the <code>visudo</code> command, (this works as a precaution to stop this file getting screwed up by letting more than one person is edit it at a time for example).</p>
<p>Also, to make things more complex, you need to edit this inside the terminal, to you may need to force this by typing <code>EDITOR='vim'</code> first</p>
<p>Okay, now that's out the way, lets look at that file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="ssh" style="font-family:monospace;">  # Run as alias specification
&nbsp;
  # User privilege specification
  root    ALL=(ALL) ALL
  %admin  ALL=(ALL) ALL
&nbsp;
  # Uncomment to allow people in group wheel to run all commands
  # %wheel        ALL=(ALL) ALL
&nbsp;
  # Same thing without a password
  # %wheel        ALL=(ALL) NOPASSWD: ALL
  %staff          ALL=(ALL) NOPASSWD: /usr/sbin/apachectl
  # Samples
  # %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
  # %users  localhost=/sbin/shutdown -h now</pre></td></tr></table></div>

<p>Lets look at the first lines, with <code>root</code> and <code>%wheel</code>. If you're even bothering to read this, the chances are you know that <code>root</code> refers to the all powerful user that can do anything on a system, but you may not be familiar with the percent prefix on <code>%admin</code> nor the <code>ALL=(ALL) ALL</code>. The <code>%admin</code> basically means 'anyone in the admin group, but the <code>ALL=(ALL) ALL</code> is somewhat more cryptic. The rough translation goes like this though:</p>
<blockquote>
<p>from <em>ALL</em> terminals, let these users run <em>ALL</em> commands and as <em>ALL</em> of the users in the system.</p>
</blockquote>
<p>We see the same trick visible again with the <code>%wheel</code> group, but the line starting with <code>%staff</code> deserves more attention:</p>

<div class="wp_syntax"><div class="code"><pre class="ssh" style="font-family:monospace;">  %staff          ALL=(ALL) NOPASSWD: /usr/sbin/apachectl</pre></div></div>

<p>Translated, this means:</p>
<blockquote>
<p>for ALL members in the <em>staff group</em>, let them use ALL terminals, to run the command <code>/usr/sbin/apachectl</code> as ALL users (in particular, the root user) without needing a password (that's the NOPASSWD: bit).</p>
</blockquote>
<p>This is the line that lets us run the familiar <code>sudo apachectl restart</code> without needing to constantly type our password credentials in.</p>
<p>Which over the course of a year, will easily save you tons of typing over the year, and leave some time to skim the <a href="http://www.gratisoft.us/sudo/sudoers.man.html"><code>sudoers</code> man page</a>, and suggest a similar trick here for others to try.</p>
<p>Over to you now...</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/08/14/no-need-to-type-your-password-with-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get back into Drupal site if you&#8217;ve locked yourself out</title>
		<link>http://chrisadams.me.uk/2010/08/10/how-to-get-back-into-drupal-site-if-youve-locked-yourself-out/</link>
		<comments>http://chrisadams.me.uk/2010/08/10/how-to-get-back-into-drupal-site-if-youve-locked-yourself-out/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 23:35:29 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[drupal php web development]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=376</guid>
		<description><![CDATA[A few posts back, I shared a one liner to get you back into a WordPress site if you manage to lock yourself out, and forget your database password. Assuming you've access to the command line and drush, you can pull a similar trick with Drupal, by typing the following query in: drush sql-query &#34;update [...]]]></description>
			<content:encoded><![CDATA[<p>A few posts back, I shared a one liner to get you back into a WordPress site if you manage to lock yourself out, and forget your database password.</p>
<p>Assuming you've access to the command line and drush, you can pull a similar trick with Drupal, by typing the following query in:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    drush sql-query <span style="color: #ff0000;">&quot;update users set pass=md5('NEWPASSWORD') where uid = 1;&quot;</span></pre></div></div>

<h3>What's happening here?</h3>
<p>The first thing we're doing is calling drush sql-query, a sub-command of drush.</p>
<p>If you haven't used Drush yet, you really, really should. It totally transforms how you work with Drupal, by making the kinds of tasks you had to do manually through the website possible from a commandline, which means yes, you can get up to all kinds of handy scripting shenanigans.</p>
<p>As you might expect drush sql-query lets you pass a single arbitrary query to the database described in your site's settings file, without you needing to fish the credentials out yourself. Here's our query too now:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"> <span style="color: #990099; font-weight: bold;">update</span> users <span style="color: #990099; font-weight: bold;">set</span> pass<span style="color: #CC0099;">=</span><span style="color: #000099;">md5</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'NEWPASSWORD'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">where</span> uid <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span></pre></div></div>

<p>In short, we're <em>updating</em> the <em>users</em> table in the Drupal database, by <em>setting</em> the <em>pass_word value for the the first user id (_where uid=1</em>), to a <em>md5 hash</em> of the phrase <em>NEWPASSWORD</em>.</p>
<p>If you don't haves access to drush, nor the command line, but you still can change a file over SFTP, you can to the same by adding a snippet like this on to the site:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$doh_forgot_my_password</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update users set pass=md5('NEWPASSWORD') where uid = 1;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Of course you really should be paramaterizing this like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$doh_forgot_my_password</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;update users set pass=md5('<span style="color: #009933; font-weight: bold;">%s</span>') where uid = <span style="color: #009933; font-weight: bold;">%d</span>;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;NEWPASSWORD&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But this given the fact that this snippet should only existing in a template for 15-20 seconds <em>at the most</em> you'd probably be forgiven for taking the short cut...</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/08/10/how-to-get-back-into-drupal-site-if-youve-locked-yourself-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick heads up on a super handy cheat sheet for Drupal</title>
		<link>http://chrisadams.me.uk/2010/08/08/quick-heads-up-on-a-super-handy-cheat-sheet-for-drupal/</link>
		<comments>http://chrisadams.me.uk/2010/08/08/quick-heads-up-on-a-super-handy-cheat-sheet-for-drupal/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 19:11:10 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[drupal php web development]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=357</guid>
		<description><![CDATA[I'm working with Drupal a lot at work now, and in the process of creating my last post, I stumbled across this cheat sheet for developing with Drupal. I had no idea could pull ddebug_backtrace() to get an instant stacktrace, or DARGS() to see the arguments being passing into a function at any point, or [...]]]></description>
			<content:encoded><![CDATA[<p>I'm working with Drupal a lot at work now, and in the process of creating my last post, I stumbled across this <a href="http://ratatosk.backpackit.com/pub/1836982-debugging-drupal">cheat sheet for developing with Drupal</a>.</p>
<p>I had no idea could pull <code>ddebug_backtrace()</code>  to get an instant stacktrace, or <code>DARGS()</code> to see the arguments being passing into a function at any point, or <code>DD()</code> to log directly to a text file (which you can tail in a terminal window to see stuff as it happens).</p>
<p>Now, if only Simpletest wasn't so depressingly slow...</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/08/08/quick-heads-up-on-a-super-handy-cheat-sheet-for-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to setup Snow Leopard for LAMP development and debugging</title>
		<link>http://chrisadams.me.uk/2010/08/08/how-to-setup-snow-leopard-lamp-for-debugging/</link>
		<comments>http://chrisadams.me.uk/2010/08/08/how-to-setup-snow-leopard-lamp-for-debugging/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 19:00:23 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=358</guid>
		<description><![CDATA[Over this weekend, I've been looking at ways to make it easier for me to work with PHP, largely because I've been using it more and more at work, and I've felt spoilt by the tools available when using Ruby, like the [ruby debugger], or when playing with Django or Twisted, python's own interactive pdb [...]]]></description>
			<content:encoded><![CDATA[<p>Over this weekend,  I've been looking at ways to make it easier for me to work with PHP, largely because I've been using it more and more at work, and I've felt spoilt by the tools available when using Ruby, like the [ruby debugger], or when playing with Django or Twisted, python's own interactive <a href="http://aymanh.com/python-debugging-techniques" title="Python Debugging Techniques | Ayman Hourieh">pdb debugger</a>, so I decided to give <a href="http://www.bluestatic.org/software/macgdbp/" title="MacGDBp - Blue Static">MacGDBp</a> a try.</p>
<p>It's pretty handy - it allows you to step your code when things break, giving you an idea of what exactly is happening, under the hood, or letting you understand the actual a request takes through your code.</p>
<p>I'm not using MAMP, because where possible, I'm trying to minimise duplication of software on the my computer, and previously I've confused myself something horrible with trying to keep track of multiple instances of MySQL and Apache before, so if you're not using MAMP, following these instructions should help get you set up with a decent debugging tool, on Snow Leopard, and along the way get a fairly maintainable lamp stack, if you're not enamoured with MAMP.</p>
<h4>Get PHP 5.2</h4>
<p>This isn't strictly necessary, but right now, I've found PHP 5.2 to be less hassle when developing than 5.3, and for time being, Drupal and WordPress to be standardising on it first before moving to the newer version, which means I am too.</p>
<p>The best instructions I've found to do this are here <a href="http://boztek.net/blog/2009/10/07/install-lamp-stack-source-mac-os-x-106-snow-leopard-using-homebrew" title="Install LAMP stack from source on Mac OS X 10.6 Snow Leopard using Homebrew | boztek">PHP 5.2 for compatibility with Drupal</a>, and provide a good introduction to the amazing Homebrew, which you really should be using instead of Macports or Fink, if you're not already.</p>
<p>Lets get the hard commandline work out of the way first.</p>
<h4>Setup PEAR to complement Homebrew's PHP 5.2</h4>
<p>Just like how we have pip or easy_install with Python, CPAN for Perl, and Rubygems for Ruby, with PHP, we have PECL, and PEAR. PEAR is repository of PHP classes, like PHP Unit for unit testing, whereas PECL is a repository for C extensions like APC or Memcache, that help with performance, and caching, or link to other programs.</p>
<p>By default we do have PEAR and PECL installed, but in keeping with Homebrew's example of storing stuff in <code>/usr/local/</code> to avoid needless sudo'ing we're going to use our own versions of PEAR, using this handy one liner. What's happening here is that we're using curl to fetch the data at http://pear.php.net/go-pear, and then streaming it into the php command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    curl http:<span style="color: #000000; font-weight: bold;">//</span>pear.php.net<span style="color: #000000; font-weight: bold;">/</span>go-pear <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> php</pre></div></div>

<p>We'll be presented with some text, once we've entered our admin password, along the lines of:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">  Welcome to go-pear!
&nbsp;
  Go-pear will install the 'pear' command and all the files needed by
  it.  This command is your tool for PEAR installation and maintenance.
&nbsp;
  Go-pear also lets you download and install the following optional PEAR
  packages: PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2.
&nbsp;
  If you wish to abort, press Control-C now, or press Enter to continue: 
&nbsp;
  HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none::</pre></div></div>

<p>We probably don't need a proxy, so you can just hit enter, at which point we'll be asked the following:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">  Below is a suggested file layout for your new PEAR installation.  To
  change individual locations, type the number in front of the
  directory.  Type 'all' to change all of them or simply press Enter to
  accept these locations.
&nbsp;
   1. Installation prefix ($prefix) : .
   2. Temporary files directory     : $prefix/temp
   3. Binaries directory            : $prefix/bin
   4. PHP code directory ($php_dir) : $prefix/PEAR
   5. Documentation base directory  : $php_dir/docs
   6. Data base directory           : $php_dir/data
   7. Tests base directory          : $php_dir/tests
&nbsp;
  1-7, 'all' or Enter to continue:</pre></div></div>

<p>We want to change the installation prefix, to make sure we're putting this stuff into <code>/usr/local</code> - I found that I had to do this explicitly, because the default value for <code>$prefix</code>, ended up with me getting build errors.</p>
<p>Once we've added this, we'll get a load of text flying past as PEAR is built, and end up with some text saying something like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">    WARNING!  The include_path defined in the currently used php.ini does not
    contain the PEAR PHP directory you just specified:
&nbsp;
    If the specified directory is also not in the include_path used by
    your scripts, you will have problems getting any PEAR packages working.
&nbsp;
    Would you like to alter php.ini ? [Y/n] :</pre></div></div>

<p>Why <em>yes</em>, we <em>would</em> like this added. This will add this snippet to your <code>php.ini</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">    ;***** Added by go-pear
    include_path=&quot;.:/usr/local/PEAR&quot;
    ;*****</pre></div></div>

<p>One important thing here - now that you have this, make sure your PEAR</p>
<p>Now, any thing you add to pear will be available in future, so installing PHP Unit for unit testing is as simple as calling this on the commandline (note):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  pear <span style="color: #c20cb9; font-weight: bold;">install</span> phpunit<span style="color: #000000; font-weight: bold;">/</span>PHPUnit</pre></div></div>

<p>In a similar fashion to Rubygems, these libraries of classes are available by calling <code>require_once</code> as if you were in the path <code>/usr/local/PEAR</code>, so to pull in PHP Unit, you just type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  require_once <span style="color: #ff0000;">'PHPUnit/Framework.php'</span>;</pre></div></div>

<h4>Setup PECL with PHP 5.2</h4>
<p>Now that we have PEAR setup, we should spend a it of time on making PECL simple to administer without sudo. All I needed to do here was check that everything in <code>/usr/local/Cellar/php52/</code> belonged to my normal user account, by calling:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>php52<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>This does away with the need to compile things as root, and makes installing extensions like Memcache, Mongodb, APC, as simple as:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    pecl <span style="color: #c20cb9; font-weight: bold;">install</span> apc</pre></div></div>

<p>If you find yourself having trouble here, you may want to check the permissions on any extra directories created during the PECL installation process - I had a couple of issues because some extensions had been installed as root earlier when following <a href="http://www.cupcakewithsprinkles.com/setting-up-apache-php-python-mysql-on-mac-os-x-snow-leopard-10-6/#comments" title="Setting Up Apache-PHP-Python-MySQL on Mac OS X Snow Leopard 10.6 |  Cupcake With Sprinkles">Hunter Ford's instructions at Cupcake with Sprinkles</a>, which stopped my user account being able to install into the nested directory structure, because my account was trying to put files into directories owned by root.</p>
<h4>Fetch Xdebug</h4>
<p>If we didn't need xdebug, this would be all we needed, but sadly things aren't as simple as that. If we try calling something like <code>pecl install xdebug</code>, we DO get a version of debug installed, but it's not quite what we need, and doesn't seem to do anything useful. If we want this to work with <a href="http://www.bluestatic.org/software/macgdbp/" title="MacGDBp - Blue Static">MacGDBp</a>, we need to install the version compiled by the chaps at <a href="http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging">Active state from their Remote Debugging page</a>, that's designed to work with their own IDE, but also other tools. Once we've downloaded the tar file, we need to choose the correct version,</p>
<p>And then copy it to where the other extensions are:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #c20cb9; font-weight: bold;">cp</span> xdebug <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>php52<span style="color: #000000; font-weight: bold;">/</span>5.2.13<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>extensions<span style="color: #000000; font-weight: bold;">/</span>xdebug.so</pre></div></div>

<p>And make the relevant changes in our <code>php.ini</code> file for them, to point to the xdebug shared object (that's the <code>.so</code> suffix on extensions), and provide a few defaults as directed on the <a href="http://www.bluestatic.org/software/macgdbp/help.php" title="MacGDBp - Help - Blue Static">MacGDBp help page</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">; Adding xdebug</span>
  <span style="color: #000099;">zend_extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/usr/local/Cellar/php52/5.2.13/lib/php/extensions/xdebug.so</span>
  xdebug.remote_enable<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">1</span>
  xdebug.remote_autostart<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">1</span>
  xdebug.remote_host<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">localhost</span>
  xdebug.remote_port<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">9000</span></pre></div></div>

<p>In short we're telling xdebug to switch on by default, and and listen on localhost:9000 for any clients that want to connect to it when we want to inspect what's happening with code.</p>
<h4>Finally turning on MacGDBp</h4>
<p>Still with me? Good. At long last, we can finally start looking through code in our debugger. Fire up MacGDBp, and when you run your next PHP script, you should get to see something like this pic pilfered from Particle Tree's own post on this subject:</p>
<p><a href="http://chrisadams.me.uk/wordpress/wp-content/uploads/2010/08/particle-tree-macgdbp.png"><img src="http://chrisadams.me.uk/wordpress/wp-content/uploads/2010/08/particle-tree-macgdbp.png" alt="" title="particle-tree-macgdbp" width="655" class="alignright size-full wp-image-364" /></a></p>
<p>There's far more to this, but in general the key to using the debugger is knowing how to set breakpoints, and remembering that your choices in the blue buttons are (from left to right)</p>
<ul>
<li>stepping <em>into</em> functions to see what's happening as a request is passed from function to function</li>
<li>stepping <em>out</em> when you no longer need to see what's happening in a particular function</li>
<li>...and stepping <em>past</em> a particular function, without needing to look into its working at all</li>
</ul>
<p>The green button is a fast-forward button, to take you to the next breakpoint you might have in the code, and the green power button is analogous to a power button, to refresh a connection to the debugger. You really, really should look into <a href="http://particletree.com/notebook/silence-the-echo-with-macgdbp/" title="Particletree  » Silence The Echo with MacGDBp">this post here by Tim Sabat at Particle Tree</a>, and this one here by <a href="http://technosophos.com/content/debugging-your-php-code-xdebug-mamp-textmate-and-macgdbp-support" title="Debugging your PHP Code: XDebug on MAMP with TextMate and MacGDBp Support | TechnoSophos">Matt Butcher, at TechnoSophos</a>.</p>
<h4>Debugging without MacGDBp</h4>
<p>Of course, you don't need to use MacGDBp all the time, In most cases, just having a stack trace will help find the source of the error. Once you've got xdebug setup, you <em>should</em> get a handy track trace whenever you throw an error - if not, be sure to make sure you have the display errors setting set to 'on' in your php.ini setting (it should be around line 370 in your file, normally):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">    <span style="color: #000099;">display_errors</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> On</span></pre></div></div>

<p>By the time you've followed these steps, you should have an easier to main installation of the LAMP stack, with a simple way to install extra PHP libraries and C extensions, a couple much more effective ways to debug than simply typing <code>echo $variable</code> everywhere, and an ideal environment to get on with hacking on Drupal, WordPress and any other PHP code in future.</p>
<h4>Phew!</h4>
<p>This guide is largely a synthesis of earlier blog posts about this subject by <a href="http://justinhileman.info/articles/building-a-lamp-development-environment-on-snow-leopard" title="Building a LAMP development environment on Snow Leopard | justin hileman dot info">Justin Hileman</a>, <a href="http://technosophos.com/content/debugging-your-php-code-xdebug-mamp-textmate-and-macgdbp-support" title="Debugging your PHP Code: XDebug on MAMP with TextMate and MacGDBp Support | TechnoSophos">Matt Butcher</a>, <a href="http://particletree.com/notebook/silence-the-echo-with-macgdbp/" title="Particletree  » Silence The Echo with MacGDBp">Tim Sabat</a>, <a href="http://www.cupcakewithsprinkles.com/setting-up-apache-php-python-mysql-on-mac-os-x-snow-leopard-10-6/#comments" title="Setting Up Apache-PHP-Python-MySQL on Mac OS X Snow Leopard 10.6 |  Cupcake With Sprinkles">Hunter Ford</a>, and <a href="http://boztek.net/blog/2009/10/07/install-lamp-stack-source-mac-os-x-106-snow-leopard-using-homebrew" title="Install LAMP stack from source on Mac OS X 10.6 Snow Leopard using Homebrew | boztek">Boris Gordon</a>, I'd recommend subscribing to their blogs, as they <em>definitely</em> know more about PHP than I do, and they're a great source of handy info.</p>
<p>If there's anything that isn't clear, please let me know, so I can improve this guide - I don't want anyone else to have to blunder through working out all this themselves in future, as working all this out has taken, far, far longer than I'd like, and well, it seems churlish not to share now that I've got a setup that seems fairly stable.</p>
<p>Now, time to actually do something useful with it...</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/08/08/how-to-setup-snow-leopard-lamp-for-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looking for the best way to keep data on servers safe</title>
		<link>http://chrisadams.me.uk/2010/07/16/looking-for-the-best-way-to-keep-data-on-servers-safe/</link>
		<comments>http://chrisadams.me.uk/2010/07/16/looking-for-the-best-way-to-keep-data-on-servers-safe/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 23:33:42 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[cloud]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=345</guid>
		<description><![CDATA[We know we should all be doing it, but most of us don't do it enough. I put out a request today to my followers Twitter asking this question: I've had the following services recommended to me by a number of fellow developers whose opinions I have a lot of respect for: A couple of [...]]]></description>
			<content:encoded><![CDATA[<p>We know we should all be doing it, but most of us don't do it enough.</p>
<p>I put out a request today to my followers Twitter asking this question:</p>
<p>I've had the following services recommended to me by a number of fellow developers whose opinions I have a lot of respect for:</p>
<p>A couple of ex-Headshifters pointed me to <a href="http://duplicity.nongnu.org/" title="duplicity: Main">Duplicity</a>, a free tool that also looks very promising. Using it looks pretty straight forward.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    duplicity <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>my_directory <span style="color: #c20cb9; font-weight: bold;">scp</span>:<span style="color: #000000; font-weight: bold;">//</span>backup<span style="color: #000000; font-weight: bold;">@</span>other.host<span style="color: #000000; font-weight: bold;">//</span>usr<span style="color: #000000; font-weight: bold;">/</span>backup</pre></div></div>

<p>A variant of it can be used to backup to Amazon S3 too, and <a href="http://blog.damontimm.com/how-to-automated-secure-encrypted-incremental-backups-amazon-s3-duplicity-os-x-or-ubuntu" title="How To: Automated Encrypted Incremental Backups on Amazon S3 with Duplicity (OS X or Ubuntu) &laquo;  damontimm.com">there's a helpful blog post to show how to do this here</a>, if you use Ubuntu or OSX.</p>
<p><a href="http://twitter.com/kalv/status/18672139356">Kalv</a> recommended <a href="[http://github.com/astrails/safe]" title="astrails's safe at master - GitHub">Safe</a>, a clever Ruby gem by the Astrails crew that was originally designed to automate the backing up of Rails projects in a simple fashion.</p>
<p>One service that looks really interesting is though is Tarsnap, as recommended by [Jon Gilbrath][]. It's similarly simple to use, but takes care of the some of the more awkwards backup issues, and saves you having to setup your own S3 account.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;"># Create an archive named &quot;mybackup&quot; containing /usr/home and /other/stuff:</span>
  tarsnap <span style="color: #660033;">-c</span> <span style="color: #660033;">-f</span> mybackup <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>home <span style="color: #000000; font-weight: bold;">/</span>other<span style="color: #000000; font-weight: bold;">/</span>stuff</pre></div></div>

<p>The developer, Colin Percival also has written quite extensively <a href="http://www.daemonology.net/blog/2008-12-14-how-tarsnap-uses-aws.html" title="How Tarsnap uses Amazon Web Services">about how it works on his own blog</a> - he's only making a few cents per gigabyte on providing this service for people, yet it still looks to be something viable for him to run - amazing.</p>
<p>It looks like it's almost exactly what I'm after - the only thing missing is the option to back up storage inside the EU. This requirement is mainly one coming from data protection concerns from previous clients, because rules for processing data and storing in in the EU are different to that in the US, but given the strength of encryption, I'm not sure how much of an issue this really is, these days.</p>
<p>I'd really appreciate some light shed on this actually - technology is moving so much faster than law these days, it's frustrating not being able to take advantage of these kinds of services.</p>
<p>Anyway that's what I've found. What do you use, and why?</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/07/16/looking-for-the-best-way-to-keep-data-on-servers-safe/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The quickest way into WordPress when you&#8217;re locked out.</title>
		<link>http://chrisadams.me.uk/2010/06/09/the-quickest-way-into-wordpress-when-youre-locked-out/</link>
		<comments>http://chrisadams.me.uk/2010/06/09/the-quickest-way-into-wordpress-when-youre-locked-out/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 13:39:55 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[passwords]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=323</guid>
		<description><![CDATA[I love WordPress as a platform for building sites. But no matter how many times I see it, I don't think I'll ever get used to having this snippet available to me if I get locked out of a WordPress install : &#60;?php wp_set_password&#40;'new_admin_password',1&#41;; // this changes the password for user with an id of [...]]]></description>
			<content:encoded><![CDATA[<p>I love WordPress as a platform for building sites.</p>
<p>But no matter how many times I see it, I don't think I'll ever get used to having this snippet available to me if I get locked out of a WordPress install :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_set_password<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'new_admin_password'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// this changes the password for user with an id of 1 (i.e. the admin)  ?&gt;</span></pre></div></div>

<p>Surely it shouldn't be that easy to get root on a WordPress site?</p>
<p>Ladies and gentlemen, <em>this</em> is why you should always sequester access on a database, so each app has it's own db user. If a charmless bad guy DOES gain access, they can only reck <em>one</em> WordPress site database, <em>not all of them</em>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/06/09/the-quickest-way-into-wordpress-when-youre-locked-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nerdy Vim tip ahoy! How to save a file as the root user from inside Vim</title>
		<link>http://chrisadams.me.uk/2010/06/01/nerdy-vim-tip-ahoy-how-to-save-a-file-as-the-root-user-from-inside-vim/</link>
		<comments>http://chrisadams.me.uk/2010/06/01/nerdy-vim-tip-ahoy-how-to-save-a-file-as-the-root-user-from-inside-vim/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 10:46:18 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[vim coding sysadmin]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=313</guid>
		<description><![CDATA[At work, I'm always managing files while working on a remote server which invariably means I'm stuck using Vim or Vi, and finding out after I've made the my necessary changes to crucial config file, I don't have the rights to actually save them - so I can see this tip by catonmat saving lots [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I'm always managing files while working on a remote server which invariably means I'm stuck using Vim or Vi, and finding out after I've made the my necessary changes to crucial config file,  I don't have the rights to actually save them - so I can see this tip by  <a href="http://www.catonmat.net/blog/top-ten-one-liners-from-commandlinefu-explained/" title="Top Ten One-Liners from CommandLineFu Explained - good coders code, great reuse">catonmat</a> saving lots of time in future. Thank you internets!</p>
<p>If you're using Vim, and you find that you need to save a file as root, the normal commands like <code>:wq</code> won't work. Instead you'll need to call this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  :<span style="color: #c20cb9; font-weight: bold;">w</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #000000; font-weight: bold;">%</span></pre></div></div>

<h3>Okay that's nice. What is it actually doing?</h3>
<p>The above command is basically saying <em>call the write command, passing in <code>sudo tee %</code> as the argument</em>. Now <code>sudo</code> we should be fairly comfortable with by now, leaving us just puzzling over what <code>tee</code> and <code>%</code>  actually mean. Thankfully, it's not too complex.</p>
<p>The <code>tee</code> command takes the the standard input (which in this case is the contents of the file we're editing), and writes that into the filename referenced by <code>%</code> which is a vim shorthard for the current filename.</p>
<h3>Again, in English please</h3>
<p>Sadly for these purposes, my first language for thinking in still English rather than Bash or Vim, so the only way I think I'll ever retain this particular gem is to think of this in the following terms:</p>
<blockquote>
<p>From within vim, take the contents of the file I'm editing, and as sudo, write it into the file I'm currently in, doing so as root.</p>
</blockquote>
<p>One day this will all be second nature to me when I'm a <em>real</em> programmer, but til then, I'll stick with Textmate - it's massively powerful, but when you come against these strange cases, it defers to OS X's much slicker handling of permissions issues.</p>
<p><!-- links --></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/06/01/nerdy-vim-tip-ahoy-how-to-save-a-file-as-the-root-user-from-inside-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The ForkBomb Tattoo</title>
		<link>http://chrisadams.me.uk/2010/05/23/the-forkbomb-tattoo/</link>
		<comments>http://chrisadams.me.uk/2010/05/23/the-forkbomb-tattoo/#comments</comments>
		<pubDate>Sun, 23 May 2010 19:18:12 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[tattoos]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=302</guid>
		<description><![CDATA[This doesn't count for much, but I think this is one of the cleverest, geekiest, most elegant tattoos I've ever seen. Carving an Apple, Cisco or Nike Logo onto your body? That's really quite sad. But this is something different: Why do I like it? I think it's about as attractive as a code type [...]]]></description>
			<content:encoded><![CDATA[<p>This doesn't count for much, but I think this is one of the cleverest, geekiest, most elegant tattoos I've ever seen. Carving an <a href="http://www.flickr.com/groups/apple_tattoo/pool/">Apple</a>, <a href="http://www.readwriteweb.com/archives/the_30_best_and_worst_web_tech_tattoos.php">Cisco</a> or <a href="http://www.flickr.com/photos/bigmoontattoo/2514998242/">Nike Logo</a> onto your body? That's really quite sad. But this is something different:</p>
<p><a href="http://www.flickr.com/photos/silveiraneto/4033340711/"><img class="alignnone" title="Fork Bomb" src="http://farm3.static.flickr.com/2422/4033340711_543ef81df0_b.jpg" alt="" width="354" height="614" /></a></p>
<h3>Why do I like it?</h3>
<h4>I think it's about as attractive as a code type tattoo is going to get</h4>
<p>The proportions are well balanced, and there's a nice visual rhythm in there - this is largely down to the choice Bitstream Sans Mono, the typeface used for this. This typeface is a well loved font in programmer circles, who spend hours staring at monospace fonts - a lovely touch.</p>
<h4>It's actually executable code</h4>
<p>This particular incantation has its own story too - this cryptic combination of symbols is a working example of a <em>forkbomb</em>, and was presented as a piece of open source art back in 2002, by<a href="http://en.wikipedia.org/wiki/Jaromil"> Denis Jaromil Rojo</a>, an Italian Rastafarian developer and media activist now residing in Amsterdam. A forkbomb is a piece of self replicating code that when called, start forking itself relentlessly, until it  consumes all the resources on a computer system, rendering it unusable.</p>
<p>For the terminally curious, here's how it works:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>      <span style="color: #666666; font-style: italic;"># define ':' -- whenever we say ':', do this:</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>        <span style="color: #666666; font-style: italic;"># beginning of what to do when we say ':'</span>
    :    <span style="color: #666666; font-style: italic;"># load another copy of the ':' function into memory...</span>
    <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #666666; font-style: italic;"># ...and pipe its output to...</span>
    :    <span style="color: #666666; font-style: italic;"># ...another copy of ':' function, which has to be loaded into memory</span>
         <span style="color: #666666; font-style: italic;"># (therefore, ':|:' simply gets two copies of ':' loaded whenever ':' is called)</span>
    <span style="color: #000000; font-weight: bold;">&amp;</span>amp;    <span style="color: #666666; font-style: italic;"># disown the functions -- if the first ':' is killed,</span>
         <span style="color: #666666; font-style: italic;">#     all of the functions that it has started should NOT be auto-killed</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>        <span style="color: #666666; font-style: italic;"># end of what to do when we say ':'</span>
;        <span style="color: #666666; font-style: italic;"># Having defined ':', we should now...</span>
:        <span style="color: #666666; font-style: italic;"># ...call ':', initiating a chain-reaction: each ':' will start two more.</span></pre></div></div>

<p>More on <a href="http://en.wikipedia.org/wiki/Fork_bomb">Forkbombs</a> here.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/05/23/the-forkbomb-tattoo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RVM and Textmate in harmony</title>
		<link>http://chrisadams.me.uk/2010/05/21/rvm-and-textmate-in-harmony/</link>
		<comments>http://chrisadams.me.uk/2010/05/21/rvm-and-textmate-in-harmony/#comments</comments>
		<pubDate>Fri, 21 May 2010 07:14:51 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=292</guid>
		<description><![CDATA[One side effect of Ruby's popularity is the proliferation of ruby interpreters that can now execute ruby code, which is generally seen as a good thing, as a sign of a healthy community. However, keeping track of all these versions of Ruby, especially when testing gets harder as each new version of Ruby is released, [...]]]></description>
			<content:encoded><![CDATA[<p>One side effect of Ruby's popularity is the proliferation of ruby interpreters that can now execute ruby code, which is generally seen as a good thing, as a sign of a healthy community. However, keeping track of all these versions of Ruby, especially when testing gets harder as each new version of Ruby is released, so to help alleviate this problem <a href="http://www.workingwithrails.com/recommendation/for/person/7192-wayne-e-seguin">Wayne E. Seguin</a> released Ruby Version Manager, or <a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> to it's friends last year.</p>
<p><a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> does some clever voodoo with symbolic links and suchlike on your box to let you switch between versions of Ruby very easily on the command line simply by typing <code>RVM use ruby-version</code> when you want to use a particular flavour of Ruby. So If I wanted to run MacRuby instead of the usual version of Ruby 1.8.7 that uses the MRI Interpreter, I'd simply check what versions of Ruby I had installed on my box like so :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
chrisadams<span style="color: #000000; font-weight: bold;">@</span>edam<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">7</span>:<span style="color: #000000;">52</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>:rvm list
&nbsp;
   jruby-1.4.0 <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>x86_64-java<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
   macruby-nightly <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
   ree-1.8.7-<span style="color: #000000;">2010.01</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> ruby-1.8.7-tv1_8_7_249 <span style="color: #7a0874; font-weight: bold;">&#91;</span> x86_64 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>default<span style="color: #7a0874; font-weight: bold;">&#41;</span> ruby-1.8.7-tv1_8_7_249 <span style="color: #7a0874; font-weight: bold;">&#91;</span> x86_64 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
   system <span style="color: #7a0874; font-weight: bold;">&#91;</span> x86_64 i386 ppc <span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>And then say which Ruby I want to use for the rest of the session I have open:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">7</span>:<span style="color: #000000;">52</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>:rvm use macruby-nightly
&nbsp;
  Now using macruby nightly</pre></div></div>

<p>And if I wanted to switch back, I'd just type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">chrisadams<span style="color: #000000; font-weight: bold;">@</span>edam<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">7</span>:<span style="color: #000000;">54</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>:rvm use default        
&nbsp;
Now using default ruby.</pre></div></div>

<p>This is extremely handy, except if you're using Textmate, which by default, will happily use a version of Ruby that pays no attention to your version switching japery, making testing and development rather less fun.</p>
<p>Fortunately, there are now some tools to make <a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> work with everyone's favourite mac only OS X editor now. Here's how to to make the two work together easily:</p>
<p>First of all tell <a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> to setup your symlink:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    rvm 1.8.7 <span style="color: #660033;">--symlink</span> textmate</pre></div></div>

<p>Now, you'll need to tell Textmate to use this version of Ruby instead by a) setting a shell variable, and then forcing Textmate to use this Ruby instead, by moving the <code>Builder</code> class, that normally sets up it's Ruby shell environment:</p>
<p>Here's where you should set your shell variable in Textmate:</p>
<p><a href="http://chrisadams.me.uk/wordpress/wp-content/uploads/2010/05/20100521-x7b3hw4i2r4xqd1kgyeg2hxijd.png"><img src="http://chrisadams.me.uk/wordpress/wp-content/uploads/2010/05/20100521-x7b3hw4i2r4xqd1kgyeg2hxijd-300x272.png" alt="" title="20100521-x7b3hw4i2r4xqd1kgyeg2hxijd" width="300" height="272" class="alignnone size-medium wp-image-294" /></a></p>
<p>Once you have that, swap out the <code>Builder</code> as mentioned before, then restart Textmate.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>TextMate.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>SharedSupport<span style="color: #000000; font-weight: bold;">/</span>Support<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span> ; <span style="color: #c20cb9; font-weight: bold;">mv</span> Builder.rb Builder.rb.backup</pre></div></div>

<p>And that should be about it. You can easily test that this worked in Textmate by opening a new file containing only the following code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#CC0066; font-weight:bold;">puts</span> RUBY_DESCRIPTION</pre></div></div>

<p>... then either saving the file with a <code>.rb</code> extension, or set the syntax colouring for Ruby, then hitting command +</p>
<p>If it worked, you should see something like this:</p>
<p><a href="http://chrisadams.me.uk/wordpress/wp-content/uploads/2010/05/Running-“test.rb”….png"><img src="http://chrisadams.me.uk/wordpress/wp-content/uploads/2010/05/Running-“test.rb”…-300x271.png" alt="" title="Running “test.rb”…" width="300" height="271" class="alignnone size-medium wp-image-293" /></a></p>
<p>If not, don't despair - there's lots of useful docs on the <a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> site itself, and the irc channel, #<a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> is full of wonderfully helpful types.</p>
<p>Now go, armed with this knowledge and make Textmate and <a href="http://rvm.beginrescueend.com/integration/textmate/">RVM</a> to play nicely together again.</p>
<p><!-- links --></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/05/21/rvm-and-textmate-in-harmony/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tar is not zip</title>
		<link>http://chrisadams.me.uk/2010/05/17/tar-is-not-zip/</link>
		<comments>http://chrisadams.me.uk/2010/05/17/tar-is-not-zip/#comments</comments>
		<pubDate>Mon, 17 May 2010 01:40:54 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[commandline]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://chrisadams.me.uk/?p=284</guid>
		<description><![CDATA[Today, I had to package up some code that was residing on a remote server that I had ssh access to, to send to someone who was probably on a windows box. This meant I had to use the zip tool, which I can never remember how to use, hence this memory jogging post. Now [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I had to package up some code that was residing on a remote server that I had ssh access to, to send to someone who was probably on a windows box.</p>
<p>This meant I had to use the <code>zip</code> tool, which I can never remember how to use, hence this memory jogging post.</p>
<p>Now if someone's using a Mac or is on Linux, the normal command line approach to to tar up a directory to send to someone goes like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cvzf</span> my_tarfile.tar.gz a_directory_to_tar and_otherone_here</pre></div></div>

<p>We're calling <code>tar</code> here, with the -create <em>(c)</em>, file <em>(f)</em>, compress <em>(z)</em> oh, and the verbose <em>(f)</em>, flag. Think of that string like saying to the computer: "create the tarfile <code>my_tarfile</code> putting it into a file we just created, verbosely, while compressing it, from <code>a_directory_to_tar</code> and <code>and_otherone_here</code>".</p>
<p>As commands go, the order feels a bit weird at first, but you get the hang eventually.</p>
<h4>Where zip is different</h4>
<p>Using <code>zip</code> isn't too different really, but it you need to remember to tell it to zip recursively (why is this not default behaviour?). If we call command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">zip</span> archive a_directory_to_tar and_otherone_here</pre></div></div>

<p>We'll end up with an rather useless empty file called <code>archive.zip</code>. We need to pass in the recursive flag</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">-r</span> archive a_directory_to_tar and_otherone_here</pre></div></div>

<p>There's also no need to add the <code>.zip</code> file extension - this is added for you as a courtesy. Well, after that ridiculous non-recursive default shenanigans, frankly that's the least it could do...</p>
<p>Anyway, there you have it. The differences you between them if you don't want to dive into the manpages just to package up a folder for somebody, or look at this <a href="http://linux.about.com/od/commands/a/blcmdl1_zipx.htm" title="Example uses of the Linux Command zip">linux.about.com</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://chrisadams.me.uk/wordpress/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://chrisadams.me.uk/2010/05/17/tar-is-not-zip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
