<?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"
	>

<channel>
	<title>The Only James</title>
	<atom:link href="http://www.theonlyjames.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theonlyjames.com</link>
	<description>Development, technology and other geekery.</description>
	<pubDate>Thu, 14 Aug 2008 21:18:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>New Terminal tab with pwd</title>
		<link>http://www.theonlyjames.com/2008/08/new-terminal-tab-with-pwd/</link>
		<comments>http://www.theonlyjames.com/2008/08/new-terminal-tab-with-pwd/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 21:18:06 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[applescript]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[geek]]></category>

		<category><![CDATA[shell]]></category>

		<category><![CDATA[tab]]></category>

		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=181</guid>
		<description><![CDATA[Just a quick snippet I&#8217;m using to open a new tab in Terminal. It accepts a single, optional argument which will override cd&#8217;ing to the working directory.

#!/usr/bin/env bash
&#160;
if &#91;&#91; $# -eq 0 &#93;&#93;; then
	dir=`pwd`
else
	dir=$1
fi
&#160;
/usr/bin/osascript \
-e &#34;tell app \&#34;System Events\&#34; to tell process \&#34;Terminal\&#34; to keystroke \&#34;t\&#34; using command down&#34; \
-e &#34;tell app \&#34;Terminal\&#34; to do [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick snippet I&#8217;m using to open a new tab in Terminal. It accepts a single, optional argument which will override cd&#8217;ing to the working directory.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">#!/usr/bin/env bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">dir=</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #007800;">dir=</span>$<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>osascript \
-e <span style="color: #ff0000;">&quot;tell app <span style="color: #000099; font-weight: bold;">\&quot;</span>System Events<span style="color: #000099; font-weight: bold;">\&quot;</span> to tell process <span style="color: #000099; font-weight: bold;">\&quot;</span>Terminal<span style="color: #000099; font-weight: bold;">\&quot;</span> to keystroke <span style="color: #000099; font-weight: bold;">\&quot;</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> using command down&quot;</span> \
-e <span style="color: #ff0000;">&quot;tell app <span style="color: #000099; font-weight: bold;">\&quot;</span>Terminal<span style="color: #000099; font-weight: bold;">\&quot;</span> to do script <span style="color: #000099; font-weight: bold;">\&quot;</span>cd $dir<span style="color: #000099; font-weight: bold;">\&quot;</span> in front window&quot;</span> \
-e <span style="color: #ff0000;">&quot;tell app <span style="color: #000099; font-weight: bold;">\&quot;</span>System Events<span style="color: #000099; font-weight: bold;">\&quot;</span> to tell process <span style="color: #000099; font-weight: bold;">\&quot;</span>Terminal<span style="color: #000099; font-weight: bold;">\&quot;</span> to keystroke <span style="color: #000099; font-weight: bold;">\&quot;</span>l<span style="color: #000099; font-weight: bold;">\&quot;</span> using control down&quot;</span></pre></div></div>

<p>I&#8217;ve put the shell script in &#8220;/usr/local/bin&#8221; as this is in my $PATH. I&#8217;ve named the script &#8220;tab&#8221; so whenever in Terminal I can enter &#8220;tab&#8221; to open a new tab with the current working directory ready and waiting. Very useful when working with Rails and multiple shells.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/08/new-terminal-tab-with-pwd/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Smart empty text field automatically</title>
		<link>http://www.theonlyjames.com/2008/08/smart-empty-text-field/</link>
		<comments>http://www.theonlyjames.com/2008/08/smart-empty-text-field/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 08:35:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[javascript]]></category>

		<category><![CDATA[demo]]></category>

		<category><![CDATA[form]]></category>

		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=178</guid>
		<description><![CDATA[I think everyone has seen a form on a web page that has text fields that automatically empty when they receive focus. I&#8217;ve added this functionality to countless fields over the years and the behaviour I used to to this has evolved more and more. Using Prototype and the following script you can have fields [...]]]></description>
			<content:encoded><![CDATA[<p>I think everyone has seen a form on a web page that has text fields that automatically empty when they receive focus. I&#8217;ve added this functionality to countless fields over the years and the behaviour I used to to this has evolved more and more. Using Prototype and the following script you can have fields intelligently empty themselves. <span id="more-178"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> clear_field<span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> handle_blur<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value_modified</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">onfocus</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value</span> <span style="color: #339933;">==</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">defaultValue</span> <span style="color: #339933;">&amp;&amp;</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value_modified</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value_modified</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>handle_blur <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">onblur</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">value</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">defaultValue</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   clear_field<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;login&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   clear_field<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The &#8220;clear_field&#8221; function handles focus and can handle blur events. When a field receives focus for the first time the &#8220;value_modified&#8221; boolean variable is set to true and the value of the field is set to an empty string. Subsequent focus events will no longer empty the field as we do not want to interfere with the user&#8217;s interaction with our field.</p>
<p>If we supply a &#8220;false&#8221; argument after our element the blur event will not be applied. If this is the case the field will never be repopulated. Handy for password fields, as is indicated in the example above.</p>
<p>If the blur event is applied the field will be repopulated with it&#8217;s defaultValue if the field is empty when it loses focus.</p>
<p>I&#8217;ve uploaded a demonstration of the use of this code. You can find it at <a href="http://static.jamesconroyfinn.com/clear_field/">http://static.jamesconroyfinn.com/clear_field/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/08/smart-empty-text-field/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Enabling Apache&#8217;s mod_deflate</title>
		<link>http://www.theonlyjames.com/2008/08/enabling-apaches-mod_deflate/</link>
		<comments>http://www.theonlyjames.com/2008/08/enabling-apaches-mod_deflate/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 17:59:08 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[sysadmin]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[geek]]></category>

		<category><![CDATA[mod_deflate]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=172</guid>
		<description><![CDATA[If you&#8217;re running an Apache web server and you want to speed up your visitor&#8217;s browsing you can enable mod_deflate, which has replaced mod_gzip in Apache 2.
You&#8217;ll probably find your mod_default module is already installed and available with just a couple of lines of configuration. 
I&#8217;ve enabled mod_deflate globally across all my domains and hence [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re running an Apache web server and you want to speed up your visitor&#8217;s browsing you can enable mod_deflate, which has replaced mod_gzip in Apache 2.</p>
<p>You&#8217;ll probably find your mod_default module is already installed and available with just a couple of lines of configuration. <span id="more-172"></span></p>
<p>I&#8217;ve enabled mod_deflate globally across all my domains and hence have added my configuration to my main httpd.conf file. With most flavours of UNIX it&#8217;s located in /etc/httpd. If not consult the documentation for your distro. Should you only wish to enable for a single domain you&#8217;d need to add the AddOutputFilterByType and BrowserMatch rules below to the VirtualHost section in your configuration.</p>
<p>These instructions are tailored for my setup (a (dv) 3.5 with MediaTemple.) Your host may put your configuration files elsewhere. You will need root access via SSH to your web server to complete these modifications. If you aren&#8217;t comfortable in the command line best you ask your host very nicely to do this for you.</p>
<p>First off we need to make sure mod_deflate is being loaded by Apache. Fly in to the command-line and use&hellip;</p>
<pre>
# grep 'mod_deflate' /etc/httpd/conf/httpd.conf
</pre>
<p>&hellip;to search for line that will load the mod_deflate module. If it&#8217;s commented out with a leading &#8220;#&#8221; then we need to remove the hash sign in order for mod_deflate to be loaded when we start up Apache.</p>
<p>I personally used vi to do this but you could use perl from the command line if you wished to. Remember to back up your files regularly and do not make modifications to httpd.conf without a stable copy you can revert to should things go wrong!</p>
<pre>
# perl -pi -e 's/# LoadModule mod_deflate/LoadModule mod_deflate/g' /etc/httpd/conf/httpd.conf
</pre>
<p>This command searches for an occurrence of &#8220;# LoadModule mod_deflate&#8221; in your configuration file and replaces if with &#8220;LoadModule mod_deflate&#8221; essentially just stripping the hash sign from the line.</p>
<p>Once we have an entry in httpd.conf for loading mod_deflate we need to add configuration settings for mod_deflate. Again, I used vi for this.</p>
<pre>
# vi /etc/httpd/conf/httpd.conf
</pre>
<p>In you configuration file you need to add&hellip;</p>
<pre>
#
# Deflate output configuration
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</pre>
<p>I put these lines in with some of the shtml configuration options near the top of my file. Just make sure you don&#8217;t nest the options inside a particular module&#8217;s configuration section or within a VirtualHost definition.</p>
<p>I used grep to pull the lines out of my http.conf file below. The -B flag pulls a number of lines before a match is found and the -A pulls lines after. The command below will find any occurrence of &#8220;Deflate&#8221; in httpd.conf and print out one line before and six lines after.</p>
<pre>
# grep -B1 -A6 'Deflate' /etc/httpd/conf/httpd.conf
#
# Deflate output configuration
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</pre>
<p>With mod_deflate enabled and our configuration settings added to compress HTML, plain, XML and css files we&#8217;re almost ready to restart Apache. Before doing so we always need to check syntax in our config files using&hellip;</p>
<pre>
# apachectl -t
</pre>
<p>If we get a &#8220;Syntax OK&#8221; message back we&#8217;re good to initiate a graceful restart.</p>
<pre>
# apachectl graceful
</pre>
<p>Now we should find Apache pushes files out using gzip compression, hence reducing page loading times and making the end user experience that bit more pleasurable.</p>
<p>There is a similar article on howtoforge regarding setting up mod_deflate on a Debian system. Check it out at <a href="http://www.howtoforge.com/apache2_mod_deflate">HowToForge.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/08/enabling-apaches-mod_deflate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Plists in Ruby</title>
		<link>http://www.theonlyjames.com/2008/08/plists-in-ruby/</link>
		<comments>http://www.theonlyjames.com/2008/08/plists-in-ruby/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 21:10:04 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[coding]]></category>

		<category><![CDATA[geek]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[sysadmin]]></category>

		<category><![CDATA[plist]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=166</guid>
		<description><![CDATA[I&#8217;m currently working on tweaking Apple&#8217;s lazy GUI design by alphabetising VPN connections in both System Preferences and the VPN Connection menu. This is definitely only intended for Leopard and I wont be testing it in Tiger or supporting it. It&#8217;s just for my own personal use as I have 40 odd VPN connections. The [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on tweaking Apple&#8217;s lazy GUI design by alphabetising VPN connections in both System Preferences and the VPN Connection menu. This is definitely only intended for Leopard and I wont be testing it in Tiger or supporting it. It&#8217;s just for my own personal use as I have 40 odd VPN connections. The initial proof of concept code is below. I still need to work on getting things to work reliably and smoothly. <span id="more-166"></span></p>
<p>I found the plist ruby gem to be somewhat unreliable but think I might have found a way to temporarily provide all the functionality required by piggy backing on plutil. The email I sent to Patrick is below as I don&#8217;t want to have to type up the same waffle twice.</p>
<blockquote><p>Hi Patrick,</p>
<p>I&#8217;m working on sorting the network connect plist so that System Preferences and the VPN menu will display connections sorted alphabetically.</p>
<p>Initially parsing&hellip;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;~/Library/Preferences/ByHost/com.apple.networkConnect.#{mac_addr}.plist&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>&hellip;returned the old unknown elements runtime error. Regrettably I can&#8217;t send the entire contents of my preference file as it contains some sensitive information even without passwords.</p>
<p>It did make me think about an alternative approach however, which allowed me to parse the plist successfully. I used plutil to convert the plist file to an xml1 format…</p>
<p>plutil -convert xml1 -o /tmp/plist.xml com.apple.network…</p>
<p>Then by parsing the xml I had full access to the file. Of course, one could use Ruby&#8217;s built-in temporary file functionality rather than writing to the /tmp directory as I did.</p>
<p>This could theoretically be included as a fall back should an unknown element be encountered.</p>
<p>Thanks for the effort you&#8217;ve put in to developing this gem. It&#8217;s a handy piece of kit!</p>
<p>Kind regards,<br />
James</p></blockquote>

<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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rubygems&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;plist&quot;</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">LoadError</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># def print_usage</span>
<span style="color:#008000; font-style:italic;">#   puts &quot;Usage: #{File.basename(__FILE__)} [file_path]&quot;</span>
<span style="color:#008000; font-style:italic;">#   exit</span>
<span style="color:#008000; font-style:italic;"># end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> ARGV.<span style="color:#9900CC;">length</span> == <span style="color:#006666;">1</span>
  file_path = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  mac_addr = <span style="color:#996600;">`ifconfig en0 ether`</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;n&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">':'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>da<span style="color:#006600; font-weight:bold;">-</span>f<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">12</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> mac_addr <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#ff6633; font-weight:bold;">$VERBOSE</span> == <span style="color:#006666;">1</span>
&nbsp;
  file_path = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;~/Library/Preferences/ByHost/com.apple.networkConnect.#{mac_addr}.plist&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>file_path<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># We don't want to worry about overwriting files</span>
  uniq_file = <span style="color:#996600;">&quot;/tmp/plist.#{(rand * 10000).floor}.xml&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Thank you Apple, I can never stay mad at you!</span>
  <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#40;</span>plutil <span style="color:#006600; font-weight:bold;">-</span>convert xml1 <span style="color:#006600; font-weight:bold;">-</span>o <span style="color:#996600;">'#{uniq_file}'</span> <span style="color:#996600;">'#{file_path}'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Parse our valid xml file</span>
  plist = Plist.<span style="color:#9900CC;">parse_xml</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>uniq_file<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># This is everything that comes out</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> plist.<span style="color:#9900CC;">inspect</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Clean up, just for fun!</span>
  <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">rm</span><span style="color:#006600; font-weight:bold;">&#40;</span>uniq_file<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#996600;">&quot;Invalid path specified &quot;</span><span style="color:#008000; font-style:italic;">#{file_path}&quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Don&#8217;t use this code AS IS! It&#8217;s a proof of concept. It doesn&#8217;t work and the really hard graft is yet to come. This just shows it can be done!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/08/plists-in-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing yum and git on a MediaTemple (dv) 3.5</title>
		<link>http://www.theonlyjames.com/2008/08/yum-git-dv-3-5/</link>
		<comments>http://www.theonlyjames.com/2008/08/yum-git-dv-3-5/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 08:59:08 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[geek]]></category>

		<category><![CDATA[sysadmin]]></category>

		<category><![CDATA[cent os]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[mediatemple]]></category>

		<category><![CDATA[unix]]></category>

		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=164</guid>
		<description><![CDATA[I recently decided to install Git on my (dv) 3.5 and found an article written by the guys at MediaTemple, my hosts, with instructions on how to do it (isn&#8217;t it nice when someone else does the hard graft for you?!) Unfortunately, the article was old and inaccurate. Luckily, with a bit of digging around [...]]]></description>
			<content:encoded><![CDATA[<p>I recently decided to install <a href="http://git.or.cz/">Git</a> on my <a href="http://www.mediatemple.net/webhosting/dv/">(dv) 3.5</a> and found an article written by the guys at <a href="http://www.mediatemple.net/go/order/?refdom=jamesconroyfinn.com">MediaTemple</a>, my hosts, with instructions on how to do it (isn&#8217;t it nice when someone else does the hard graft for you?!) Unfortunately, the article was old and inaccurate. Luckily, with a bit of digging around I managed to get yum installed, updated and ready for Git. <span id="more-164"></span></p>
<p>The problem with the <a href="http://mediatemple.net">(mt)</a> article is it&#8217;s outdated. The URI they provide with the initial rpm command is non-existent. It produces a lovely little 404 error, which rpm reports as follows&hellip;</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;"># rpm -Uvh http://mirror.centos.org/centos/5.1/os/i386/CentOS/yum-3.0.5-1.el5.centos.5.noarch.rpm</span>
&nbsp;
Retrieving http:<span style="color: #000000; font-weight: bold;">//</span>mirror.centos.org<span style="color: #000000; font-weight: bold;">/</span>centos<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5.1</span><span style="color: #000000; font-weight: bold;">/</span>os<span style="color: #000000; font-weight: bold;">/</span>i386<span style="color: #000000; font-weight: bold;">/</span>CentOS<span style="color: #000000; font-weight: bold;">/</span>yum<span style="color: #000000;">-3.0</span><span style="color: #000000;">.5</span><span style="color: #000000;">-1</span>.el5.centos<span style="color: #000000;">.5</span>.noarch.rpm
error: skipping http:<span style="color: #000000; font-weight: bold;">//</span>mirror.centos.org<span style="color: #000000; font-weight: bold;">/</span>centos<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5.1</span><span style="color: #000000; font-weight: bold;">/</span>os<span style="color: #000000; font-weight: bold;">/</span>i386<span style="color: #000000; font-weight: bold;">/</span>CentOS<span style="color: #000000; font-weight: bold;">/</span>yum<span style="color: #000000;">-3.0</span><span style="color: #000000;">.5</span><span style="color: #000000;">-1</span>.el5.centos<span style="color: #000000;">.5</span>.noarch.rpm - transfer failed - Unknown or unexpected error
warning: u 0x807d980 ctrl 0x807e148 nrefs <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>mirror.centos.org http<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>First of all we need the &#8220;yum-metadata-parser.&#8221; If you don&#8217;t install this dependency the yum install will fail.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;"># rpm -Uvh http://mirror.centos.org/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-2.el5.i386.rpm</span></pre></div></div>

<p>Now we can install yum itself.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;"># rpm -Uvh http://mirror.centos.org/centos/5/os/i386/CentOS/yum-3.2.8-9.el5.centos.1.noarch.rpm</span></pre></div></div>

<p>This link may no longer be accurate in the future as the rpm package includes a version number. If CentOS decide to no longer mirror the download we&#8217;ll need to track down the latest version and rpm that instead.</p>
<p>Once this is all installed we can update yum using &#8220;yum update.&#8221; When I ran the update there were roughly 142 packages to update totalling around 245 MB of actual data. It was done pretty sharpish thanks to (mt)&#8217;s huge pipe!</p>
<p>The git package is available via EPEL repository so we need to run another rpm command in order to search this repository when using yum.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;"># rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm</span></pre></div></div>

<p>With yum up to date and access to the EPEL repository we can finally install git.</p>

<div class="wp_syntax"><div class="code"><pre class="bash">yum <span style="color: #c20cb9; font-weight: bold;">install</span> git</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/08/yum-git-dv-3-5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Modified CSS Bundle for TextMate</title>
		<link>http://www.theonlyjames.com/2008/07/tm-css-bundle-mod/</link>
		<comments>http://www.theonlyjames.com/2008/07/tm-css-bundle-mod/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 12:29:54 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[awk]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[geek]]></category>

		<category><![CDATA[bundle]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[textmate]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=152</guid>
		<description><![CDATA[If you use TextMate when you&#8217;re coding for the web you&#8217;ll probably have at least tried out Jim Jeffer&#8217;s CSS Bundle, which was inspired by an article by Jina Bolton. If not check it out!
When I first downloaded it I was impressed but not exactly blown away as the snippets don&#8217;t really leverage the true [...]]]></description>
			<content:encoded><![CDATA[<p>If you use TextMate when you&#8217;re coding for the web you&#8217;ll probably have at least tried out <a href="http://donttrustthisguy.com/">Jim Jeffer&#8217;s</a> <a href="http://donttrustthisguy.com/2008/01/05/css-commenting-with-textmate/">CSS Bundle</a>, which was inspired by an article by <a href="http://jinabolton.com/">Jina Bolton</a>. If not check it out!</p>
<p>When I first downloaded it I was impressed but not exactly blown away as the snippets don&#8217;t really leverage the true power of TextMate&#8217;s bundle system. I had to get to work to make things a lot smoother.<span id="more-152"></span></p>

<div class="wp_syntax"><div class="code"><pre class="css"><span style="color: #808080; font-style: italic;">/*
	${1:Working Title}
	Updated:	${2:`Date +'%a'`} ${3:`date +'%d/%m/%Y'`} ${4:`date +'%H:%M:%S %Z (%z)'`}
	Author:		${5:`dscl . -read /Users/$USER RealName | awk 'NR==2 { sub(/^[ \t]+/, &quot;&quot;); print }'`}
	----------------------------------------------------*/</span>$<span style="color: #933;">0</span></pre></div></div>

<p>I modified the &#8220;comment: updated&#8221; snippet to automatically populate the Updated timestamp for us and added a dscl command to get the RealName associated with the current user&#8217;s shortname.</p>
<p>The date timestamp will appear in the format &#8220;Mon 23/04/1984 12:01:21 GMT (+0000).&#8221; I&#8217;m using this format as I&#8217;m British and it&#8217;s makes sense to me. If you&#8217;re American you could switch the &#8220;%d&#8221; and &#8220;%m&#8221; around to get &#8220;MM/DD/YYYY.&#8221; Alternatively you could just replace &#8220;date +&#8217;%d/%m/%Y&#8217;&#8221; with &#8220;date +&#8217;%D&#8217;&#8221; to have a date formatted according to your computer&#8217;s default date format. For more all the possible options available when formatting dates using the date command check out <a href="http://en.wikipedia.org/wiki/Date_(Unix)">WikiPedia&#8217;s date article</a>.</p>
<p>I also amended the &#8220;comment: declare&#8221; snippet similarly so my RealName would be added automatically to the snippet. To do this you only need to replace &#8220;${4:Your Name}&#8221; on the &#8220;Author:&#8221; line with&hellip;</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #800000;">${4:`dscl . -read /Users/$USER RealName | awk 'NR==2 { sub(/^[ \t]+/, &quot;&quot;); print }</span><span style="color: #ff0000;">'`}
</span</pre></div></div>

<p>Or just replace the whole snippet with my amended version below.</p>

<div class="wp_syntax"><div class="code"><pre class="css"><span style="color: #808080; font-style: italic;">/*   
Theme Name: ${1:Name}
Theme URI: ${2:URL}
Description: ${3:a-brief-description}
Author: ${4:`dscl . -read /Users/$USER RealName | awk 'NR==2 { sub(/^[ \t]+/, &quot;&quot;); print }'`}
Author URI: ${5:your-URI}
Template: ${6:use-this-to-define-a-parent-theme--optional}
Version: ${7:a-number--optional}
.
${8:General comments/License Statement if any.}
.
*/</span>$<span style="color: #933;">0</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/07/tm-css-bundle-mod/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Don Logan is pissed!</title>
		<link>http://www.theonlyjames.com/2008/07/don-logan-is-pissed/</link>
		<comments>http://www.theonlyjames.com/2008/07/don-logan-is-pissed/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 09:58:06 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[asides]]></category>

		<category><![CDATA[comedy]]></category>

		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/2008/07/143/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="350"><param name="movie" value="http://youtube.com/v/7_UzRJe_nL0"></param><embed src="http://youtube.com/v/7_UzRJe_nL0" type="application/x-shockwave-flash" width="425" height="350"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/07/don-logan-is-pissed/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My must have iPhone apps</title>
		<link>http://www.theonlyjames.com/2008/07/my-must-have-iphone-apps/</link>
		<comments>http://www.theonlyjames.com/2008/07/my-must-have-iphone-apps/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 08:32:11 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[geek]]></category>

		<category><![CDATA[iphone]]></category>

		<category><![CDATA[facebook]]></category>

		<category><![CDATA[itunes]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=138</guid>
		<description><![CDATA[Since the release of the iPhone 2.0 firmware I&#8217;ve become a stubble covered hobo with a taste for £1.99 tipples. After having an iPhone for several months the initial lust started to turn in to more of a comfortable facet of every day life. But thanks to the App Store, my relationship with my darling [...]]]></description>
			<content:encoded><![CDATA[<p>Since the release of the iPhone 2.0 firmware I&#8217;ve become a stubble covered hobo with a taste for £1.99 tipples. After having an iPhone for several months the initial lust started to turn in to more of a comfortable facet of every day life. But thanks to the App Store, my relationship with my darling iPhone has been revitalised. And now, the sex has never been better! <span id="more-138"></span></p>
<p>Ok, so maybe I don&#8217;t love my iPhone enough to engage in autoerotica but with the new apps I have access to I do find it much more productive!</p>
<p>The first couple of apps I downloaded were Apple&#8217;s <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&#038;mt=8">Remote</a>, <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284882215&#038;mt=8">Facebook</a> and <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284540316&#038;mt=8">Twitterrific</a>.</p>
<p>Remote is brilliant. Imagine listening to your music on your iPhone with all your glorious album artwork displayed on the big bright screen, playing, pausing and scrubbing away. Now imagine the music that&#8217;s playing is actually coming out of your £2000 surround sound stereo system and your 8 GB iPhone has access to 500 GB of music. All you need is iTunes on the same wireless network as your iPhone and you can pair away. The integration with iTunes feels solid and professionally done which really helps!</p>
<p>If you use <a href="http://facebook.com">Facebook</a> then the Facebook app is a must have. The initial release had all the most basic features of Facebook without all the adverts and tacky third-party apps. Since 1.1 the Facebook has seen a few improvements. For example you can now write on your friend&#8217;s walls and upload photos stored in your photo library.</p>
<p>As a pretty regular user of <a href="http://twitter.com">Twitter</a> I couldn&#8217;t resist getting <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284540316&#038;mt=8">Twitterific</a> by <a href="http://iconfactory.com/software/twitterrific">IconFactory</a>. I&#8217;ve been pretty impressed with it so far, and it&#8217;s got a rating of around five stars on the App store. Twitterrific will show you your timeline of tweets with the ability to reply to and direct message people you are following. You can also access your friend&#8217;s profiles and star tweets. All round it does everything you need.</p>
<p>There is a premium version of Twitterrific, which gives you the option of a lighter theme and no adverts but to be honest I haven&#8217;t found the ads to be too obtrusive so haven&#8217;t opted to buy the <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284542696&#038;mt=8">premium</a> version.</p>
<p>I&#8217;m loving the <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284916679&#038;mt=8">Last.fm</a> applications because there&#8217;s nothing quite like free music and Last.fm&#8217;s recommendations are always really good! If you&#8217;re not already using <a href="http://last.fm">Last.fm</a> <a href="http://www.last.fm/join">sign up</a> today! You can share your musical tastes with other people and find loads of guys and gals who listen to the same embarrassing rubbish as you! I&#8217;ll post a load more about Last.fm in the next couple of days because there&#8217;s more to it than meets the eye&hellip;</p>
<p>So now you&#8217;re posting pictures to your friends on Facebook, tweeting as you sit on the train to work and listening to internet radio tailor made to your musical tastes. But wait, you decided to pop in to a trendy little independent clothes store to pick up a pair of jeans for the weekend and you hear this great track playing in the background. Those rolling lo-fi beats would make a perfect addition to your pre-partying warmup mix but you have no idea who the song is by or what it&#8217;s called. There are after all no words!</p>
<p>Out comes the iPhone with <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284993459&#038;mt=8">Shazam</a>. Shazam is amazing and it&#8217;s currently free! This app listens to what&#8217;s going on around your iPhone, picks up a song in the background and tells you what it is. And it works!</p>
<p>I&#8217;ve only had it fail on me once and that was when the music was really quiet and there were loads of people talking. To be fair, I could barely hear the music myself! It did, however, manage to recognise an Al Green track in Pulp Fiction while in the midst of onscreen dialog. Overall, a must have app!</p>
<p><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284972147&#038;mt=8">Tap Tap Revenge</a> is the only real game I have on my iPhone. It&#8217;s kind of like a guitar hero dance mat kind of game where you tap the screen or shake your iPhone in time with music. It&#8217;s quite a lot of fun especially when playing two player head to head mode! And there are additional tracks available for download so the shelf life of the game can be extended.</p>
<p>I&#8217;ve played <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=281966695&#038;mt=8">Super Monkey Ball</a> on the iPhone and was quite impressed with the logistics of it all. It makes great use of the accelerometer and feels well made. The only reason I haven&#8217;t bought it is I can&#8217;t justify spending £5.99 just to waste all of my battery life in an hour.</p>
<p>The next app I want to try out has to be the VNC viewer. I don&#8217;t think it would be that practical in every day situations. For example, I could never use it for controlling a server over a VPN connection, it would just be far too slow; and I&#8217;d rather use SSH anyway. But it does seem like a nice idea when I&#8217;m floating around the house controlling iTunes remotely. And it would be quite good at showing off what the iPhone can do.</p>
<p>When I get my 3G I&#8217;ll no doubt be able to rethink some of my app choices as the size of my pipe will increase massively. Until then, I&#8217;ll just stick with my edgy little pipe and use bandwidth hungry apps over WiFi only.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/07/my-must-have-iphone-apps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>puts Ruby.in_colour!</title>
		<link>http://www.theonlyjames.com/2008/07/puts-ruby-in-colour/</link>
		<comments>http://www.theonlyjames.com/2008/07/puts-ruby-in-colour/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 23:04:10 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[geek]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[colour]]></category>

		<category><![CDATA[shell]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=126</guid>
		<description><![CDATA[When I&#8217;m making a script for someone I always think it&#8217;s nice to add a bit of colour to anything output by Ruby. Not to be garish… We don&#8217;t want command line filth reminiscent of Geocities after all! But if there&#8217;s an obvious exception that ends our fun it&#8217;s good to highlight that. 
When working with [...]]]></description>
			<content:encoded><![CDATA[<p>When I&#8217;m making a script for someone I always think it&#8217;s nice to add a bit of colour to anything output by Ruby. Not to be garish… We don&#8217;t want command line filth reminiscent of Geocities after all! But if there&#8217;s an obvious exception that ends our fun it&#8217;s good to highlight that. <span id="more-126"></span></p>
<p>When working with colour in Terminal we have to use a rather cryptic series of escape characters with colour codes to present the user with some beautiful letters.</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
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby -wdK</span>
&nbsp;
esc = <span style="color:#996600;">&quot;<span style="color:#000099;">\0</span>33[&quot;</span>
fgs = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">30</span>..<span style="color:#006666;">37</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>
bgs = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">40</span>..<span style="color:#006666;">47</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>
box_width = <span style="color:#006666;">4</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">4</span> <span style="color:#006600; font-weight:bold;">*</span> bgs.<span style="color:#9900CC;">length</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#996600;">&quot;Ruby colour box&quot;</span>.<span style="color:#9900CC;">center</span><span style="color:#006600; font-weight:bold;">&#40;</span>box_width<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;&quot;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot; &quot;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">4</span>
&nbsp;
bgs.<span style="color:#9900CC;">each_with_index</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>bg, i<span style="color:#006600; font-weight:bold;">|</span>
  fg = fgs<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot; #{bg} &quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
&nbsp;
fgs.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>fg<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot; #{fg} &quot;</span>
  bgs.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>bg<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;#{esc}#{fg};#{bg}m #{fg} #{esc}0m&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#996600;">&quot;http://www.theonlyjames.com&quot;</span>.<span style="color:#9900CC;">center</span><span style="color:#006600; font-weight:bold;">&#40;</span>box_width<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;&quot;</span></pre></td></tr></table></div>

<p>The Ruby script illustrates the structure pretty well. You have an escape character (in our script it&#8217;s defined as &#8220;\033&#8243;. For convenience I&#8217;ve bundled the &#8220;[&#8221; on the end of my variable) followed by the foreground colour code, a semicolon, the background colour code and finally a closing &#8220;m.&#8221;</p>
<p>The escape character and the following options are cumulatively called an escape sequence.</p>
<p>After our string we restore the default colours using another escape character followed by &#8220;0m.&#8221;</p>
<p>There are a number of further codes we can use after our escape sequence to control the behaviour of our shell although most are fairly specific to the environment in which you run them.</p>
<p>Worth noting, something I played with after starting to use colour. I drafted a quick colour check step that could be added to any script before we start printing out illegible escape sequences that might not be interpreted. For example, when testing quickly in <a href="http://macromates.com">TextMate</a>&hellip;</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
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby -wdK</span>
&nbsp;
term = <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#40;</span>echo <span style="color:#ff6633; font-weight:bold;">$TERM</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>!
&nbsp;
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> term.<span style="color:#9900CC;">downcase</span> == <span style="color:#996600;">&quot;xterm-color&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Colour supported in <span style="color:#000099;">\0</span>33[32;40m#{term}<span style="color:#000099;">\0</span>33[0m!&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Unknown environment (#{term}).&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/07/puts-ruby-in-colour/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Repair permissions on network home folders</title>
		<link>http://www.theonlyjames.com/2008/07/repair-network-home-folders/</link>
		<comments>http://www.theonlyjames.com/2008/07/repair-network-home-folders/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 22:52:26 +0000</pubDate>
		<dc:creator>James</dc:creator>
		
		<category><![CDATA[geek]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[sysadmin]]></category>

		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.theonlyjames.com/?p=124</guid>
		<description><![CDATA[I had a problem to fix a few months back where by something like 1000 users had totally bricked their home folder permissions. Trying to propagate permissions from Workgroup Manager (it was a 10.4.11 server) kept hanging and would only fix home folders up to the letter &#8220;d.&#8221; It was at this point I was [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem to fix a few months back where by something like 1000 users had totally bricked their home folder permissions. Trying to propagate permissions from Workgroup Manager (it was a 10.4.11 server) kept hanging and would only fix home folders up to the letter &#8220;d.&#8221; It was at this point I was called in to write a script so a colleague could repair the permissions without running the risk of annihilating the home folders from the command line. <span id="more-124"></span></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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Name of group to apply</span>
new_group = <span style="color:#996600;">&quot;teachers&quot;</span>
&nbsp;
home_folders = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
sub_folders = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>Pictures Documents Library Music Movies Sites Desktop<span style="color:#006600; font-weight:bold;">&#41;</span>
d = <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> do_cmd<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>cmd<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#ff6633; font-weight:bold;">$DEBUG</span>
    cmd.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> c<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    cmd.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">`#{c}`</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
d.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>item<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>item<span style="color:#006600; font-weight:bold;">&#41;</span>
    home_folders <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> item
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
home_folders <span style="color:#006600; font-weight:bold;">-</span>= <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>. ..<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Home folders found: &quot;</span>, home_folders.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;, &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;&quot;</span>
&nbsp;
home_folders.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>item<span style="color:#006600; font-weight:bold;">|</span>  
  do_cmd<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;sudo chown #{item}:#{new_group} #{item}&quot;</span>, <span style="color:#996600;">&quot;sudo chmod 770 #{item}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  sub_folders.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>sub<span style="color:#006600; font-weight:bold;">|</span>
    do_cmd<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;sudo chown -R #{item}:#{new_group} #{item}/#{sub}&quot;</span>, <span style="color:#996600;">&quot;sudo chmod -R 770 #{item}/#{sub}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#ff6633; font-weight:bold;">$DEBUG</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;You are working in debug mode. No changes have been made.&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Any home folder will be owned by its respective user. The name of the folder will of course be the shortname, which made this a whole lot easier. Then it was just a case of picking a group and applying the changes to files and folders we knew were safe to change.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theonlyjames.com/2008/07/repair-network-home-folders/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
