<?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>AdamFranco.com &#187; Computers and Technology</title>
	<atom:link href="http://www.adamfranco.com/category/computers-and-technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adamfranco.com</link>
	<description>Musings, projects, software, and photography.</description>
	<lastBuildDate>Mon, 14 Jun 2010 16:03:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Adding reverse-proxy caching to PHP applications</title>
		<link>http://www.adamfranco.com/2010/06/14/adding-reverse-proxy-caching-to-php-applications/</link>
		<comments>http://www.adamfranco.com/2010/06/14/adding-reverse-proxy-caching-to-php-applications/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 16:03:57 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[reverse-proxy]]></category>
		<category><![CDATA[Varnish]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=426</guid>
		<description><![CDATA[Note: This is a cross-post of documentation I am writing about Lazy Sessions. Why use reverse-proxy caching? For most public-facing web applications, the significant majority of their traffic is anonymous, non-authenticated users. Even with a variety of internal data-cache mechanisms and other good optimizations, a large amount of code execution goes into executing a PHP [...]]]></description>
			<content:encoded><![CDATA[<p><em>Note: This is a cross-post of <a href="http://wiki.github.com/adamfranco/lazy_sessions/adding-reverse-proxy-caching-to-php-applications">documentation I am writing about Lazy Sessions</a>.</em></p>
<h1>Why use reverse-proxy caching?</h1>
<p>For most public-facing web applications, the significant majority of their traffic is anonymous, non-authenticated users. Even with a variety of internal data-cache mechanisms and other good optimizations, a large amount of code execution goes into executing a <span class="caps">PHP</span> application to generate a page even if the content of this page will be the same for many users. Code and query optimization are very important to improving the experience for all users of a web application, but even the most basic &ldquo;Hello World&rdquo; script will top out at about 3k requests/second due to the overhead of Apache and <span class="caps">PHP</span> &mdash; many real applications top out at less than 200 requests/second. Varnish, a light-weight proxy-server that can run on the same host as the webserver, can cache pages in memory and can serve them at rates of more than 10k requests/second with thousands of concurrent connections.</p>
<p>While the point of web-applications is to have content be dynamic and easily changeable, for most applications and most of the anonymous users, receiving content that is slightly stale (cached for 5 minutes or something similar) isn&rsquo;t a big deal. Sure, visitors to your blog might not see the latest post for a few minutes, but they will get their response in 4 milliseconds rather than 2 seconds.</p>
<p>Should your site get posted on Slashdot, a caching reverse-proxy server will give anonymous visitor #2 and up the same page from cache (until expiration), while authenticated users continue to have their requests passed through to the Apache/<span class="caps">PHP</span> back-end. Everyone wins.</p>
<p><span id="more-426"></span></p>
<h1>Caveats</h1>
<p>Before we get into how to set this up, you should be aware of a few caveats (in addition to increased complexity) that come with this scheme.</p>
<h2>1. Stale Content</h2>
<p>Ideally, pages would always be served from the cache for as long as they don&rsquo;t change, then the application would expire pages when they are changed on the back-end. Varnish has an <span class="caps">API</span> that supports this behavior and <a href="http://drupal.org/project/Varnish">Drupal Varnish module</a> is being developed to do this dynamic cache-clearing for Drupal sites, but overall, dynamic cache clearing is much more difficult to set up than time-based cache expiration.</p>
<p>When using time-based cache expiration, the challenge is to balance the needs for content freshness (shorter cache lifetimes) against the efficiency of cache hits (longer cache lifetimes will result in more clients using the cached versions). For content that doesn&rsquo;t need to be up-to-the-minute fresh, a cache lifetime of around 5 minutes might be a good starting point. If the content only changes daily at certain time, a fixed expiration time (shortly after the data sync) might be appropriate.</p>
<h2>2. Cookie Use</h2>
<p>If your application only uses a cookies set by PHP&rsquo;s <code>session_start()</code> function, then <code>lazy_sessions.php</code> should work transparently without modification of either that include file or your application (other than including the file). If your application sets other cookies then these will cause the reverse-proxy not to cache them unless you specifically exclude them in the reverse-proxy server&rsquo;s configuration.</p>
<h2>3. Data Caching in the <code>$_SESSION</code></h2>
<p>If you use the <code>$_SESSION</code> array as a data cache on anonymous requests, then these anonymous requests will be given a session cookie and their requests won&rsquo;t be served from the reverse-proxy&rsquo;s cache. Rather than using the <code>$_SESSION</code> array for non-user-specific data, cache such data with <span class="caps">APC</span> or memcached. This also has the advantage of such non-user-specific data not having to be rebuilt for every new client.</p>
<h2>4. <code>flush()</code> and output buffering</h2>
<p>The default <span class="caps">PHP</span> session handling mechanism adds the session cookie to the response headers right when <code>session_start()</code> is called and writes the data off to the file-system after the script exits and the data has been sent. This default behavior ensures that users will always get a session cookie and saves the session data as the final processing step after all class destructors have been called.</p>
<p>Since we don&rsquo;t want to always set a session cookie, we need to remove the <code>Set-Cookie</code> header before headers are sent to the client. Output buffering with <code>ob_start()</code> will ensure that we have a chance to decide to clear the <code>Set-Cookie</code> header at script shutdown.</p>
<p>In some cases (such as incrementally sending large binary files) we want to send the content body (and therefor also the headers) before the script exits using the <code>flush()</code> function. To ensure that the session cookie is properly removed <code>session_write_close()</code> must be called before <code>flush()</code> or any other code that causes headers to be sent.</p>
<h1>Implementation</h1>
<p>Implementing reverse-proxy caching has three steps: <span class="caps">PHP</span> changes to enable lazy sessions, <span class="caps">PHP</span> changes to set cache-controlling headers, and finally the reverse-proxy server setup. For this example I&rsquo;ll use the Varnish reverse-proxy server, but others could be used instead.</p>
<h2>1. <span class="caps">PHP</span>: Lazy Sessions</h2>
<p>The first thing that needs to happen to make anonymous requests cache-able in an application that uses sessions is to ensure that sessions are only started when there is session data to be stored. By default, PHP&rsquo;s session handling mechanisms add a session cookie to the response header and store a session data file on the server on page-load that calls <code>session_start()</code>. While this behavior makes it easy to write applications that use sessions, it effectively means that there is no way to differentiate between responses that are for a particular user and those that could be for many users.</p>
<p>Including the <a href="http://github.com/adamfranco/lazy_sessions/blob/master/lazy_sessions.php"><code>lazy_sessions.php</code> file</a> before <code>session_start()</code> is called will override the default session-handling mechanism with one that checks to see if there is any data in the <code>$_SESSION</code> array before sending the user a <code>Set-Cookie</code> header and storing a session file:</p>
<pre>
<code>&lt;?php

// Include files or other pre-session_start code

require_once('lazy_sessions/lazy_sessions.php');
start_session();

// The rest of the application code.
?&gt;
</code>
</pre>
<p>If your application needs to flush content and thereby send headers before script shutdown (such as incrementally sending file data), call <code>session_write_close()</code> if <code>session_start()</code> has been called for that script:</p>
<pre>
<code>&lt;?php

// Include files or other pre-session_start code

require_once('lazy_sessions/lazy_sessions.php');
start_session();

// other application code.

// If session_write_close() is not called before flushing, then the Set-Cookie
// header will be sent before our custom session handler has a chance to determine
// if a session is even needed.
session_write_close();

print "Hello";
flush();
print " World.";
flush();

?&gt;
</code>
</pre>
<h2>2. <span class="caps">PHP</span>: Cache-Control headers</h2>
<p>Now that we have our cookies straightened out, we need to ensure that our <span class="caps">PHP</span> scripts respond with <span class="caps">HTTP</span> headers that indicate that downstream clients such as our reverse-proxy and the user&rsquo;s browser are allowed to cache anonymous pages. There are a number of different <a href="http://wiki.github.com/adamfranco/lazy_sessions/cache-controlling-headers">Cache-Controlling Headers</a> that may affect whether a particular cache may store a given response. By default, <span class="caps">PHP</span> sets all of these headers to indicate that no caches may store any pages, ensuring that they are dynamic.</p>
<pre>
<code>&lt;?php

// If the session data is empty, then we could assume that there is no per-user data
// and that the response can be cached.
if (!count($_SESSION)) {

// Alternatively, we could check an application-specific value (such as a user-id)
// to determine if the response is for a particular user.
// if (!isset($_SESSION['user_id'])) {

// Cache for 5 minutes
$maxAge = 300;

header('Expires: '.gmdate('D, d M Y H:i:s', time() + $maxAge).' GMT', true);
header('Cache-Control: public, max-age='.$maxAge, true);
header('Pragma: ', true);
}

header('Vary: Cookie,Accept-Encoding', true);
</code>
</pre>
<p>The two most important headers with regard to caching with varnish are the following:</p>
<h3>The <code>Cache-Control</code> header.</h3>
<p>The <code>Cache-Control: public, max-age=300</code> header indicates to any clients (such as the Varnish caching proxy) that this response can be cached in public caches valid for many downstream clients. The <code>max-age</code> portion of the header indicates that the cache may store this response for 300 seconds.</p>
<p>As I understand it (possibly wrong) Varnish only looks at the <code>max-age</code> portion of the <code>Cache-Control</code> header when determining how long to store a response. Apparently it ignores the <code>Expires</code> header for its cache-expiration purposes, though this header is passed on to downstream clients.</p>
<h3>The <code>Vary</code> header</h3>
<p>The <code>Vary: Cookie,Accept-Encoding</code> header tells Varnish (and in-browser caches) that they should not respond with the cached version of a response if the request includes a cookie or a different cookie from the request that previously had its response cached. Similarly, if one client says that it accepts gzip encoding via an <code>Accept-Encoding: gzip</code> request header, then the cached response may be compressed with gzip and should not be sent in response to requests from clients that do not state that they accept gzip encoding.</p>
<p>While Varnish&rsquo;s behavior is to never cache or respond from cache when cookies are present, without the <code>Vary: Cookie</code> response header, browsers or other downstream caches may respond with a cached response valid for only anonymous users even though a cookie is now present.</p>
<p>See my notes on <a href="http://wiki.github.com/adamfranco/lazy_sessions/cache-controlling-headers">Cache-Controlling Headers</a> for more details about other headers and how they affect the Varnish cache and in-browser caches.</p>
<h2>3. Varnish (Reverse-Proxy) Configuration</h2>
<p>The <code>/etc/varnish/default.vcl</code> config file controls how Varnish responds to requests and responses, in particular whether or not it should cache or not. Below is the contents of my <code>default.vcl</code> file.</p>
<div>
<strong>Notes:</strong></p>
<ol>
<li>The backend portion is the default, you probably will want to modify this to point at your correct backend hosts and ports.</li>
<li>The <code>vcl_recv</code> and <code>vcl_hash</code> sections come directly from the <a href="https://wiki.fourkitchens.com/display/PF/Configure+Varnish+for+Pressflow?focusedCommentId=15335604">Pressflow wiki</a> and are set up to allow requests that include Google Analytics cookies to be cached while not caching requests that include other cookies.</li>
<li>The <code>vcl_fetch</code> section is the default with my addition of the lines to unset empty Set-Cookie headers that can&rsquo;t be removed from within <span class="caps">PHP</span> &lt; 5.3.</li>
</ol>
</div>
<pre>
<code>
backend default {
.host = "127.0.0.1";
.port = "80";
}

sub vcl_recv {
// Remove has_js and Google Analytics __* cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
// Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
// Remove empty cookies.
if (req.http.Cookie ~ "^\s*$") {
unset req.http.Cookie;
}

// Cache all requests by default, overriding the
// standard Varnish behavior.
// if (req.request == "GET" || req.request == "HEAD") {
//   return (lookup);
// }
}

sub vcl_hash {
if (req.http.Cookie) {
set req.hash += req.http.Cookie;
}
}

sub vcl_fetch {
if (!beresp.cacheable) {
	return (pass);
}

// If using PHP &lt; 5.3 there is no way to fully delete headers, so empty
// Set-Cookie headers may be in the response. Ignore these empty headers.
if (beresp.http.Set-Cookie ~ "^\s*$") {
	unset beresp.http.Set-Cookie;
}

if (beresp.http.Set-Cookie) {
	return (pass);
}
return (deliver);
}
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2010/06/14/adding-reverse-proxy-caching-to-php-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing users into Bugzilla</title>
		<link>http://www.adamfranco.com/2010/03/08/importing-users-into-bugzilla/</link>
		<comments>http://www.adamfranco.com/2010/03/08/importing-users-into-bugzilla/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 04:11:45 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Bugzilla]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=374</guid>
		<description><![CDATA[For the past 6 months our Web Application Development work-group has been Bugzilla as our issue tracker with quite a bit of success. While it has its warts, Bugzilla seems like a pretty decent issue-tracking system and is flexible enough to fit into a variety of different work-flows. One very important feature of Bugzilla is [...]]]></description>
			<content:encoded><![CDATA[<p>For the past 6 months our <a href="http://go.middlebury.edu/webservices">Web Application Development work-group</a> has been Bugzilla as our issue tracker with quite a bit of success. While it has its warts, Bugzilla seems like a pretty decent issue-tracking system and is flexible enough to fit into a variety of different work-flows. One very important feature of Bugzilla is support for LDAP authentication. This enables any Middlebury College user to log in and report a bug using their standard campus credentials.</p>
<p>While LDAP authentication works great, there is one problem: If a person has never logged into our Bugzilla, we can&#8217;t add them to the CC list of an issue. This is important for us because issues usually don&#8217;t get submitted directly to the bug tracker, but rather come in via calls, emails, tweets, and face-to-face meetings. We are then left to submit issues to Bugzilla ourselves to keep track of our to-do items. Ideally we&#8217;d add the original reporter to the bug&#8217;s CC list so that they will automatically be notified as we make progress on the issue, but their Bugzilla account must exist before we can add them to the bug.</p>
<p>Searching about the internet I wasn&#8217;t able to find anything about how to import LDAP users (or any kind of users) into Bugzilla, though I was able to find some <a href="http://groups.google.com/group/mozilla.support.bugzilla/browse_thread/thread/165d4fc1a8b4ad82/b1e31ad20bfef3f0">basic instructions</a> on how to create a single user via Bugzilla&#8217;s Perl API. To improve on the lack of user-import support I&#8217;ve created an Perl script that creates users from lines in a tab-delimited text file (<code>create_users.pl</code>) as well as a companion PHP script that will export an appropriately-formatted list of users from an Active Directory (LDAP) server (<code>export_users.php</code>).</p>
<p><span id="more-374"></span><br />
<a href='http://tmp.adamfranco.com/files/2010/03/BugzillaImport.zip'>BugzillaImport.zip</a> &#8212; Unzip in your Bugzilla directory, run via the command line. See below for examples.</p>
<h1>File Listings:</h1>
<h2>create_users.pl</h2>
<p>This script can safely be run repeatedly. Only new users not already in Bugzilla will be added, users matching existing email addresses will be skipped.</p>
<pre>#!/usr/bin/env perl
##########################################################
# This is a basic script to import users into Bugzilla.
#
# Users can be imported from tab-delimited text files or
# tab-delimited lines piped to STDIN. Lines should have 3
# columns: login	email	name
#
#
# Author:
#	Adam Franco (afranco@middlebury.edu)
# Date:
#	2010-03-08
# URL:
#	http://www.adamfranco.com/archives/374
# License:
#   The contents of this file are subject to the Mozilla Public
#   License Version 1.1 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.mozilla.org/MPL/
#
#   Software distributed under the License is distributed on an "AS
#   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
#   implied. See the License for the specific language governing
#   rights and limitations under the License.
##########################################################

use FindBin qw($Bin);
BEGIN {
    push @INC,$Bin;
    push @INC,$Bin."/lib";
    push @INC,$Bin."/lib/x86_64-linux-thread-multi";
}
use Bugzilla;
use Bugzilla::User;
use Error qw(:try);

sub usage {
    print "
Usage:
    $0 ListOfUsers1.txt [ListOfUsers2.txt [...]]
    $0 < ListOfUsers.txt

The ListOfUsers can be passed as either a file argument or passed to STDIN.

The ListOfUsers must be tab-delimited with the following columns:
login   email   name

";
    exit 1;
}

foreach (@ARGV) {
    if ($_ =~ /^-h|--help$/) {
        usage();
    }
}

my $lines = 0;
my $users = 0;
my $usersAdded = 0;
while (<>) {
    chomp; # Remove the trailing new-line.
    my($login, $email, $name) = split(/\t/, $_);

    if ($login &#038;&#038; $email &#038;&#038; $name &#038;&#038; $login =~ /[a-z0-9]+/ &#038;&#038;  $email =~ /[a-z0-9]+.*@.*[a-z0-9]+/ &#038;&#038; $name =~ /[a-z]+/) {
        if (is_available_username($email)) {
            try {
                my $user = Bugzilla::User->create({
                    login_name    => $email,
                    realname      => $name,
                    cryptpassword => '*',
                    disable_mail  => 0,
                    extern_id     => $login
                });
                print "Account for " . $user->login . " was created.\n";
                $usersAdded++;
            } catch Error with {
                my $ex = shift;
                my $error = "Error: $ex";
                $error =~ s/\n|\r/ /g;
                print $error."\n";
            };
        }

        $users++;
    }
    $lines++;
    close (ARGV) if (eof);
}

if (!$lines) {
    print "No input lines given.\n\n";
    usage();
}

print "\n$lines lines evaluated, $users user records checked, $usersAdded users added.\n";

exit 0;
</pre>
<h2>export_users.php</h2>
<pre>#!/usr/bin/env php
&lt;?php
##########################################################
# This is a basic script to export users from an
# MS Active Directory via LDAP in the format required
# by create_users.pl.
#
# Authors:
#	Adam Franco (afranco@middlebury.edu)
#	Ian McBride (imcbride@middlebury.edu)
# Date:
#	2010-03-08
# URL:
#	http://www.adamfranco.com/archives/374
# License:
#   The contents of this file are subject to the Mozilla Public
#   License Version 1.1 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.mozilla.org/MPL/
#
#   Software distributed under the License is distributed on an "AS
#   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
#   implied. See the License for the specific language governing
#   rights and limitations under the License.
##########################################################

$ldaphost = "ldap.example.com";
$ldapport = 389;
$ldapuser = "username";
$ldappass = "password";
$baseDN = "DC=example,DC=com";

$connection = ldap_connect($ldaphost, $ldapport);

if (!$connection) die();

if (ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION,3) === FALSE) die();

if (ldap_set_option($connection, LDAP_OPT_REFERRALS,0) === FALSE) die();

$bind = ldap_bind($connection, $ldapuser, $ldappass);

if (!$bind) die();

$filter = "(&#038;(objectClass=User)(!(objectClass=Computer)))";

$search = ldap_search($connection, $baseDN, $filter, array("samaccountname", "mail", "givenname", "sn"));

$entries = ldap_get_entries($connection, $search);

print "samaccountname\temail\tname\n";

foreach($entries as $entry) {
  if(isset($entry['samaccountname'])) {
    print iconv('UTF-8', 'UTF-8//IGNORE', $entry['samaccountname'][0]);
  }
  print "\t";

  if(isset($entry['mail'])) {
    print iconv('UTF-8', 'UTF-8//IGNORE', $entry['mail'][0]);
  }
  print "\t";

  $name = '';
  if(isset($entry['givenname'])) {
    $name .= iconv('UTF-8', 'UTF-8//IGNORE', $entry['givenname'][0]);
  }  $name .= ' ';
  if(isset($entry['sn'])) {
    $name .= iconv('UTF-8', 'UTF-8//IGNORE', $entry['sn'][0]);
  }
  print trim($name);

  print "\n";
}
</pre>
<h1>Example Usage</h1>
<p>After unzipping the scripts in your Bugzilla directory you can use the <code>create_users.pl</code> script right away. To use <code>export_users.php</code> you will need to edit it and add your LDAP server configuration.<br />
<code>[root@hostname /var/www/htdocs/bugzilla/]# ./export_users.php | ./create_users.pl</code></p>
<p>If you&#8217;d rather import users from another source, simply create one or more tab-delimited text files that have the following columns:<br />
login&nbsp;&nbsp;&nbsp;&nbsp;email&nbsp;&nbsp;&nbsp;&nbsp;name<br />
<code>[root@hostname /var/www/htdocs/bugzilla/]# ./create_users.pl users.txt otherusers.txt</code></p>
<p>You can pipe tab-delimited data to the script as well:<br />
<code>[root@hostname /var/www/htdocs/bugzilla/]# head -n 20 users.txt | ./create_users.pl</code></p>
<h2>Update:</h2>
<ul>
<li>Changed the license statement to the MPL be compatible with the rest of Bugzilla</li>
<li>Changed the password to &#8216;*&#8217; based on Max&#8217;s suggestion</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2010/03/08/importing-users-into-bugzilla/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The future of phones: Google Voice, Skype, mobile, and more</title>
		<link>http://www.adamfranco.com/2009/11/08/the-future-of-phones-google-voice-skype-mobile-and-more/</link>
		<comments>http://www.adamfranco.com/2009/11/08/the-future-of-phones-google-voice-skype-mobile-and-more/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 05:21:04 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google-voice]]></category>
		<category><![CDATA[phones]]></category>
		<category><![CDATA[telephony]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=319</guid>
		<description><![CDATA[As members of the under-30 club, my wife Sarah and I have come into adulthood in the age of mobile phones. I got my first cell phone right after college and Sarah has had hers since she was 14; neither of us has ever had a land-line of our own. While the mobile-only lifestyle has [...]]]></description>
			<content:encoded><![CDATA[<p>As members of the under-30 club, my wife Sarah and I have come into adulthood in the age of mobile phones. I got my first cell phone right after college and Sarah has had hers since she was 14; neither of us has ever had a land-line of our own.</p>
<p>While the mobile-only lifestyle has generally worked great for us over the years, it does have downsides that have become more apparent as our lifestyles have shifted to a more settled routine. Currently Sarah and I find ourselves generally splitting our time between work and home. At work we each have an office phone supplied, but we had only had our mobile phones at home. An unfortunately common occurrence was for one of us to come home and leave the mobile on silent/vibrate in a coat pocket and become unreachable. After a few incidents of being stranded, stood up, or not getting the message to pick up milk we decided that a home phone was needed &#8212; but were shocked to find that a local-only land-line would run us $40 per month (about the same as a cell phone plan in this area).</p>
<p>We were in search of a solution that would allow us to have a phone ringing audibly at home, keep our mobile phones for mobile usage, and come in at less than $120/month (if not lower our bills). Our solution is shown in the diagram below. While it looks a bit complicated, it meets our goals, didn&#8217;t require any tricky setup, and comes in at a grand total of $50/month for maintaining two mobile phones and a home phone. It has the added benefits of a single number to reach each of us and Google&#8217;s snazzy transcribed-voice-mail service.</p>
<div id="attachment_320" class="wp-caption aligncenter" style="width: 510px"><a href="http://tmp.adamfranco.com/files/2009/11/Phone-System-1.png"><img src="http://tmp.adamfranco.com/files/2009/11/Phone-System-1.png" alt="New phone system with Google Voice  (click to enlarge)" title="Phone System 1" width="500" class="size-full wp-image-320" /></a><p class="wp-caption-text">New phone system with Google Voice (click to enlarge)</p></div>
<h2>The new home phone: Skype + a handset</h2>
<p>The first piece of the puzzle was to purchase a handset (the <a href="http://www.amazon.com/gp/product/B002V45UEE">IPEVO SO-20</a>) that sits at home on our wireless network, signed in to my <a href="http://skype.com/">Skype</a> account. This handset works just like the Skype-application on a desktop computer, but doesn&#8217;t require keeping a large computer on to make or receive Skype calls. In addition to making free Skype-to-Skype calls, Skype also offers services for making calls from your Skype client to normal telephone numbers (known as &#8220;<a href="http://www.skype.com/intl/en/allfeatures/callphones/">Skype-Out</a>&#8220;) as well as a service which provides you with a telephone number that will ring your Skype client (known as &#8220;<a href="http://www.skype.com/intl/en/allfeatures/onlinenumber/">Skype In</a>&#8220;). Skype-Out charges a minimal 2-cents/minute for calls to most of the world and maintaining the Skype-In number costs $3/month with no charge for talk-time.</p>
<p>We&#8217;ve been using the Skype phone for a few months now and have been very pleased with it. We notice a 1-1.5 second delay in hearing the caller when we first answer a call. This was a little confusing at first and resulted in a lot of &#8220;Hello? Hello? Can you hear me?&#8221; back-and-forth with the caller, but the delay is only at connection time and saying &#8220;Hello?&#8221; and then just pausing for a moment gives the call time to connect fully. Once in a call, the audio quality is generally a bit better than my mobile phone.</p>
<h2>Routing calls with Google Voice</h2>
<p>With the Skype-phone in place we now had a number that would reliably ring at home and costs us less than $10/month for a few hours of incoming and outgoing calls to anywhere in the world. Now the question is: How do we get people to call us on the Skype-phone rather than our mobile phones? Enter (from stage left) Google Voice.</p>
<p><a href="http://www.google.com/googlevoice/about.html">Google Voice</a> (from here out referred to as &#8220;GV&#8221;) is at its heart a phone-number forwarding service. The basic idea is that you get a GV phone number and then in your account settings, configure it to forward incoming calls to one or more other phone numbers. When a call comes in, all of your phones ring at the same time (this can be quite shocking if you have them in close proximity) and you pick up whichever one is at hand (and doesn&#8217;t incur a usage fee if you want to avoid that). Once you&#8217;ve picked up one phone the others stop ringing and you talk away.</p>
<p>I have my GV set up to ring three phones, my mobile number, our Skype-In number, and my work number. Since I spend the majority of my time either at work or home, most of the time I pick up calls at one of those two places. This cuts my mobile phone usage to only a few days per week, opening up other options for cutting costs.</p>
<h2>Prepaid mobile + minimal usage = savings</h2>
<p>Another driver for this entire phone-system change was that Unicel&#8217;s network in Vermont was recently sold to AT&#038;T. After some bad customer-service experiences with Verizon I switched to Unicel in 2007 and was very happy with their service. In particular, they used unlocked GSM phones and didn&#8217;t charge for incoming calls or text messages, all for $35/month. With the sale to AT&#038;T I was looking at an increase to $40/month for the minimal plan plus airtime usage for incoming calls.</p>
<p>With the Skype-phone in place and GV forwarding calls to all numbers, our mobile-phone usage wasn&#8217;t as high, allowing us to try some other options. Rather than signing up for a new AT&#038;T contract, I instead kept the unlocked phone I used with Unicel and went with a prepaid (&#8220;<a href="http://www.wireless.att.com/cell-phone-service/go-phones/pyg-plans-phones.jsp">GoPhone</a>&#8220;) plan from AT&#038;T. Rather than paying a monthly fee, I pre-pay on my account and then only have my account balance debited when I use the phone. I&#8217;m currently using the version of the plan where I pay $1/day on days that I use the phone, plus 10-cents/minute. While this sounds like it would add up, with GV routing calls to my other numbers I&#8217;ve averaged $16/month in mobile charges for the past two months. Also, unlike the monthly phone contract this has the potential to get much lower as more friends and family learn of my GV number and stop calling my mobile directly.</p>
<h2>All said and done</h2>
<p>From a pure cost perspective this telephony setup has been a big success. From two cell phones at $40/month each for a total of $80/month (with additional for a home phone); we&#8217;ve now gone to $3/month for the Skype-In number with ~$3/month of Skype-out calls from home, plus about $16/month each in mobile phone charges leaves us with a new total of a bit under $40/month. We had the additional $140 up-front cost for the IPEVO Skype-phone, but amortized over a year that still leaves us at about $50/month, with the potential to drop costs further if our cell-phone usage drops.</p>
<p>The non-monetary benefits are certainly harder to quantify. The biggest benefit I find is the increased control over my phone environment. For example, I could swap out the Skype-phone for something else (or get rid of it entirely) and no callers would know the difference. Once my contacts are all using my GV number, the same is true of my mobile phone.</p>
<p>Other features of GV such as voicemail transcription, caller filtering, scheduling of times when each phone should ring, and free SMS sending are all pretty neat too, but I haven&#8217;t yet made heavy use of them.</p>
<p>Now for the downsides:</p>
<ul>
<li>Complexity: While I find the increased flexibility valuable and none of the steps are challenging, others may find the whole thing not worth the hassle to set up.</li>
<li>A new number: While I now have one number that will ring all of my phones, Google currently doesn&#8217;t support transferring existing numbers to their service. I&#8217;m now trying to wean friends and family off of the mobile number I&#8217;ve had for 7 years.</li>
<li>Apparently some have found that using GV causes delays or other audio degradation. I haven&#8217;t noticed this myself.</li>
<li>One more thing relying on Google. Since all of the phone companies hosted NSA <a href="http://en.wikipedia.org/wiki/NSA_warrantless_surveillance_controversy">warrentless-wire-tapping</a> computers in their data-centers, I&#8217;m not particularly worried about Google having my calling data as well. That said, I&#8217;m relying on them to stick around for my email, searching, RSS reading, spreadsheets, and now call-routing.</li>
<li>Users don&#8217;t see my GV number in the caller id. You can make calls with GV so that the person you are calling sees your GV number in the caller-id, but this requires either initiating the call from the GV website (your phone rings first), or dialing your GV number, then from there initiating the call. I find this to be too much hassle so I never bother</li>
</ul>
<p>One final note: If you are a friend, family, or colleague who I missed in my number-update-email, let me know and I&#8217;ll send you my new GV number. <img src='http://www.adamfranco.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2009/11/08/the-future-of-phones-google-voice-skype-mobile-and-more/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>High-availability Drupal &#8212; File-handling</title>
		<link>http://www.adamfranco.com/2009/09/09/high-availability-drupal-file-handling/</link>
		<comments>http://www.adamfranco.com/2009/09/09/high-availability-drupal-file-handling/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:18:27 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=266</guid>
		<description><![CDATA[One of the requirements in the migration of our web sites to Drupal is that we create a robust and redundant platform that can stay running or degrade gracefully when hardware or software problems inevitably arise. While our sites get heavy use from our communities and the public, our traffic numbers are no where near [...]]]></description>
			<content:encoded><![CDATA[<p>One of the requirements in the migration of our <a href="http://www.middlebury.edu/">web</a> <a href="http://www.miis.edu">sites</a> to <a href="http://drupal.org/">Drupal</a> is that we create a robust and redundant platform that can stay running or degrade gracefully when hardware or software problems inevitably arise. While our sites get heavy use from our communities and the public, our traffic numbers are no where near those of a top-1000 site and could comfortably run off of one machine that ran both the database and web-server.<br />
<div id="attachment_297" class="wp-caption aligncenter" style="width: 541px"><img src="http://tmp.adamfranco.com/files/2009/09/1-SingleMachine.jpg" alt="Single Machine Configuration" title="Single Machine Configuration" width="531" height="332" class="size-full wp-image-297" /><p class="wp-caption-text">Single Machine Configuration</p></div><br />
This simple configuration however has the major weakness that any hiccups in the hardware or software of the machine will likely take the site offline until the issues can be addressed. In order to give our site a better chance at staying up as failures occur, we separate some of the functional pieces of the site onto discrete machines and then ensure that each function is redundant or fail-safe. This post and the next will detail a few of the techniques we have used to build a robust site.</p>
<p><span id="more-266"></span></p>
<h2>Pull out the database, use multiple web-servers</h2>
<p>The two main components of Drupal (and most similar web applications) are the webserver, which handles PHP execution and file-serving; and the MySQL database, which stores all data with the exception of uploaded files. By putting the database on a separate machine we can can have multiple machines acting as front-end web-servers, both of them reading and writing to the same database. In this way, it doesn&#8217;t matter which web-server handles a given request as they will both get the same information out of the database. With two or more web-servers, our platform gains some redundancy since one web-server can fail while the second keeps handling requests.</p>
<p>With both web-servers point at the same database server, the database server still remains a single point of failure. Database clustering can alleviate this problem, but will be the subject of a future post.</p>
<h2>Multiple web-server challenges</h2>
<p>This redundancy does come at a cost in complexity however, since we need to ensure that any uploaded files are available on both web-servers. There seem to be <a href="http://groups.drupal.org/node/1648">two primary ways</a> of tackling this problem (without resorting to costly and complex distributed file-system tools). The first is use rsync to copy files between the web-servers every few minutes.<br />
<div id="attachment_299" class="wp-caption aligncenter" style="width: 610px"><img src="http://tmp.adamfranco.com/files/2009/09/2a-Two-Web-servers-rsync.jpg" alt="Two web servers with rsync" title="2a - Two Web servers - rsync" width="600" class="size-full wp-image-299" /><p class="wp-caption-text">Two web servers with rsync</p></div><br />
While this is reasonably simple to set up between two web-servers, it comes with significant downsides:</p>
<ul>
<li>Files cannot be deleted in the sync as newly-added files will exist on only one web-server. Since the sync is two-way, there is no way for the rsync processes to tell the difference between a new file and a deleted file.</li>
<li>Requests that come to the &#8220;other&#8221; web-server will not be able to access new files until the sync happens.</li>
<li>If additional web-servers are added, the sync process needs to be updated on every existing web-server to include the new web-server</li>
</ul>
<p>The other alternative is to store uploaded files on a separate file-server, whose upload directory is mounted on each web-server using NFS. This method eliminates the synchronization problems, since all web-servers are essentially writing to the same directory.<br />
<div id="attachment_300" class="wp-caption aligncenter" style="width: 610px"><img src="http://tmp.adamfranco.com/files/2009/09/2b-Two-Web-servers-nfs.jpg" alt="Two web servers with NFS" title="2b - Two Web servers - nfs" width="600" class="size-full wp-image-300" /><p class="wp-caption-text">Two web servers with NFS</p></div><br />
On top of the complexity of adding a fourth machine (the file-server) to our mix, this method also leaves us with the file-server as a single point of failure &#8212; were it to go down, no uploaded files would be accessible.</p>
<h2>Best of both worlds</h2>
<p>In order to better solve this problem, the approach we took is to go the NFS route, but augment it with a backup copy of the files stored on the local file-system of each web-server. Every ten minutes or so a script (<a href='http://tmp.adamfranco.com/files/2009/09/sync_files.sh'>sync_files.sh</a>) runs that checks to see if the shared NFS directory is available, and if so syncs the uploaded-files to a backup location on the web-server&#8217;s file-system. This backup copy has its permissions set so that the Apache process cannot write to it, preventing synchronization problems if the shared NFS directory goes offline and we need to serve files out of the backup copy.<br />
<div id="attachment_302" class="wp-caption aligncenter" style="width: 610px"><img src="http://tmp.adamfranco.com/files/2009/09/3-Two-Web-servers-nfs+backup1.jpg" alt="Two web servers with NFS and local backup copies." title="3 - Two Web servers - nfs+backup" width="600" class="size-full wp-image-302" /><p class="wp-caption-text">Two web servers with NFS and local backup copies.</p></div><br />
A second script (<a href='http://tmp.adamfranco.com/files/2009/09/check_link.sh'>check_link.sh</a>) runs every minute and checks to see if the shared NFS directory is available. If it is offline, this script changes the symbolic link of our &#8220;files&#8221; directory so that Drupal will now use the read-only backup copy for its files. If the NFS directory comes back online, this script will again update the symbolic link to point at our writable shared NFS directory.</p>
<p>An important consideration in this setup is that the NFS share is mounted in &#8216;soft&#8217; mode so that file-access errors will time out quickly and allow for a timely switch-over to our backup files.<br />
<div class="wp-caption alignnone" style="width: 610px">
<pre>files.example.edu:/images       /mnt/files     nfs     soft    0 0</pre>
<p><p class="wp-caption-text">An example 'soft' mount line in /etc/fstab</p></div></p>
<p>If the default &#8216;hard&#8217; NFS mount is used, the check_link processes will hang indefinitely while trying to communicate with the file-server and never switch to our backup files.</p>
<p>Here is an example layout on the web-server to accomplish this setup:</p>
<pre style='width: 100%'># The scripts that will be run by cron:
/usr/local/bin/check_link.sh  # Run every minute
/usr/local/bin/sync_files.sh   # Run every 10 minutes

# The mounted NFS share:
/mnt/files/

# The backup copy of files:
/srv/files_read_only/

# The 'files' symbolic link, pointing normally at the NFS share:
/srv/files/ => /mnt/files/
# On NFS failure, this link will be switched to the backup directory:
/srv/files/ => /srv/files_read_only/

# The Drupal code directory:
/srv/drupal/
# The files directory for a site is a link into the switched files link
/srv/drupal/sites/www.example.com/files/ => /srv/files/www.example.com/files/
</pre>
<p>By mounting the shared NFS directory, keeping a read-only local copy of the files, and monitoring the state of the NFS directory we gain the following benefits:</p>
<ul>
<li>No problems with synchronization as all web-servers share the same remote filesystem.</li>
<li>Synchronization of the local backup copies is not a problem as this is always a one-way sync rather than a two-way sync between different web-servers.</li>
<li>While the NFS file-server is still a single point of failure, read access to the uploaded files (via the backup copy) will be restored after a maximum of one minute plus the NFS time-out (2 minutes by default for &#8216;soft&#8217; mounts).</li>
<li>The web-servers don&#8217;t need to know about each other, easing configuration if additional web-servers are added.</li>
</ul>
<p>This configuration adds an extra machine to the platform mix and a bit of complexity, but it makes normal operation robust (instant file availability to all web-servers) and allows for graceful degradation (file-access becomes read-only) if the file-server goes down.</p>
<p><em>Many thanks to our system administrator, Mark Pyfrom, for all of his help in developing and testing this platform.</em></p>
<p><em>* Update on 2009-09-10: added note about &#8216;soft&#8217; NFS mounts and an example file-system layout.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2009/09/09/high-availability-drupal-file-handling/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Time Machine Backups For The Moderately Paranoid</title>
		<link>http://www.adamfranco.com/2009/07/29/time-machine-backups-for-the-moderately-paranoid/</link>
		<comments>http://www.adamfranco.com/2009/07/29/time-machine-backups-for-the-moderately-paranoid/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 00:28:05 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Computers and Technology]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=189</guid>
		<description><![CDATA[I have recently reworked by computer backup strategy to ensure a high degree of reliability by backing my Mac laptop to two drives in two locations using Time Machine. These backups are encrypted as well to allow me to store them in non-ultra-secure locations while not increasing my exposure to identity theft or snooping. While [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently reworked by computer backup strategy to ensure a high degree of reliability by backing my Mac laptop to two drives in two locations using Time Machine. These backups are encrypted as well to allow me to store them in non-ultra-secure locations while not increasing my exposure to identity theft or snooping. While not a trivial process, it is one that is quite approachable with a little effort and a guiding purpose.</p>
<p>As a tribute to <em><a href="http://www.thisamericanlife.org/">This American Life</a></em>, I present you with an essay in three acts. In <a href="http://www.adamfranco.com/archives/189#ActOne">Act One</a> we&#8217;ll see my older backup system and how it saved me, yet left me wanting more; <a href="http://www.adamfranco.com/archives/189#ActTwo">Act Two</a> discusses a philosophy of backups appropriate for the <em>moderately</em> paranoid;  and in <a href="http://www.adamfranco.com/archives/189#ActThree">Act Three</a> we&#8217;ll go step-by-step through the process of implementing that philosophy.<br />
<span id="more-189"></span></p>
<p><a name='ActOne'></a></p>
<h2>Act One: A Complex Old (But Successful) Backup System</h2>
<p>For the past four years or so I&#8217;ve been successfully running automated backups of my Mac laptop using <a href="http://rdiff-backup.nongnu.org/">rdiff-backup</a> to send incremental backups over the network to a Linux file-server. These backups occurred every day at 12:30 and every night at 2am when there was a fast-enough network connection. This solution was a bit complex to set up &#8212; I wrote my own scripts for testing network connection speed so that it wouldn&#8217;t start backing up over dial-up or other slow connections &#8212; but it did the job of ensuring that I always had a good copy of my data.</p>
<p>In late 2007 Apple released OS X 10.5 (Leopard) with its built-in Time Machine backup system. As I am a bit paranoid about my data, I set up Time Machine to back up to a 150GB external Firewire drive. Since the external drive was smaller than my laptop&#8217;s drive I was only able to back up my user directory, not the whole system. The rdiff-backup system kept running in the background as well.</p>
<p>Fast-forward to June 2009 and my current laptop hard drive has died and gone to meet its maker: Apple (via AppleCare). Incidentally I got a great repair with the display (dead pixels), keyboard, aluminum chassis (deformed), and battery (swelling) all replaced in addition to the faulty drive. Almost a new computer! Now time to restore my data.</p>
<p>Since I didn&#8217;t have a full-system Time Machine backup, I couldn&#8217;t use the one-click-restore option to get my system back so my recovery process was:</p>
<ol>
<li>Do a fresh install of OS X</li>
<li>Restore my user account from my Time Machine backup</li>
<li>Restore my applications and other system utilities from my rdiff-backup backups</li>
</ol>
<p>While this process worked out and I wasn&#8217;t in danger of loosing any important data, I did end up wasting an entire weekend getting the whole system back up to snuff, copying over pieces I missed, reinstalling plugins, etc. I wished that I had a full-system Time Machine backup that would have allowed the single-click method to restore my machine. Once I got the laptop back up and running I decided it was time to set up a more robust backup solution that would be easier to restore from and provide a similar or greater amount of protection.</p>
<p><a name='ActTwo'></a></p>
<h2>Act Two: A Backup Philosophy For The Moderately Paranoid</h2>
<p>If you aren&#8217;t doing backups of your computer, please do! Even going the most basic route and plugging in a single external drive and choosing it to be used by Time Machine is an immense improvement over not having any backups. In the past 10 years I&#8217;ve had 6 hard drives die on me, making them (and batteries) the most likely parts of a modern computer to fail. Backups are critically important to keeping you safe when those failures happen. Time Machine and other similar programs incrementally back up your data every few hours so that only the files that have recently changed need to be transferred to the backup drive. This allows you to use backup drives that are only a bit bigger than your primary drive as well as to view differences in files over time. Incremental backups are pretty neat and much faster and more space-efficient than duplicating the entire drive every once and a while. Faster and more efficient also mean that there is less penalty (in time and cost) for doing backups, so they happen more frequently, making it much more likely that you have a recent backup when your computer suddenly goes on the fritz.</p>
<p>Unfortunately, there are a few situations that a single backup drive won&#8217;t help with:</p>
<ul>
<li>Lightning strikes while your backup drive is plugged into your computer, frying both the computer and the backup drive</li>
<li>Your house burns down, gets hit by a tornado, or is robbed and both the laptop and the drive are gone</li>
</ul>
<p>The best way to prevent these and similar situations is to have backups stored in a place where your laptop is not. While you can do this by sending your data over the internet to a remote file-server, current DSL upload speeds aren&#8217;t fast enough to make this a sure-thing. Another option is to keep an external drive where your computer is not, the catch however is that an external drive needs to be where your computer <em>is</em> in order to get data. My solution to this problem: two backup drives, one in my desk at work, one at home. Since my laptop is either with (or without) me at home, with me at work, or with me somewhere else I always have a copy of my data in a location remote to my laptop.</p>
<p>Though I trust my office-mates, leaving a drive in my desk unattended does open up another possibility of data theft by intruders and a corresponding increase in exposure to it being misused for identity theft. I&#8217;m pretty good at using <a href="http://support.apple.com/kb/HT1578">encrypted disk-images</a> to keep my tax documents and similar things safe, but I&#8217;d rather not have some else rifling through the rest of my digital life. While it requires a few work-arounds to set up initially, Time Machine will back up to an encrypted disk-image on a USB/Firewire drive, giving you a backup that nothing except your laptop can access without entering your password.</p>
<p>To recap, the primary tenets of this philosophy are:</p>
<ol>
<li>Make backups!</li>
<li>Make multiple backups and keep them in different physical locations to mitigate against catastrophies</li>
<li>Encrypt your backups to keep prying eyes away when you can&#8217;t fully prevent physical access to them by others</li>
</ol>
<p><strong>A note to the <em>fully</em> paranoid:</strong> The safety of your data can be significantly increased (at a significant expense and hassle) by also backing up to a third drive, then periodically rotating one of your backup drives into a safe-deposit box in your bank. Periodically mailing a drive to a friend or family member far away is another option.</p>
<p><a name='ActThree'></a></p>
<h2>Act Three: Step By Step Into Mutiple Encrypted Time Machine Backups</h2>
<p>Without further ado, here is how to set this up.</p>
<ol>
<li>Purchase or acquire two USB or Firewire external hard-drives, preferably larger than the drive you want to back up. They may not need to be identical, but mine are. I purchased two <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822242014">Cirago 320GB USB drives</a> since they were cheap ($66 each), big enough, and don&#8217;t require a wall-wart for power.</li>
<li>Time Machine won&#8217;t let you choose a disk image directly as a backup destination, but it does create images for backing up to network drives. We have to jump through a few hoops to get an encrypted image created and onto our external drive. (based on <a href="http://www.macosxhints.com/article.php?story=20071110145136486" target="_blank">these instructions</a>)
<ol>
<li>Open the Terminal and run the following command to allow Time Machine to back up to non-TimeCapsule(TM) network drives:<br />
<code>defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1</code></li>
<li>Connect to another computer over the network in Finder using &#8220;Go&#8221; &#8211;> &#8220;Connect to Server&#8221;. I happened to just connect to my desktop at work, but it can be any computer. We won&#8217;t be actually backing up there, just getting Time Machine to initialize it&#8217;s backup image. </li>
<li>Open the Time Machine preferences and choose to back up to the network drive you just connected to. Time Machine will do a lot of &#8220;Preparing for Backup&#8221;; once it starts transferring data, just stop the backup.</li>
<li>Time Machine will have created a disk image on your network drive in which it was beginning to back up to. This disk image will be called something like &#8220;ComputerName_01a8b93325acf.sparsebundle&#8221;. Copy that disk image onto your external hard drive and delete it from the network drive. </li>
</ol>
<p>You are now done with the network drive.</li>
<li>The disk image is not encrypted yet, so we must do that. Open the Terminal and cd to your external drive (where the disk image should be, the disk image itself shouldn&#8217;t be mounted), copy the disk image to a temporary name, encrypt it, then delete the temporary version:
<pre>cd /Volumes/BackupDrive/
cp ComputerName_01a8b93325acf.sparsebundle ComputerName_01a8b93325acf.sparsebundle-temp
hdiutil convert -format UDSB -o ComputerName_01a8b93325acf.sparsebundle  -encryption AES-256 ComputerName_01a8b93325acf.sparsebundle-temp
rm ComputerName_01a8b93325acf.sparsebundle-temp
</pre>
</li>
<li>You should now have your external drive with the encrypted disk image on it. Now you need to make sure that the System keychain has the password for the encrypted image so that it can back up automatically without prompting you for a password every 10 minutes. Mount the disk image, enter your password, and check the &#8220;Save Password in Keychange&#8221; box. Then, open the Keychain Access utility and search for &#8216;sparsebundle&#8217;. Right-click on the keychain item and paste it into the &#8220;System&#8221; keychain.</li>
<li>Unmount the disk image.</li>
<li>Open Time Machine Preferences and select your external drive as the backup destination. Time Machine is smart enough to use the encrypted image if it sees it because of the disk image name and possibly other file metadata. Time Machine should mount the disk image without prompting for a password and back up to it. This will take a long time.</li>
</ol>
<p>At this point you should now have Time Machine automatically backing up to an encrypted disk image on one external disk. You can test that the disk image is encrypted by trying to mount it on another machine. It should require a password.</p>
<p>Time Machine keeps its last-backup-position information on the backup drive itself and will happily back up incrementally from the point it left off on that drive no matter how many other drives you back up to in between. Unfortunately the default behavior of the Time Machine preferences requires you to open the preferences and select the new backup drive every time you want to switch. To get around this and have both drives work automatically whenever they are plugged in we need to make the second drive a clone of the first one. That way, Time Machine won&#8217;t be able to tell them apart and will back up to whichever one is plugged in.</p>
<p>To clone the drive, plug in both drives and use Disk Utility&#8217;s &#8216;Restore&#8217; tab to restore from the drive with the backup image to your empty second drive. Once the drive is cloned, either one plugged in individually should be automatically used by Time Machine for backups.</p>
<p><strong>Caveats:</strong></p>
<ul>
<li>Some people have run into an issue when backing up to disk-images on a network share where the disk fills up and rather than just deleting the oldest few backups, all but the latest backup versions are deleted. It is unknown whether or not this will happen with disk images on USB/Firewire drives.</li>
<li>While I can browse the backup disk image and see all of the incremental backup versions, this history is not browsable through the Time Machine history-browser user-interface.</li>
</ul>
<p><strong>References and more help: </strong></p>
<ul>
<li><a href="http://www.macosxhints.com/article.php?story=20071110145136486">Mac OS X Hints &#8211; 10.5: Ease Time Machine networked backups</a></li>
<li>
<a href="http://forums.macosxhints.com/archive/index.php/t-94173.html">Mac OS X Hints &#8211; Encrypting Time Machine Backup?</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2009/07/29/time-machine-backups-for-the-moderately-paranoid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby and Rails Thoughts</title>
		<link>http://www.adamfranco.com/2009/02/03/ruby-and-rails-thoughts/</link>
		<comments>http://www.adamfranco.com/2009/02/03/ruby-and-rails-thoughts/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 05:23:59 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=95</guid>
		<description><![CDATA[I&#8217;ve decided to learn a few new programming languages and web frameworks over the next year or so to broaden my experience and just to have fun. I figured that I&#8217;d start with Ruby and its Rails framework. Python (and its Django framework) are also at the top of my list, but I seem to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to learn a few new programming languages and web frameworks over the next year or so to broaden my experience and just to have fun. I figured that I&#8217;d start with <a href="http://www.ruby-lang.org/en/">Ruby</a> and its <a href="http://rubyonrails.org/">Rails</a> framework. <a href="http://www.python.org/">Python</a> (and its <a href="http://www.djangoproject.com/">Django</a> framework) are also at the top of my list, but I seem to run into Ruby programs more often and the Rails fanatics are loudest, so I&#8217;m starting there.</p>
<p>After about 5 evenings of documentation and tutorial reading intermixed with a bit of programming I&#8217;m about 1/3 of the way through my first real Rails application and am beginning to have a few thoughts on Ruby, Rails, and the process of learning new languages and frameworks:</p>
<p><strong>Languages are Easy&#8230;</strong><br />
This might have something to do with how my brain works, but I find learning new programming languages quite easy and extremely interesting. Some of the things I find really neat about the Ruby language:</p>
<ul>
<li>Full-on object-oriented &#8212; I really like the consistency</li>
<li><a href="http://www.rubycentral.com/pickaxe/tut_containers.html#S2">Blocks and Iterators</a> &#8212; I fell in love with blocks in <a href="http://www.squeak.org/">SmallTalk</a>, they are a great concept and so much easier to use than named callback functions</li>
<li>Method names can end in equals such as <code>name=(newName)</code>, parentheses are optional, and spaces seem to be allowed in method names that include &#8216;=&#8217;, so attribute-setting methods can look syntactically identical to variable assignment operators. Example: <code>adam.name=('Adam')</code> is equivalent to <code>adam.name = ('Adam')</code> and is equivalent to <code>adam.name = 'Adam'</code>. Sweet syntactical sugar.</li>
<li>All instance variables are private. Always. The snazzy setter/getter syntax can spoof the idea of public attributes while still retaining actual methods to do the work. (I never got the point of public attributes other than as a way to avoid other languages&#8217; painful getter/setter syntactical requirements.)</li>
<li>Classes are never closed &#8212; can always add a method</li>
<li>Single-inheritance prevents ambiguity in the class-hierarchy, but there is this concept of &#8216;Mix-ins&#8217; where the un-closed nature of classes (I think) allows for a class to obtain method implementations from another class without inheriting from it. It sounds interesting, but I haven&#8217;t played with it yet</li>
</ul>
<p>The Ruby language may have some blemishes (and apparently a slow interpreter), but it seems like a pretty nice language in general and pretty devoid of major syntactical or conceptual warts.</p>
<p><strong>&#8230;Frameworks are hard</strong><br />
While I feel like I can [mostly] get my head around Ruby in a few days, Rails is another matter. Rails follows a few architectural concepts very strictly: <a href="http://en.wikibooks.org/wiki/Ruby_on_Rails/Getting_Started/Convention_Over_Configuration">convention over configuration</a>, <a href="http://wiki.rubyonrails.org/rails/pages/DRY">DRY</a>, <a href="http://wiki.rubyonrails.org/rails/pages/MVC">MVC</a>, etc. One of the problems (at least with the <a href="http://guides.rubyonrails.org/">tutorials and documentation</a> on the Rails website) is that few of the convention have descriptions on how they should be applied and the documentation is scattered and can be hard to follow. A lot of magic happens behind the scenes when things are named a certain way and it can be hard to sort out what&#8217;s up when something goes wrong.</p>
<p>One problem I ran into that took me forever to debug was that by naming one of my classes <code>Connection</code> and using it in a <code>has_many</code> relationship I collided with something internal to ActiveRecord which caused an indecipherable error when trying to save my object. <code>Connection</code> is not one of the <a href="http://wiki.rubyonrails.org/rails/pages/ReservedWords">reserved words</a> listed for Rails.</p>
<p>It may just be that I need to find a good book for Rails, but the official online documentation seems to be rather sparse, disorganized, and/or scattered. I don&#8217;t mean to complain too much and I believe that Rails will become much easier to use after I have a bit more time in the saddle, but it is a complex system that is not easy to learn a bit at a time.</p>
<p>I don&#8217;t want to dwell on on comparisons, but I must note that I have been very spoiled by PHP&#8217;s excellent official documentation at <a href="http://us.php.net/manual/en/function.array-map.php">PHP.net</a> and for the <a href="http://framework.zend.com/manual/en/zend.db.statement.html">Zend Framework</a>. PHP has more warts than, well, something with a lot of warts, (it has many, many warts), and doesn&#8217;t begin to compare to Ruby in syntactical elegance, but good documentation is also a valuable thing.</p>
<p>With all this said, I now have only 5 evenings in Ruby on Rails and I plan to give it at least twice that more. I hope by the end of this first project I&#8217;ll be comfortable enough with it to use it on other small to medium-sized applications with relative speed and ease.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2009/02/03/ruby-and-rails-thoughts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Tip of the Day: Stage Hunks</title>
		<link>http://www.adamfranco.com/2009/01/13/git-tip-of-the-day-stage-hunks/</link>
		<comments>http://www.adamfranco.com/2009/01/13/git-tip-of-the-day-stage-hunks/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 16:19:43 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[Musings]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=91</guid>
		<description><![CDATA[One of the great things about the Git version-control system is the ability to incrementally commit your changes on a private branch to keep a step-by-step record of your thought and writing process on a fix or a feature, and then merge the completed work onto your main [or public] branch after your feature or [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about the <a href="http://git-scm.com/">Git</a> version-control system is the ability to incrementally commit your changes on a <a href="http://amarok.kde.org/wiki/Development/Git#Branching">private branch</a> to keep a step-by-step record of your thought and writing process on a fix or a feature, and then merge the completed work onto your main [or public] branch after your feature or fix is all done and tested. By keeping an incremental log of your changes &#8212; rather than just committing one giant set of code with changes to 30 files &#8212; it becomes much easier to know why a certain line was changed in the future when bugs are discovered with it.</p>
<p>One thing that often happens to me though, is that I work for about a half hour to an hour trying to get a new piece of code working and in the process make several sets of changes to one file that are only loosely related.</p>
<p>Let&#8217;s say that I am fixing a bug in my &#8216;MediaLibrary&#8217; class and while doing so notice some some spelling mistakes in some comments that I fix. Now my one file has two changes my bug fix, and the spelling fix. Rather than committing both changes together with one comment describing both changes, I can highlight one of the changes in <a href="http://www.kernel.org/pub/software/scm/git/docs/git-gui.html">git-gui</a> and select the &#8220;Stage Hunk for Commit&#8221; option.</p>
<p><a href='http://tmp.adamfranco.com/files/2009/01/stagehunk1.jpg'><img src="http://tmp.adamfranco.com/files/2009/01/stagehunk1.jpg" alt="Screen-shot of Staging a Hunk of code" title="Git-GUI: Stage Hunk" width="500" height="361" class="alignnone size-full wp-image-93" /></a></p>
<p>With that one hunk staged I can now commit with a message applicable to that change. Other changes can then be staged and committed with their own messages resulting in a very understandable history of changes.</p>
<p>&#8220;Stage Hunk for Commit&#8221; can also be used to commit important changes while not including debugging lines inserted in your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2009/01/13/git-tip-of-the-day-stage-hunks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Export Script</title>
		<link>http://www.adamfranco.com/2008/10/13/twitter-export-script/</link>
		<comments>http://www.adamfranco.com/2008/10/13/twitter-export-script/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 15:47:35 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=88</guid>
		<description><![CDATA[I have been using Twitter as a log of my daily doings and wished to export my time-line for reformatting into a calender format. Unfortunately TweetDumpr just retrieves the list of Tweets using a single fetch request which is limited by the Twitter API to a maximum of 200 Tweets. (Update: apparently TweetDumpr can get [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://twitter.com">Twitter</a> as a <a href="http://twitter.com/afranco_work">log of my daily doings</a> and wished to export my time-line for reformatting into a calender format. Unfortunately <a href="http://pantsland.com/2008/04/14/released-twitter-timeline-export-tweetdumpr/">TweetDumpr</a> just retrieves the list of Tweets using a single fetch request which is limited by the Twitter API to a maximum of 200 Tweets. (Update: apparently TweetDumpr <em>can</em> get more than 200 Tweets. It just didn&#8217;t say so in its description.)</p>
<p>I wanted to export all 600+ of my tweets, so I wrote the following little php script to accomplish this. I have not yet tested it with many concurrent users or added a form to select which user to update. Until I do so, I won&#8217;t be providing it as an end-user service. You are free to put it on your own machine and use it though.</p>
<p><strong>TwitterExport.php</strong></p>
<pre>&lt;?php
/**
 * This script will allow the export of complete user time-lines from the twitter
 * service. It joins together all pages of status updates into one large XML block
 * that can then be reformatted/processed with other tools.
 *
 * @since 10/13/08
 *
 * @copyright Copyright &copy; 2008, Adam Franco
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
 */

$user = 'afranco_work';	// Replace this with your user name.

header('Content-type: text/plain');

$allDoc = new DOMDocument;
$root = $allDoc-&gt;appendChild($allDoc-&gt;createElement('statuses'));
$root-&gt;setAttribute('type', 'array');

$page = 1;
do {
	$numStatus = 0;

	$pageDoc = new DOMDocument;
	$res = @$pageDoc-&gt;load('http://twitter.com/statuses/user_timeline/'.$user.'.xml?page='.$page);
	if (!$res) {
		print "\n\n**** Error loading page $page ****";
		exit;
	}
	foreach ($pageDoc-&gt;getElementsByTagName('status') as $status) {
		$root-&gt;appendChild($allDoc-&gt;createTextNode("\n"));
		$root-&gt;appendChild($allDoc-&gt;importNode($status, true));
		$numStatus++;
	}

	print "\nLoaded page $page with $numStatus status updates.";
	flush();

	$page ++;
	sleep(1);

} while ($numStatus);

print "\nDone loading timeline.";
print "\n\n\n";

$root-&gt;appendChild($allDoc-&gt;createTextNode("\n"));
print $allDoc-&gt;saveXml();
</pre>
<p><br/><br />
<strong>Usage (assuming <a href="http://www.php.net">PHP</a> is installed)</strong></p>
<ol>
<li>Save the code above on your machine as twitter_export.php</li>
<li>Edit the code to change the <code>$user</code> variable to be your own Twitter username</li>
<li>From the command line run <code>php twitter_export.php</code></li>
<li>Copy/paste the XML output into a file for safe keeping and further processing</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2008/10/13/twitter-export-script/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Getting Rid of the Translucent Menu Bar in Leopard</title>
		<link>http://www.adamfranco.com/2008/02/20/getting-rid-of-the-translucent-menu-bar-in-leopard/</link>
		<comments>http://www.adamfranco.com/2008/02/20/getting-rid-of-the-translucent-menu-bar-in-leopard/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 14:47:53 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Computers and Technology]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/archives/70</guid>
		<description><![CDATA[With the latest OS X Leopard update (10.5.2) Apple finally added an option to turn off menu bar translucency. I much prefer an opaque menu bar as I find it much more legible. There is only one problem with this fix: Apple, in their infinite wisdom, decided to hide this option on computers that &#8220;don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>With the latest OS X Leopard update (10.5.2) Apple finally added an option to turn off menu bar translucency. I much prefer an opaque menu bar as I find it much more legible. There is only one problem with this fix: Apple, in their infinite wisdom, decided to hide this option on computers that &#8220;don&#8217;t support transparency&#8221; due to having lower-end graphics hardware. After upgrading to 10.5.2 my MacBookPro laptop has the option to turn of menu bar transparency, but my newer and more powerful MacPro Desktop does not. After much searching and forum-reading I found that most of the people with this problem (menu bar is translucent, but the option to make it opaque is missing) had MacPro desktops with multiple monitors and video cards.</p>
<p>The problem it turns out, is that while one of my video cards (that drives my two primary monitors ) is a high-end ATI Radeon X1900XT that supports transparent menu bars, the second  (that drives my two outer monitors used mostly for notes and email) is a cheaper NVIDIA GeForce 7300 GT. The presence of the lower-end card in the system was causing the &#8220;Translucent Menu Bar&#8221; option to be hidden, even though it was supported by my other card.</p>
<p>Steps to fix:</p>
<ol>
<li>Turn off computer</li>
<li>Remove low-end video card</li>
<li>Start computer</li>
<li>Go to System Preferences &#8211;&gt; Desktop &amp; Screen Saver and un-check the &#8220;Translucent Menu Bar&#8221; option</li>
<li>Turn off computer</li>
<li>Replace low-end video card</li>
<li>Start computer</li>
</ol>
<p>It is a pain in the butt, but it works to get the damn translucency turned off.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2008/02/20/getting-rid-of-the-translucent-menu-bar-in-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>River Levels Widget v1.2.1</title>
		<link>http://www.adamfranco.com/2008/02/10/river-levels-widget-v121/</link>
		<comments>http://www.adamfranco.com/2008/02/10/river-levels-widget-v121/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 23:21:29 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Computers and Technology]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.adamfranco.com/?p=69</guid>
		<description><![CDATA[This version is a re-release of version 1.2 which had a corrupted archive missing some necessary files. The RiverLevels widget provides an easy way to monitor the amount of water flowing in your favorite streams and rivers right from your Dashboard. The RiverLevels widget is of particular interest to whitewater kayakers and canoeists. Once any [...]]]></description>
			<content:encoded><![CDATA[<p><em>This version is a re-release of <a href="http://www.adamfranco.com/?p=68">version 1.2</a> which had a corrupted archive missing some necessary files.</em></p>
<p><a href="http://downloads.sourceforge.net/waterwidgets/RiverLevels.wdgt-1.2.zip"><img src="http://tmp.adamfranco.com/files/2008/02/screen-shot.jpg" title="RiverLevels 1.0 Screen Shot" alt="RiverLevels 1.0 Screen Shot" style="width: 100%; max-width: 817px" align="middle" border="0" /></a></p>
<p>The <span class="title">RiverLevels</span> widget provides an easy way to monitor the amount of water flowing in your favorite streams and rivers right from your Dashboard. The <span class="title">RiverLevels</span> widget is of particular interest to whitewater kayakers and canoeists.</p>
<p>Once any United States Geological Survey (USGS) stream-gauge station is selected, it is automatically refreshed to always provide you with the latest graph of the water-level. As of version 1.2 you can choose between two graph styles: discharge in cubic feet per second (CFS) and water-height in feet.</p>
<p>This widget is Free software, licensed under the GNU General Public License (GPL) version 3 or later.</p>
<ul>
<li><strong><a href="http://downloads.sourceforge.net/waterwidgets/RiverLevels.wdgt-1.2.1.zip">Download</a></strong></li>
</ul>
<ul>
<li><a href="http://waterwidgets.sourceforge.net/">More Info</a></li>
<li><a href="http://www.apple.com/downloads/dashboard/information/riverlevels.html">Apple&#8217;s Download page for RiverLevels.wdgt</a></li>
<li><a href="http://sourceforge.net/tracker/?group_id=149897&amp;atid=776122">Bug Tracker</a></li>
</ul>
<p><strong> Requirements:</strong></p>
<ul>
<li>OS X &#8211; 10.4 &#8220;Tiger&#8221; or later</li>
</ul>
<p><strong>Change Log:</strong></p>
<p>1.2.1 (2008-02-10)</p>
<ul>
<li>New zip archive includes the &#8216;library&#8217; directory missing in the 1.2 release.</li>
</ul>
<p>1.2 (2008-02-06)</p>
<ul>
<li>Fixed Leopard (10.5) compatability bug.</li>
<li> Added the ability to choose Gauge Height (ft) in addition to discharge (CFS).</li>
</ul>
<p>1.1 (2007-01-08)</p>
<ul>
<li>Fixed graphs extending off bottom of widget</li>
<li>Fixed invisibility of front refresh icon</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.adamfranco.com/2008/02/10/river-levels-widget-v121/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
