<?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>randys.org &#187; Code Chunks</title>
	<atom:link href="http://www.randys.org/category/code-chunks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randys.org</link>
	<description>wasting your precious bandwidth since 1998</description>
	<lastBuildDate>Wed, 16 Nov 2011 23:40:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Homebrew &#8211; Building a working APC 3.1.9</title>
		<link>http://www.randys.org/2011/08/26/homebrew-building-a-working-apc-3-1-9/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=homebrew-building-a-working-apc-3-1-9</link>
		<comments>http://www.randys.org/2011/08/26/homebrew-building-a-working-apc-3-1-9/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 04:06:21 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[How-To]]></category>

		<guid isPermaLink="false">http://www.randys.org/?p=563</guid>
		<description><![CDATA[I&#8217;ve recently started using Homebrew as a means to get a working PHP/APC on my local MACs. It was fairly straight forward, however, after installing APC, PHP stopped working. Turns out there was a tiny bug in apc_lock.h that needed &#8230; <a href="http://www.randys.org/2011/08/26/homebrew-building-a-working-apc-3-1-9/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently started using <a href="https://github.com/mxcl/homebrew">Homebrew</a> as a means to get a working <a href="http://www.php.net">PHP</a>/<a href="http://pecl.php.net/package/APC">APC</a> on my local MACs. It was fairly straight forward, however, after installing APC, PHP stopped working. Turns out there was a <a href="http://pecl.php.net/bugs/bug.php?id=22688">tiny bug in <code>apc_lock.h</code></a> that needed to be fixed. Literally, one extra character in the header caused the whole thing to go kaput.</p>
<p>Turns out it&#8217;s a pretty simple fix. Just have to <a href="http://news.php.net/php.pecl.cvs/15669">remove ONE ampersand</a> (&amp;) in the file and everything is kosher. But, since I <a href="https://github.com/mxcl/homebrew/commit/d6cd00ab3a284120711fb6d3775a165803411e3c#commitcomment-540394">couldn&#8217;t figure how to incorporate a patch</a> in Homebrew, I <a href="https://github.com/sesser/homebrew/blob/fbbf0652902fa0c8a330d1da30bde8e57656d656/Library/Formula/apc.rb">wrote some hacky ruby</a> in the <code>apc.rb</code> file to fix the situation.</p>
<p>Hacky code to follow:</p>
<pre class="brush: ruby; gutter: true">   def install
        Dir.chdir "APC-#{version}" do
            text = File.read("apc_lock.h")
            text.gsub!(/apc_fcntl_unlock\(&amp;a TSRMLS_CC\)/, "apc_fcntl_unlock(a TSRMLS_CC)")
            File.open("apc_lock.h", 'w') { |f| f.write(text) }
            system "phpize"
            system "./configure", "--prefix=#{prefix}"
            system "make"

            prefix.install %w(modules/apc.so apc.php)
        end
    end</pre>
<p>Enjoy!</p>
<div style=" text-align: center;  margin: 8px; ">
				<script type="text/javascript">
				google_ad_client = "pub-6476605957445525";
				google_ad_width = 468;
				google_ad_height = 60;
				google_ad_format = "468x60_as";
				google_ad_type = "text_image";
				google_ad_channel = "8409641020";
				google_color_border = "#C7C7C7";
				google_color_bg = "#FFFFFF";
				google_color_link = "#777777";
				google_color_text = "#777777";
				google_color_url = "#3333CC";
				google_ui_features = "rc:0";
				</script>
				<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
			</div><!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2011/08/26/homebrew-building-a-working-apc-3-1-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototype: It&#8217;s Not Just a JavaScript Library</title>
		<link>http://www.randys.org/2009/05/14/prototype-its-not-just-a-javascript-library/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prototype-its-not-just-a-javascript-library</link>
		<comments>http://www.randys.org/2009/05/14/prototype-its-not-just-a-javascript-library/#comments</comments>
		<pubDate>Fri, 15 May 2009 05:08:25 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.randys.org/2009/05/14/prototype-its-not-just-a-javascript-library/</guid>
		<description><![CDATA[Used to be that writing front-end code (HTML, CSS, JavaScript) wasn&#8217;t terribly complex. The syntax of HTML and CSS isn&#8217;t all that difficult to get the hang of and JavaScript (back in the day) was just a tool to validate &#8230; <a href="http://www.randys.org/2009/05/14/prototype-its-not-just-a-javascript-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Used to be that writing front-end code (HTML, CSS, JavaScript) wasn&#8217;t terribly complex. The syntax of HTML and CSS isn&#8217;t all that difficult to get the hang of and JavaScript (back in the day) was just a tool to validate form fields and play funny tricks on poor unsuspecting visitors. These days, JavaScript has become <em>the</em> language for front-end development and it&#8217;s not just for printing the &#8216;lastModifiedDate&#8217; of a document.</p>
<p><script src="http://static.randys.org/js/prototype-date.js" type="text/javascript"></script></p>
<p>Anyone who has kept up with the advancements of JavaScript knows the <a href="http://www.prototypejs.org/">Prototype</a> library. For those who don&#8217;t know, it&#8217;s a JavaScript library that wraps a whole bunch of functionality into easy to use (and remember) &#8220;shortcuts&#8221; for doing things like getting elements on a page, manipulating said elements, and dealing with data. It&#8217;s all written in <a href="http://www.json.org/">JSON</a> notation and allows you do things like:</p>
<pre><code>$('element-id').addClassName('active').show();
</code></pre>
<p>Instead of</p>
<pre><code>var element = document.getElementById('element-id');
    element.className = 'active';
    element.style.display = 'block';
</code></pre>
<p>Anyway, things like Prototype, <a href="http://jquery.com/">jQuery</a>, <a href="http://www.dojotoolkit.org/">Dojo</a>, and <a href="http://developer.yahoo.com/yui/">YUI</a> all provide some convenience to writing custom JavaScript applications. I haven&#8217;t dug super deep into any of the frameworks&#8217; source (mostly because the code has been somewhat obfuscated and &#8220;compressed&#8221; to save space), but I imagine that they all have one thing in common; they make use of the <a href="http://phrogz.net/JS/Classes/ExtendingJavaScriptObjectsAndClasses.html#prototype">prototype</a> property to extend both existing and custom built objects/classes in JavaScript.</p>
<h3>The prototype Property</h3>
<p>Even if you don&#8217;t make heavy use of one of the afforementioned framework/toolkits, using the <em>prototype</em> property to extend existing JavaScript objects and/or classes can be quite useful. Say you want an easy way to print out a date. Rather than createing a separate function, just extend the <code>Date</code> object itself.</p>
<pre><code>Date.prototype.months = new Array(
    {name: "January", abbrev: "Jan", number: "01"},
    {name: "February",    abbrev: "Feb", number: "02"},
    {name: "March",       abbrev: "Mar", number: "03"},
    {name: "April",       abbrev: "Apr", number: "04"},
    {name: "May",     abbrev: "May", number: "05"},
    {name: "June",        abbrev: "Jun", number: "06"},
    {name: "July",        abbrev: "Jul", number: "07"},
    {name: "August",  abbrev: "Aug", number: "08"},
    {name: "September", abbrev: "Sep", number: "09"},
    {name: "October", abbrev: "Oct", number: "10"},
    {name: "November",    abbrev: "Nov", number: "11"},
    {name: "December",    abbrev: "Dec", number: "12"}
);
Date.prototype.dow = new Array(
    {name: 'Sunday',  abbrev: 'Sun', number: "01"},
    {name: 'Monday',  abbrev: 'Mon', number: "02"},
    {name: 'Tuesday', abbrev: 'Tue', number: "03"},
    {name: 'Wednesday',   abbrev: 'Wed', number: "04"},
    {name: 'Thursday',    abbrev: 'Thu', number: "05"},
    {name: 'Friday',  abbrev: 'Fri', number: "06"},
    {name: 'Saturday',    abbrev: 'Sat', number: "07"}
);
Date.prototype.getShortDate = function() {
    return this.months[this.getMonth()].abbrev + ' ' + this.getDate() + ' ' + this.getFullYear();
};
Date.prototype.getLongDate = function() {
    return this.dow[this.getDay()].name + ', ' + this.months[this.getMonth()].name + ' ' + this.getDate() + ', ' + this.getFullYear();
};
Date.prototype.getValueDate = function() {
    var d = (this.getDate() &lt; 10) ? '0'+this.getDate():this.getDate();
    return this.getFullYear() + '/' + this.months[this.getMonth()].number + '/' + d;
};

var now = new Date();
document.write(now.getLongDate());
</code></pre>
<p>And you get something like this <script type="text/javascript">var now = new Date();document.write(now.getLongDate());</script>. Handy.</p>
<p>Now, there&#8217;s a couple of issues with the above script. One, the names aren&#8217;t localized and two, there&#8217;s probalby a more efficient way to formatting a date (much like the example on <a href="http://phrogz.net/JS/Classes/ExtendingJavaScriptObjectsAndClasses.html#example2">this page</a>). But, it works in all the browsers I tested (Chrome, Firefox, IE7, Safari [Mac]).</p>
<p>You can prototype most of the default objects in JavaScript. Say you have an application the has to validate a bunch of text fields. Prototype the <code>String</code> objects to add built in parsing methods for various fields.</p>
<pre><code>String.prototype.isValidEmail = function() { ... }
String.prototype.isValidPhone = function() { ... }
</code></pre>
<p>You get the idea.</p>
<p>The <code>prototype</code> property is a handy little tool. There maybe some limitations between browsers, but overall, it should help simplify your code and prevent repetitive and reduntant methods.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2009/05/14/prototype-its-not-just-a-javascript-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How-To: Automated Backups to Amazon&#039;s S3 with Duplicity</title>
		<link>http://www.randys.org/2007/11/16/how-to-automated-backups-to-amazon-s-s3-with-duplicity/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-automated-backups-to-amazon-s-s3-with-duplicity</link>
		<comments>http://www.randys.org/2007/11/16/how-to-automated-backups-to-amazon-s-s3-with-duplicity/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 00:28:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Duplicity]]></category>
		<category><![CDATA[GPG]]></category>
		<category><![CDATA[Slicehost]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/11/16/how-to-automated-backups-to-amazon-s-s3-with-duplicity</guid>
		<description><![CDATA[I&#8217;ve been using Amazon&#8217;s S3 service for a couple months now. It was working OK using s3sync and a cron job, but it seemed like it wasn&#8217;t actually making incremental backups and I wasn&#8217;t 100% sure that it was backing &#8230; <a href="http://www.randys.org/2007/11/16/how-to-automated-backups-to-amazon-s-s3-with-duplicity/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Amazon&#8217;s <a href="http://www.amazon.com/S3-AWS-home-page-Money/b/ref=sc_fe_l_2?ie=UTF8&amp;node=16427261&amp;no=3435361&amp;me=A36L942TSJ2AJA">S3</a> service for a couple months now. It was working OK using <a href="http://s3sync.net/wiki">s3sync</a> and a cron job, but it seemed like it wasn&#8217;t actually making incremental backups and I wasn&#8217;t 100% sure that it was backing up everything (i.e. it appeared to be crapping out once in a while). I searched around for various S3 backup solutions and found a handy utility called <a href="http://duplicity.nongnu.org/">duplicity</a>. Even more handy that it is available for most distributions (Archlinux, <a href="http://www.ubuntu.com/">the</a> <a href="http://www.debian.org/">debs</a>, and Fedora anyway).</p>
<p>From the duplicity home page:</p>
<blockquote>
<p>Duplicity backs directories by producing encrypted tar-format volumes and uploading them to a remote or local file server. Because duplicity uses <a href="http://sourceforge.net/projects/librsync">librsync</a>, the incremental archives are space efficient and only record the parts of files that have changed since the last backup. Because duplicity uses <a href="http://www.gnupg.org/">GnuPG</a> to encrypt and/or sign these archives, they will be safe from spying and/or modification by the server.</p>
</blockquote>
<h3>What you&#8217;ll need</h3>
<p>You&#8217;ll need to make sure you have a few things installed before you install duplicity. Namely librsync and GnuPG. Luckily, if the duplicity package is available for your distribution, you probably needn&#8217;t worry.</p>
<p>Here&#8217;s a rundown of the steps involved:</p>
<ol>
<li>Generate a new GnuPG key</li>
<li>Create a simple shell script wrapper</li>
<li>Create a cron job</li>
</ol>
<h3>Generating a new Key</h3>
<p>Start by generating a new gpg key for duplicity. Or if you have an existing one, you can use that. </p>
<p><strong>N.B.</strong> <em>I set this up on a <a href="https://manage.slicehost.com/customers/new?referrer=396224371">Slice</a> running Arch64 and had problems generating a new key (<code>gpg --gen-key</code>). Apparently, it could not generate enough entropy. Not a problem though: Just generate the keys else where and import them later if this happens to you.</em></p>
<pre><code>#~ gpg --gen-key
gpg (GnuPG) 1.4.7; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection?
</code></pre>
<p>Default (DSA and Elgamal) is fine here.</p>
<pre><code>DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
</code></pre>
<p>The default (2048) is more than enough for this. Change it to whatever you want.</p>
<pre><code>Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0)
</code></pre>
<p>Unless you want the key to expire (I don&#8217;t see why one would want that), the default is what we want.</p>
<pre><code>Key does not expire at all
Is this correct? (y/N)
</code></pre>
<p>Um, yes, this is correct.</p>
<pre><code>You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) &lt;heinrichh@duesseldorf.de&gt;"

Real name: DuplicityBackup
Email address: duplicity@mydomain.com
Comment: Key for Duplicity
You selected this USER-ID:
    "DuplicityBackup (Key for Duplicity) &lt;duplicity@mydomain.com&gt;"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
</code></pre>
<p>Enter whatever information you want here and type &#8216;O&#8217; for &#8216;Okay&#8217;</p>
<pre><code>You need a Passphrase to protect your secret key.

Enter Passphrase:
</code></pre>
<p>Enter something. Anything. The more complex the better. This is your private data. Remember that it&#8217;s being transfered over http to a server you don&#8217;t own. I don&#8217;t care if it is Amazon. Remember what you type because you&#8217;ll need it later while creating the wrapper script.</p>
<pre><code>gpg: key **9929DAB1** marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   1024D/9929DAB1 2007-11-15
      Key fingerprint = 3378 8E93 4349 0E7F 44F3  7C81 2460 5A11 9929 DAB1
uid                  DuplicityBackup (Key for Duplicity) &lt;duplicity@mydomain.com&gt;
sub   2048g/5385A6BB 2007-11-15
</code></pre>
<p>And you&#8217;re done. Make note of the key (in this case, 9929DAB1) as we&#8217;ll need that later too.</p>
<h4>But I already have a key I want to use</h4>
<p>OK, fine, but chances are, if you have a key already, you know how to get it. However, if you don&#8217;t know how to get your key, <code>gpg --list-keys</code>. You want the key in the &#8216;pub&#8217; line&#8230; after the forward slash &#8216;/&#8217;</p>
<h3>The Wrapper</h3>
<p>This can be written in any language really. I chose shell because it&#8217;s easy and basic. You could run the <code>duplicity</code> now on the command line, but writing a wrapper is much more convenient and makes adding a cron job later a lot easier. Here&#8217;s what you&#8217;ll need:</p>
<ul>
<li>Your Amazon S3 Access Key ID and Secret Access Key. If you don&#8217;t have one, you&#8217;ll have to <a href="http://www.amazonaws.com/">sign up for one</a>.</li>
<li>Your GPG key</li>
<li>Your GPG key&#8217;s passphrase</li>
<li>A list of directories you want to back up</li>
</ul>
<p>Here&#8217;s a basic script that works for me:</p>
<p>	#!/bin/bash<br />
	# Export some ENV variables so you don&#8217;t have to type anything<br />
	export AWS_ACCESS_KEY_ID=&lt;your-access-key-id&gt;<br />
	export AWS_SECRET_ACCESS_KEY=&lt;your-secret-access-key&gt;<br />
	export PASSPHRASE=&lt;your-gpg-passphrase&gt;</p>
<p>	GPG_KEY=&lt;your-gpg-key&gt;</p>
<p>	# The source of your backup<br />
	SOURCE=/</p>
<p>	# The destination<br />
	# Note that the bucket need not exist<br />
	# but does need to be unique amongst all<br />
	# Amazon S3 users. So, choose wisely.<br />
	DEST=s3+http://&lt;your-bucket-name&gt;</p>
<p>	duplicity<br />
	    &#8211;encrypt-key=${GPG_KEY} \<br />
	    &#8211;sign-key=${GPG_KEY} \<br />
	    &#8211;include=/boot \<br />
	    &#8211;include=/etc \<br />
	    &#8211;include=/home \<br />
	    &#8211;include=/root \<br />
	    &#8211;include=/var/lib/mysql \<br />
	    &#8211;exclude=/** \<br />
	    ${SOURCE} ${DEST}</p>
<p>	# Reset the ENV variables. Don&#8217;t need them sitting around<br />
	export AWS_ACCESS_KEY_ID=<br />
	export AWS_SECRET_ACCESS_KEY=<br />
	export PASSPHRASE=</p>
<p>And, that&#8217;s pretty much it. Save the file as something creative, like, <code>backup</code> and make it executable (<code>chmod 700 backup</code>). If you want to test it first (and you have the disk space), change the destination to some <code>/tmp</code> directory or external HDD. Once you&#8217;ve got it working the way you want, set it up as a cron job. Daily, weekly, monthly&#8230; doesn&#8217;t matter.</p>
<p>Duplicity is a nice backup solution for any situation, not just Amazon&#8217;s S3. It can handle HTTP, SCP and local backups as well. I highly recommend reading the <a href="http://duplicity.nongnu.org/duplicity.1.html">duplicity man page</a> and checking out the various command line arguments and availble options.</p>
<p>A couple of <em>Thanks</em> goes out to <a href="http://www.brainonfire.net/2007/08/11/remote-encrypted-backup-duplicity-amazon-s3/">Tim McCormack&#8217;s</a> and <a href="http://www.sysadminschronicles.com/archives/2007/10/21/backing_up_with_amazon_s3/">Ben and Ron&#8217;s</a> articles which got me started.</p>
<hr/>
<p>Tim points out that, adding your GPG PASSPHRASE to the shell script might not be the most secure method, especially in a shared environment. I agree, however, it kind of defeats the purpose of automated backups if you have to actually enter your passphrase (twice) on the command line when calling the wrapper script. One way I managed to go around this is to create a simple C++ application that prints the passphrase.</p>
<p>Here&#8217;s the C++ code:</p>
<pre><code>#include &lt;stdio.h&gt;
int main()
{
    printf("your-gpg-passphrase");
    return 0;
}
</code></pre>
<p>Compile</p>
<pre><code>#~ gcc gpg-passphrase.c -o gpg-passphrase
</code></pre>
<p>Make it executable by your user and set the sticky bit so no one else can execute it</p>
<pre><code>#~ chmod 700 gpg-passphrase
#~ chmod +s gpg-passphrase
</code></pre>
<p>Modify the wrapper script to use the binary for the passphrase</p>
<pre><code>export PASSPHRASE=$(gpg-passphrase)
</code></pre>
<p>You might go as far as to do the same thing for your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as well. There are probably other ways around this, but this was a quick a dirty way to not have readable strings in shell scripts. I figure, if someone has rooted my server, I&#8217;ve got bigger problems to worry about than my data sitting on Amazon&#8217;s S3.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/11/16/how-to-automated-backups-to-amazon-s-s3-with-duplicity/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>How-To: Install Archlinux on Slicehost</title>
		<link>http://www.randys.org/2007/08/17/how-to-install-archlinux-on-slicehost/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-install-archlinux-on-slicehost</link>
		<comments>http://www.randys.org/2007/08/17/how-to-install-archlinux-on-slicehost/#comments</comments>
		<pubDate>Fri, 17 Aug 2007 08:43:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Archlinux]]></category>
		<category><![CDATA[Slicehost]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/08/17/how-to-install-archlinux-on-slicehost</guid>
		<description><![CDATA[I recently acquired a 256 Slice from Slicehost. While their distribution selection is good, I was hoping for something, well, different. My old VPS is rocking Ubuntu (quite well) but I just want something else. Slicehost&#8217;s other distributions weren&#8217;t going &#8230; <a href="http://www.randys.org/2007/08/17/how-to-install-archlinux-on-slicehost/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently acquired a 256 Slice from Slicehost. While their distribution selection is good, I was hoping for something, well, different. My old VPS is rocking Ubuntu (quite well) but I just want something else. Slicehost&#8217;s other distributions weren&#8217;t going to cut it.</p>
<ol>
<li>Ubuntu Dapper &#8211; Already running that.. that&#8217;s how I got here.</li>
<li>CentOS 4.3 &#8211; Um, no. Never liked RedHat. Hate RPMs. Package management is a nightmare.</li>
<li>Gentoo 2006.1 &#8211; I&#8217;ve used Gentoo in the past (a lot) and enjoyed it. I even tried it on my old VPS. I just don&#8217;t have the patience to wait for shit to compile.</li>
<li>Debian Etch &#8211; Debian is a true soldier. Secure and stable. However, not up-to-date enough for my tastes (that&#8217;s why I went with Ubuntu).</li>
<li>Fedora 6 &#8211; See #2.</li>
</ol>
<h3>Enter Archlinux.</h3>
<p>This little how-to was taken from various places on the net, but the bulk of it is from Anders&#8217; Blargh post and a couple of comments in a previous post of mine. So, let&#8217;s dive in.</p>
<h3>Back It Up!</h3>
<p>If you have any valuable information on your slice, now would be the time to make a backup of the important stuff you want to keep.</p>
<h3>Bootstrapping</h3>
<p>First thing you want to do is bootstrap Arch64 to directory on your current distribution. If you happen to have a 64bit version running at home, you could do this locally and it should still work (in theory).</p>
<pre><code>export PACMAN_VERSION=3.0.5-2
export XEN_MODULES_VERSION=2.6.16.29
wget http://www.randys.org/assets/2007/8/17/archbootstrap-packages-20070817
wget ftp://ftp.archlinux.org/current/os/x86_64/pacman-${PACMAN_VERSION}.pkg.tar.gz
tar zxvf pacman-${PACMAN_VERSION}.pkg.tar.gz -C /
mkdir /arch
</code></pre>
<p>At this point, you might want to edit <code>/etc/pacman.conf</code> and <code>/etc/pacman.d/current</code> to your liking. Picking a close/fast mirror will help speed things along.</p>
<pre><code>pacman.static -Sy `cat archbootstrap-packages-20070817` -r /arch
</code></pre>
<p>Now you need to bind /dev, /sys and /proc to the bootstrap directory so you can chroot in.</p>
<pre><code>for s in dev sys proc; do mount /$s /arch/$s --bind; done
</code></pre>
<p>Copy some important files for the chroot.</p>
<pre><code>cp /etc/mtab /arch/etc/
cp /etc/fstab /arch/etc/
cp /etc/resolv.conf /arch/etc/
</code></pre>
<p>We also need to copy the all important xen kernel modules from the existing slice into our Arch64 bootstrap directory.</p>
<pre><code>cp -r /lib/modules/${XEN_MODULES_VERSION}-xen /arch/lib/modules/
</code></pre>
<p>Now we&#8217;re ready to chroot into your new Arch64 directory.</p>
<pre><code>chroot /arch /bin/bash
</code></pre>
<p>One of gotchas I had was when I went to SSH into my newly booted Arch64 Slice. It would connect and I could enter my password, but it would hang and never drop me to a command line prompt. Did a little searching and found that it was all because /dev/pts was not being mounted at boot time. Easy fix.</p>
<pre><code>echo "none  /dev/pts    devpts  gid=5,mode=620  0 0" &amp;gt;&amp;gt; /etc/fstab
</code></pre>
<p>Edit <code>/etc/locale.gen</code> and enable any locales you require. en_US.UTF-8 UTF-8 and en_US ISO-8859-1 are popular choices. Now generate the locales.</p>
<pre><code>locale-gen
</code></pre>
<p>Edit <code>/etc/pacman.conf</code> and <code>/etc/pacman.d/(current|extra|community)</code> in your chroot to your liking. If you don&#8217;t do it here, you can always do it when you get it running. But we&#8217;re about to install openssh, so now is as good a time as any.</p>
<pre><code>pacman -Sy openssh
</code></pre>
<p>Now you nee to add sshd to our DAEMONS array in <code>/etc/rc.conf</code> file</p>
<pre><code>vim /etc/rc.conf
...
DAEMONS=(syslog-ng network netfs crond sshd)
...
</code></pre>
<p>While you&#8217;re in <code>/ect/rc.conf</code>, go ahead and setup your network interfaces and gateway. You can get the current information from your running Slice (for Ubuntu cat <code>/etc/network/interfaces</code>)</p>
<pre><code>...
eth0="eth0 XXX.XXX.XXX.XXX netmask 255.255.255.0 broadcast XXX.XXX.XXX.XXX"
INTERFACES=(lo eth0)
gateway="default gw XXX.XXX.XXX.XXX"
ROUTES=(gateway)
...
</code></pre>
<p>Next, you&#8217;ll need to modfy <code>/etc/hosts.allow</code> so you can actually connect to our new Arch64 VPS via ssh.</p>
<pre><code>echo "sshd : ALL : allow" &amp;gt;&amp;gt; /etc/hosts.allow
</code></pre>
<p>If there&#8217;s any other tweaks you want to make, make them now. Otherwise, exit the chroot.</p>
<p>One thing I did before exiting the chroot to cut down on the bootstrap size is to clear pacman&#8217;s cache directory. It should probably save you 100MB+ and there&#8217;s no need to keep them at this point.</p>
<pre><code>pacman -Scc
exit
</code></pre>
<p>Unmount the dev, sys and proc filesystems you mounted earlier.</p>
<pre><code>umount /arch/dev
umount /arch/sys
umount /arch/proc
</code></pre>
<p>Now we&#8217;ll archive the files.</p>
<pre><code>cd /arch &amp;amp;&amp;amp; tar cjvf /archbootstrap-$(date +%Y%m%d).tar.bz2 *
</code></pre>
<p>That&#8217;s it. You&#8217;re all set. If you want to keep a copy of this so you don&#8217;t have to do all this again, do it now.</p>
<pre><code>scp /archbootstrap-$(date +%Y%m%d).tar.bz2 @:
</code></pre>
<h3>Dealing with Slicehost</h3>
<p>At this point you should have a working Arch64 install ready to be installed. Now you need to login to the Slicehost manager and put your slice into Rescue Mode. Login to your slice via SSH. Once logged in you&#8217;ll need to mount your slice&#8217;s partition and copy the archive to the rescue disk.</p>
<pre><code>mkdir /mnt/oldslice
mount /dev/sda1 /mnt/oldslice
cp /mnt/oldslice/archbootstrap-* /root
umount /mnt/oldslice
</code></pre>
<p>Next, format your old slice partition and re-mount it so you can install Arch64.</p>
<pre><code>mke2fs -j /dev/sda1
mount /dev/sda1 /mnt/oldslice
tar xjvfp /root/archbootstrap-*.tar.bz2 -C /mnt/oldslice/
</code></pre>
<p>And that&#8217;s about it. You should now have a working Arch64 installation on your new Slice! Probably a good idea to double check all your settings before rebooting your slice, but, then you do have access to the rescue console.</p>
<p>Enjoy! And thanks to Anders for pointing me in the right direction.</p>
<p>If you find any errors or have any additions, please let me know and I&#8217;ll update this post.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/08/17/how-to-install-archlinux-on-slicehost/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mephisto: How-to add monthly archives to the side-bar</title>
		<link>http://www.randys.org/2007/05/23/mephisto-how-to-add-monthly-archives-to-the-side-bar/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mephisto-how-to-add-monthly-archives-to-the-side-bar</link>
		<comments>http://www.randys.org/2007/05/23/mephisto-how-to-add-monthly-archives-to-the-side-bar/#comments</comments>
		<pubDate>Wed, 23 May 2007 22:53:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[liquid]]></category>
		<category><![CDATA[mephisto]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/05/23/mephisto-how-to-add-monthly-archives-to-the-side-bar</guid>
		<description><![CDATA[One of the odd things I&#8217;m finding with Mephisto is that none of the templates I looked at had monthly archives in the sidebar. That&#8217;s generally not that strange, but Mephisto doesn&#8217;t really paginate (out of the box, anyway) sections &#8230; <a href="http://www.randys.org/2007/05/23/mephisto-how-to-add-monthly-archives-to-the-side-bar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the odd things I&#8217;m finding with Mephisto is that none of the templates I looked at had monthly archives in the sidebar. That&#8217;s generally not that strange, but Mephisto doesn&#8217;t really paginate (out of the box, anyway) sections (categories), so the lack of any way for a user (that would be you) to navigate to older posts is beyond me. So the search for some Liquid code to display monthly archives began.</p>
<p>Mephisto&#8217;s documentation is seriously lacking, but what can you expect from a small development team with no funding behind the app. Most of the links I followed were to the Mephisto Google Group. I took this snippet from <a href="http://groups.google.com/group/MephistoBlog/browse_thread/thread/dda3a8efd2f31607/782512794b3c4ec7?lnk=gst&amp;q=archives&amp;rnum=4#782512794b3c4ec7">one particular thread</a>:</p>
<pre><code> &lt;ul&gt;
 {% for month in section.months %}
     {{ section | monthly_articles: month | assign_to: 'monthly_articles' }}
     &lt;li&gt;
     {% if monthly_articles %}
         {{ section | link_to_month: month }} ({{ monthly_articles | size }})
     {% else %}
         {{ month | format_date: 'my' }}
     {% endif %}
     &lt;/li&gt;
 {% endfor %}
 &lt;/ul&gt;
</code></pre>
<p>But this would still spit out months with no posts. We can&#8217;t have that! So, I turned it into this:</p>
<pre><code>{% if section.months.size &gt; 0 %}
&lt;ul&gt;
    &lt;li class="head"&gt;Archives&lt;/li&gt;
    {% for month in section.months %}
    {{ section | monthly_articles: month | assign_to: 'monthly_articles' }}
        {% if monthly_articles.size &gt; 0 %}
            &lt;li&gt;&lt;span class="right"&gt;{{ monthly_articles | size }}&lt;/span&gt;
            {{ section | link_to_month: month }} &lt;/li&gt;
        {% endif %}
    {% endfor %}
&lt;/ul&gt;
{% endif %}
</code></pre>
<p>Much better! Now I have this:</p>
<div align="center"><img src="http://www.randys.org/assets/2007/5/23/article_archives_sidebar-20.gif" style="border:solid 1px #333"/></div>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/05/23/mephisto-how-to-add-monthly-archives-to-the-side-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scrobble This: last.fm recent tracks AJAX style</title>
		<link>http://www.randys.org/2007/01/24/scrobble-this-last-fm-recent-tracks-ajax-style/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=scrobble-this-last-fm-recent-tracks-ajax-style</link>
		<comments>http://www.randys.org/2007/01/24/scrobble-this-last-fm-recent-tracks-ajax-style/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 19:40:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/01/24/scrobble-this-last-fm-recent-tracks-ajax-style</guid>
		<description><![CDATA[So, I&#8217;ve been reading up a bit on prototype.js and its Ajax helpers. It&#8217;s an amazing tool and helped me write the bit of info at the top of the page. It&#8217;s pretty basic, but here&#8217;s the code that does &#8230; <a href="http://www.randys.org/2007/01/24/scrobble-this-last-fm-recent-tracks-ajax-style/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve been reading up a bit on <a href="http://prototypejs.org/">prototype.js</a> and its <a href="http://prototypejs.org/learn/introduction-to-ajax">Ajax</a> helpers. It&#8217;s an amazing tool and helped me write the bit of info at the top of the page. It&#8217;s pretty basic, but here&#8217;s the code that does most of the work:</p>
<pre><code>function lastfm()
{
    new Ajax.Request('/as/recenttracks.xml',
    {
        method: 'get',
        onLoading: function() {

        },
        onLoaded: function(transport) {
            if (transport.overrideMimeType) {
                transport.overrideMimeType('application/xml');
            }
        },
        onSuccess: function(transport) {
            var response = transport.responseXML.documentElement;
            updateLastfm(response);
        },
        onFailure: failedLastfm()
    });
}
</code></pre>
<p>The only issue I ran into was that I was originally using the RSS flavor of recent tracks, however it didn&#8217;t split up the artist and track information. It displays it as <code>&lt;title&gt;[artist] – [track]&lt;/title&gt;</code>. That en-dash in the middle was preventing me from using <code>title.split()</code> on the JavaScript side of things. Really weird.</p>
<p>Also, since I&#8217;m a complete newbie with <a href="http://www.ruby-lang.org/">Ruby</a>, I couldn&#8217;t figure out how (read: didn&#8217;t take the time to learn) to grab the content from a remote server and serve it up to the JavaScript. I&#8217;m sure it&#8217;s pretty simple&#8230; but I was at work and in a hurry. So, being that I know <a href="http://www.php.net/">PHP</a>, I just created a script to download the file and save it to the local disk and setup a cronjob.</p>
<p>Here&#8217;s the PHP script:</p>
<pre><code>class lastfm
{
    private $user;
    private $reports;
    private $basews;
    public $saveto;

    function __construct($user)
    {
        $this-&gt;user = $user;
        $this-&gt;basews = 'http://ws.audioscrobbler.com/1.0/user/';
        $this-&gt;reports = array(
            'recenttracks.xml',
            'weeklyartistchart.xml',
            'weeklytrackchart.xml',
            'topartists.xml'
        );
        $this-&gt;saveto = '.';
    }

    public function go()
    {
        for ($i = 0; $i &lt; count($this-&gt;reports); $i++)
        {
            try
            {
                $opts = array('http' =&gt; array('method' =&gt; 'GET', 'header' =&gt; 'Content-type: text/plain; charset=utf-8'));
                $context = stream_context_create($opts);

                $fp = fopen($this-&gt;saveto.DIRECTORY_SEPARATOR.$this-&gt;reports[$i], 'w+');
                $stream = fopen($this-&gt;basews.$this-&gt;user.'/'.$this-&gt;reports[$i], 'r', false, $context);
                $string = stream_get_contents($stream);
                fwrite($fp, $string);
                fclose($fp);
                fclose($stream);
                echo 'Saved ' . $this-&gt;saveto.DIRECTORY_SEPARATOR.$this-&gt;reports[$i] . "\n";
            }
            catch (Exception $e)
            {
                echo $e-&gt;getMessage() . "\n";
            }
        }
    }

    public function setSaveto($path)
    {
        if (is_dir($path))
        {
            if (ereg('\/$', $path))
            {
                $path = ereg_replace('\/$', '', $path);
            }
            $this-&gt;saveto = $path;
        }
        else
        {
            $this-&gt;createDir($path);
            $this-&gt;setSaveto($path);
        }
    }

    private function createDir($path)
    {
        if (!is_dir($path))
        {
            $res = `mkdir -p $path`;
        }
    }
}
</code></pre>
<p>I&#8217;ll hit up the <a href="http://api.rubyonrails.org/">Rails API Docs</a> one of these days and write a simple Ruby script that does all the work of the PHP script. Even better would be to process the XML document using ruby that just returns a string of HTML and use <code>Ajax.PeriodicalUpdater($(e), ...)</code>.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/01/24/scrobble-this-last-fm-recent-tracks-ajax-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Permalinks In Typo</title>
		<link>http://www.randys.org/2007/01/12/changing-permalinks-in-typo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=changing-permalinks-in-typo</link>
		<comments>http://www.randys.org/2007/01/12/changing-permalinks-in-typo/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 19:50:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[typo]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/01/12/changing-permalinks-in-typo</guid>
		<description><![CDATA[When I switched from WordPress to Typo, I faced the issue of keeping my WordPress permalinks in Typo. Unfortunately, there&#8217;s no simple way of doing this. I noticed the &#8216;redirects&#8217; table in the database, but I could never get it &#8230; <a href="http://www.randys.org/2007/01/12/changing-permalinks-in-typo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When I switched from <a href="http://www.wordpress.org">WordPress</a> to <a href="http://www.typoshpere.org">Typo</a>, I faced the issue of keeping my WordPress permalinks in Typo. Unfortunately, there&#8217;s no simple way of doing this. I noticed the &#8216;redirects&#8217; table in the database, but I could never get it to realy do anything. So, I had to dig in and find the bit of code that controlled the permalinks in Typo.</p>
<p>Typo uses &#8216;articles&#8217; as it&#8217;s base for all posts so I looked in <code>config/routes.rb</code> and found what I needed to change. As you can see from the <a href="http://www.randys.org/content/2007/01">url</a> of this post, I use &#8216;content&#8217; as the base of my permalink. So, I changed all the references of &#8216;articles&#8217; to &#8216;content&#8217; and all seems to be right in the world.</p>
<p>I changed</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">map.connect <span class="s"><span class="dl">'</span><span class="k">articles</span><span class="dl">'</span></span>,<tt>
</tt>    <span class="sy">:controller</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">articles</span><span class="dl">'</span></span>, <span class="sy">:action</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">index</span><span class="dl">'</span></span></pre>
</td>
</tr>
</table>
<p>to</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">map.connect <span class="s"><span class="dl">'</span><span class="k">content</span><span class="dl">'</span></span>,<tt>
</tt>    <span class="sy">:controller</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">articles</span><span class="dl">'</span></span>, <span class="sy">:action</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">index</span><span class="dl">'</span></span></pre>
</td>
</tr>
</table>
<p>and then changed</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">map.connect <span class="s"><span class="dl">'</span><span class="k">articles/:year/:month/:day</span><span class="dl">'</span></span>,<tt>
</tt>    <span class="sy">:controller</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">articles</span><span class="dl">'</span></span>, <span class="sy">:action</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">find_by_date</span><span class="dl">'</span></span>,<tt>
</tt>    <span class="sy">:year</span> =&gt; <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">{4}</span><span class="dl">/</span></span>, <span class="sy">:month</span> =&gt; <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">{1,2}</span><span class="dl">/</span></span>, <span class="sy">:day</span> =&gt; <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">{1,2}</span><span class="dl">/</span></span></pre>
</td>
</tr>
</table>
<p>to</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">map.connect <span class="s"><span class="dl">'</span><span class="k">content/:year/:month/:day</span><span class="dl">'</span></span>,<tt>
</tt>    <span class="sy">:controller</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">articles</span><span class="dl">'</span></span>, <span class="sy">:action</span> =&gt; <span class="s"><span class="dl">'</span><span class="k">find_by_date</span><span class="dl">'</span></span>,<tt>
</tt>    <span class="sy">:year</span> =&gt; <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">{4}</span><span class="dl">/</span></span>, <span class="sy">:month</span> =&gt; <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">{1,2}</span><span class="dl">/</span></span>, <span class="sy">:day</span> =&gt; <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">{1,2}</span><span class="dl">/</span></span></pre>
</td>
</tr>
</table>
<p>and so on.</p>
<p>The only thing I haven&#8217;t gotten to work is to map the pages. I can change the &#8216;pages&#8217; map, but it doesn&#8217;t act as desired. I only had 3 pages in WordPress, so I might as well either alias them or premanent redirect in the <a href="http://httpd.apache.org">Apache</a> configuration.</p>
<p>If anybody has some insight, I&#8217;d love to here it. Also, still haven&#8217;t figured out why <code>mod_rewrite</code> is working like it should.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/01/12/changing-permalinks-in-typo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache2: mod_rewrite vs. mod_proxy</title>
		<link>http://www.randys.org/2007/01/11/apache2-mod_rewrite-vs-mod_proxy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=apache2-mod_rewrite-vs-mod_proxy</link>
		<comments>http://www.randys.org/2007/01/11/apache2-mod_rewrite-vs-mod_proxy/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 00:43:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mongrel]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/01/11/apache2-mod_rewrite-vs-mod_proxy</guid>
		<description><![CDATA[I can&#8217;t quite figure this out. I&#8217;m trying to write a simple rule to force randys.org to redirect to www.randys.org but it&#8217;s not realy working. Of course, I haven&#8217;t tried it on a vhost that isn&#8217;t proxying request to mongrel. &#8230; <a href="http://www.randys.org/2007/01/11/apache2-mod_rewrite-vs-mod_proxy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t quite figure this out. I&#8217;m trying to write a simple rule to force <code>randys.org</code> to redirect to <code>www.randys.org</code> but it&#8217;s not realy working. Of course, I haven&#8217;t tried it on a vhost that isn&#8217;t proxying request to mongrel. Here&#8217;s the rule:</p>
<pre><code>RewriteEngine On
RewriteCond %{HTTP_HOST}    !^www.randys.org$ [NC]
RewriteCond %{HTTP_HOST}    !^$
RewriteRule ^/(.*)          http://www.randys.org/$1 [R=301,L]
</code></pre>
<p>Anyone?</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/01/11/apache2-mod_rewrite-vs-mod_proxy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Typo, Apache &amp; Mongrel, Oh My!</title>
		<link>http://www.randys.org/2007/01/10/typo-apache-mongrel-oh-my/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=typo-apache-mongrel-oh-my</link>
		<comments>http://www.randys.org/2007/01/10/typo-apache-mongrel-oh-my/#comments</comments>
		<pubDate>Wed, 10 Jan 2007 02:32:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.randys.org//2007/01/10/typo-apache-mongrel-oh-my</guid>
		<description><![CDATA[Wow. I&#8217;ve been testing the possibility of running Typo on my VPS with the pre-notion that it just wouldn&#8217;t work very well. I think I may be wrong. It&#8217;s been running for about a week while I tweak some shit &#8230; <a href="http://www.randys.org/2007/01/10/typo-apache-mongrel-oh-my/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Wow. I&#8217;ve been testing the possibility of running <a href="http://typosphere.org">Typo</a> on my VPS with the pre-notion that it just wouldn&#8217;t work very well. I think I may be wrong. It&#8217;s been running for about a week while I tweak some shit and so far, my memory performance has been stable. Of course, thing would probably be different if I threw some <strong>real</strong> traffic at it&#8230; but, then again, I don&#8217;t get a lot of that.</p>
<h2>The Setup</h2>
<p>Initially, I was going to use <a href="http://www.lighttpd.net">lighty</a> + <a href="http://www.fastcgi.com">fastcgi</a> to serve up the Rails application. So, I had setup lighty to serve up my PHP/MySQl sites and that worked just fine. Then I started reading up on <a href="http://mongrel.rubyforge.org">Mongrel</a> and wanted to see what all the hubub was about. But then I got to reading the <a href="http://mongrel.rubyforge.org">Mongrel</a> site (more specifically the part where he says <a href="http://mongrel.rubyforge.org/docs/lighttpd.html">don&#8217;t use lighty and mod_proxy</a>).</p>
<p>Crap.</p>
<p>Aight, so back to <a href="http://httpd.apache.org">Apache</a> and their proxy setup. no biggie. I racked my brain for several hours one night trying to figure out why the hell I kept getting these 403 Forbidden errors in Apache. Hours. After the millionth <a href="http://www.google.com">Google</a> search, I finally found the issue: The mod_proxy configuration <em>in <a href="http://www.ubuntu.com">Ubuntu</a></em> is turned off by default (well, not really turned off&#8230; it just denies traffic to the proxy server).</p>
<pre><code> 8     &lt;Proxy *&gt;
 9         Order deny,allow
10         #Deny from all
11         Allow from .randys.org
12     &lt;/Proxy&gt;
</code></pre>
<p>Line 8 was initially not commented out. I had to comment that out and add the <code>Allow from .randys.org</code> bit.</p>
<p>Once I got that changed and reloaded Apache, everything is working nicely together.. even <a href="http://www.php.net">PHP</a>.</p>
<h2>The Tweaks</h2>
<p>So far, the only tweaks I&#8217;ve managed to make is to the <a href="http://www.flickr.com">flickr</a> Sidebar plugin. It now uses <a href="http://www.huddletogether.com/projects/lightbox2/">Lightbox V2</a>. That was a bit tricky, considering I don&#8217;t really know <a href="http://www.ruby-lang.org">Ruby</a> but, it all worked out in the end.</p>
<p>As I figure out more <em>stuff</em> to do, I&#8217;ll post more.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2007/01/10/typo-apache-mongrel-oh-my/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LiMP: Lighttpd, MySQL &amp; PHP on OS X</title>
		<link>http://www.randys.org/2006/10/03/limp-lighttpd-mysql-php-on-os-x/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=limp-lighttpd-mysql-php-on-os-x</link>
		<comments>http://www.randys.org/2006/10/03/limp-lighttpd-mysql-php-on-os-x/#comments</comments>
		<pubDate>Tue, 03 Oct 2006 07:19:00 +0000</pubDate>
		<dc:creator>randy</dc:creator>
				<category><![CDATA[Code Chunks]]></category>
		<category><![CDATA[General Nerdery]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[os]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[x]]></category>

		<guid isPermaLink="false">http://www.randys.org//2006/10/03/limp-lighttpd-mysql-php-on-os-x</guid>
		<description><![CDATA[In following with the LAMP, MAMP, and WAMP themes, I&#8217;ve come up with my own acronym: LiMP. Lighttpd, MySQL, PHP. Of course, this doesn&#8217;t really follow the conventions of the other acronyms (my OS isn&#8217;t represented). Mainly because adding an &#8230; <a href="http://www.randys.org/2006/10/03/limp-lighttpd-mysql-php-on-os-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In following with the LAMP, MAMP, and WAMP themes, I&#8217;ve come up with my own acronym: LiMP. <a href="http://lighttpd.net">Lighttpd</a>, <a href="http://www.mysql.com">MySQL</a>, <a href="http://www.php.net">PHP</a>. Of course, this doesn&#8217;t <em>really</em> follow the conventions of the other acronyms (my OS isn&#8217;t represented). Mainly because adding an &#8216;M&#8217; just doesn&#8217;t sound (or look) right. It&#8217;s a great setup and I recently reconfigured it so it&#8217;s a (somewhat) isolated installation that could potentially be installed on any OS X system. I also managed to get ExecWrap working properly as well.</p>
<p><em>*NB</em>*<br />
This is a fairly technical article and requires getting your fingers dirty in the Terminal (a.k.a. comman line). If you&#8217;re not fully comfortable in the Terminal, I suggest you familiarize yourself with the Terminal. You&#8217;ll also need to have installed the latest version of <a href="http://developer.apple.com/tools/index.html">Xcode</a>.</p>
<p>You can build this just about anywhere on your system you like. I personally keep everything in
<pre><code>/usr/local/src</code></pre>
<p> but you can build this anywhere you want on your system. I also like to
<pre><code>sudo -s</code></pre>
<p> so that I&#8217;m always root when comiling and installing these things. Let&#8217;s jump in&#8230;</p>
<p>Create your src directories:</p>
<pre><code>mkdir -p /usr/local/src &amp;&amp; cd /usr/local/src
</code></pre>
<p>That&#8217;s it. Now lets dig in&#8230;</p>
<h2>Setting up Lighttpd on OS X</h2>
<p>I figured building this on OS X wouldn&#8217;t take too much effort and I was pretty much right. Lighttpd builds just fine on OS X but it does need some other libraries installed for certain functionality. Specifically, <a href="http://www.fastcgi.com/">fastcgi</a> and <a href="http://www.pcre.org/" title="PCRE">Perl Compatible Regular Expressions</a>. These libraries install without issue as well.</p>
<p>First lets grab the fastcgi libraries:</p>
<pre><code>curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar zxvf fcgi-2.4.0.tar.gz &amp;&amp; cd fcgi-2.4.0
./configure
make
make install
cd ..
</code></pre>
<p>Now lets get the PCRE libraries:</p>
<pre><code>curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-5.0.tar.gz
tar zxvf pcre-5.0.tar.gz &amp;&amp; cd pcre-5.0
./configure
make
make install
cd ..
</code></pre>
<p>Now for lighttpd:</p>
<pre><code>curl -O http://www.lighttpd.net/download/lighttpd-1.4.12.tar.gz
tar zxvf lighttpd-1.4.12.tar.gz &amp;&amp; cd lighttpd-1.4.12
./configure --prefix=/Library/limp/lighttpd
</code></pre>
<p>Hopefully, you&#8217;ll see something like this after the configure script is done.</p>
<pre><code>Plugins:

mod_rewrite     : enabled
mod_redirect    : enabled
mod_ssi         : enabled
mod_cgi         : enabled
mod_fastcgi     : enabled
mod_proxy       : enabled
mod_evhost      : enabled
mod_simple_vhost: enabled
mod_mysql_vhost : enabled
mod_access      : enabled
mod_alias       : enabled
mod_setenv      : enabled
mod_usertrack   : enabled
mod_compress    : enabled
mod_auth        : enabled
mod_status      : enabled
mod_accesslog   : enabled
mod_rrdtool     : enabled
mod_secdownload : enabled
mod_expire      : enabled
</code></pre>
<p>If you don&#8217;t see mod_fastcgi in there, something went south.</p>
<pre><code>make
make install
cp doc/lighttpd.conf /Library/limp/lighttpd/lighttpd.conf
</code></pre>
<h2>MySQL</h2>
<p>For MySQL, I just used the standard binary installation provided by <a href=") themselves. Unfortunately, the doesn't install the correct libraries for compiling the mysqli extension of PHP (which is needed for MySQL 4.1 and newer">MySQL</a>. Therefore, we&#8217;ll need to also configure and install the libraries after installing the binary package. (Thanks to <a href="http://switch.richard5.net/isp-in-a-box-v2/installing-mysql-on-mac-os-x/">Richard Valk</a> for his article series for this bit).</p>
<p>First, download and install MySQL (version 5.0.24a as of this writing) Standard binary for OS X for your platform (PPC or Intel). Once you&#8217;ve installed the package, install the StartupItem and make your life simple-er (??). After everything is setup, you should modify your
<pre><code>PATH</code></pre>
<p> environment variable again in your ~/.bashrc file.</p>
<pre><code>export PATH="/usr/local/bin:/usr/local/mysql/bin:"${PATH}
</code></pre>
<p>Now we have to rebuild mysql and install the shared libraries we need for building PHP. Make sure you&#8217;re still in your &#8216;src&#8217; directory.</p>
<pre><code>curl -O http://www.stathy.com/mysql/Downloads/MySQL-5.0/mysql-5.0.24.tar.gz
tar zxvf mysql-5.0.24.tar.gz &amp;&amp; cd mysql-5.0.24
./configure --prefix=/usr/local/mysql \
 --localstatedir=/usr/local/mysql/data \
 --libexecdir=/usr/local/mysql/bin \
 --libdir=/usr/local/mysql/lib \
 --with-server-suffix=-standard \
 --enable-thread-safe-client \
 --enable-local-infile \
 --enable-shared \
 --with-zlib-dir=bundled \
 --with-big-tables \
 --with-readline \
 --with-archive-storage-engine \
 --with-innodb \
 --without-docs \
 --without-bench \
make
make install
cd ..
</code></pre>
<h2>Compiling PHP on OS X (with the mysqli extension)</h2>
<p>This was fairly straight forward with the exception of GD. It took me a while to figure this out, but I was using
<pre><code>--with-gd=/sw</code></pre>
<p> and this was confusing the compiler for some reason. When I changed it to just
<pre><code>--with-gd</code></pre>
<p> everything compiled fine&#8230; including the mysqli extension. Here&#8217;s what my config looks like:</p>
<pre><code>./configure \
 --prefix=/Lbrary/limp/php \
 --enable-fastcgi \
 --enable-force-cgi-redirect \
 --enable-mbstring \
 --with-xml \
 --with-zlib \
 --with-curl \
 --with-mysql=/usr/local/mysql \
 --with-pdo-mysql=/usr/local/mysql \
 --with-mysqli=/usr/local/mysql/bin/mysql_config \
 --with-pdo-sqlite \
 --with-sqlite \
 --with-mcrypt=/sw \
 --with-gd \
 --with-jpeg-dir=/sw \
 --with-png-dir=/sw \
 --with-zlib-dir=/sw \
 --with-xpm-dir=/usr \
 --enable-exif \
 --enable-ftp \
 --enable-libxml \
 --enable-soap \
 --enable-sockets

make &amp;&amp; make install
cp /Library/limp/php/bin/php /Library/limp/php/bin/php-cgi
</code></pre>
<p>I&#8217;m renaming the php binary to php-cgi because, well, that&#8217;s what it is. It&#8217;s the CGI version, not the CLI version. If you want to compile the CLI version, replace</p>
<pre><code> --enable-fastcgi \
 --enable-force-cgi-redirect \
</code></pre>
<p>with</p>
<pre><code> --enable-cli \
</code></pre>
<p>and run
<pre><code>make &amp;&amp; make install</code></pre>
<p> again. Only do this <strong>after</strong> you&#8217;ve renamed the php file to php-cgi. Otherwise, you&#8217;ll overwrite the cgi version with the cli version and it won&#8217;t work with fastcgi.</p>
<h2>Building ExecWrap</h2>
<hr/>
<p>I&#8217;ll have to finish this at a later date&#8230; sorry. This was originally posted to my old WordPress blog as a <em>Draft</em> but got imported into Typo via the wordpress2.rb script as a published article&#8230; so I left it.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.randys.org/2006/10/03/limp-lighttpd-mysql-php-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

