<?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>Alunduil&#039;s Hosting</title>
	<atom:link href="http://www.alunduil.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alunduil.com</link>
	<description>Gentoo Hackery and Other Fun ...</description>
	<lastBuildDate>Sun, 01 May 2011 22:00:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Apache Rewrite Cheat Sheet</title>
		<link>http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/</link>
		<comments>http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/#comments</comments>
		<pubDate>Sun, 01 May 2011 22:00:34 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewritelog]]></category>
		<category><![CDATA[rewriteloglevel]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=410</guid>
		<description><![CDATA[Introduction I was recently requested to document common apache rewrite pitfalls and examples and crafted the following document as a response.  It is intended as a two page document (Rewrite Cheat Sheet) where the first page is a reference guide of commonly used rewrite variables and flags and the second page is a short list of <a href='http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		P.western { font-size: 10pt } 		P.cjk { font-size: 10pt } 		H1 { margin-bottom: 0.08in } 		H1.western { font-family: "Liberation Sans", sans-serif; font-size: 15pt } 		H1.cjk { font-family: "DejaVu Sans"; font-size: 16pt } 		H1.ctl { font-family: "DejaVu Sans"; font-size: 16pt } 		H2 { margin-bottom: 0.08in } 		H2.western { font-family: "Liberation Sans", sans-serif; font-size: 12pt; font-style: italic } 		H2.cjk { font-size: 14pt; font-style: italic; font-weight: normal } 		H2.ctl { font-size: 14pt; font-style: italic; font-weight: normal } 		H3 { margin-bottom: 0.08in } 		H3.western { font-family: "Liberation Sans", sans-serif; font-size: 12pt } 		CODE.cjk { font-family: "DejaVu Sans", monospace } --></p>
<h1>Introduction</h1>
<p>I was recently requested to document common apache rewrite pitfalls and examples and crafted the following document as a response.  It is intended as a two page document (<a href="http://www.alunduil.com/wp-content/uploads/2011/04/Rewrite-Cheat-Sheet.pdf">Rewrite Cheat Sheet</a>) where the first page is a reference guide of commonly used rewrite variables and flags and the second page is a short list of examples, gotchas, and troubleshooting advice.</p>
<h1>Rewrite Cheat Sheet</h1>
<h2>Common Variables</h2>
<h3>HTTP Headers</h3>
<ul>
<li>HTTP_USER_AGENT</li>
<li>HTTP_REFERER</li>
<li>HTTP_COOKIE</li>
<li>HTTP_FORWARDED</li>
<li>HTTP_HOST</li>
<li>HTTP_PROXY_CONNECTION</li>
<li>HTTP_ACCEPT</li>
</ul>
<h3>connection &amp; request</h3>
<ul>
<li>REMOTE_ADDR</li>
<li>REMOTE_HOST</li>
<li>REMOTE_PORT</li>
<li>REMOTE_USER</li>
<li>REMOTE_IDENT</li>
<li>REQUEST_METHOD</li>
<li>SCRIPT_FILENAME</li>
<li>PATH_INFO</li>
<li>QUERY_STRING</li>
<li>AUTH_TYPE</li>
</ul>
<h3>server internals</h3>
<ul>
<li>DOCUMENT_ROOT</li>
<li>SERVER_ADMIN</li>
<li>SERVER_NAME</li>
<li>SERVER_ADDR</li>
<li>SERVER_PORT</li>
<li>SERVER_PROTOCOL</li>
<li>SERVER_SOFTWARE</li>
</ul>
<h3>date and time</h3>
<ul>
<li>TIME_YEAR</li>
<li>TIME_MON</li>
<li>TIME_DAY</li>
<li>TIME_HOUR</li>
<li>TIME_MIN</li>
<li>TIME_SEC</li>
<li>TIME_WDAY</li>
<li>TIME</li>
</ul>
<h3>specials</h3>
<ul>
<li>API_VERSION</li>
<li>THE_REQUEST</li>
<li>REQUEST_URI</li>
<li>REQUEST_FILENAME</li>
<li>IS_SUBREQ</li>
<li>HTTPS</li>
</ul>
<h2>Variable Descriptions</h2>
<ul>
<li><code>REQUEST_FILENAME</code>
<ul>
<li>The full local filesystem path to the file 		or script matching the request, if this has already been determined 		by the server at the time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such as when used in virtual host 		context, the same value as <code>REQUEST_URI</code>.</li>
</ul>
</li>
<li><code>HTTPS</code>
<ul>
<li>Will contain the text &#8220;on&#8221; if the 		connection is using SSL/TLS, or &#8220;off&#8221; otherwise. (This 		variable can be safely used regardless of whether or not <code>mod_ssl</code> is loaded).</li>
</ul>
</li>
</ul>
<h2>Flag Descriptions</h2>
<ul>
<li>&#8216;<code>nocase|NC</code>&#8216; (<strong>n</strong>o 	<strong>c</strong>ase) :: This makes the test case-insensitive &#8211; 	differences between &#8216;A-Z&#8217; and &#8216;a-z&#8217; are ignored, both in the 	expanded <em>TestString</em> and the <em>CondPattern</em>.</li>
<li>&#8216;<code>ornext|OR</code>&#8216; (<strong>or</strong> next condition) (<strong>RewriteCond Only</strong>) :: Use this to combine 	rule conditions with a local OR instead of the implicit AND.</li>
<li><strong>&#8216;last|L&#8217;</strong> :: Stop the rewriting 	process immediately and don&#8217;t apply any more rules.</li>
<li><strong>&#8216;proxy|P&#8217;</strong> :: Force the substitution 	URL to be internally sent as a proxy request.</li>
<li><em><strong>&#8216;qsappend|QSA</strong></em><em>&#8216;</em><em> :: Appends any query string created in the rewrite target to any 	query string that was in the original request URL.</em></li>
<li><em>&#8216;</em><em><strong>redirect|R[=code]</strong></em><em>&#8216; 	:: </em><em>Forces an external redirect, optionally with the 	specified HTTP status code.</em></li>
<li><em>&#8216;</em><em><strong>forbidden|F</strong></em><em>&#8216;</em><em> :: Returns a 403 FORBIDDEN response to the client browser.</em></li>
</ul>
<h2>Good Examples</h2>
<ul>
<li>Adding www to all requests
<ul>
<li>RewriteCond %{HTTP_HOST} !^www [NC]</li>
<li>RewriteRule ^ 		http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]</li>
</ul>
</li>
<li>Forcing all requests to HTTPS
<ul>
<li>RewriteCond %{HTTPS} off</li>
<li>RewriteRule ^ 		https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]</li>
</ul>
</li>
<li>Redirect a specific subweb to another domain
<ul>
<li>RewriteRule ^/?subweb/(.*) 		http://other.example.com/$1 [R,L,QSA]</li>
</ul>
</li>
<li>Block specific IPs from access
<ul>
<li>RewriteCond %{REMOTE_ADDR} ^127\.0\.0</li>
<li>RewriteRule ^ &#8211; [F,L]</li>
</ul>
</li>
<li>Creating a filesystem alias with modrewrite
<ul>
<li>RewriteRule ^/?alias/(.*) 		/var/www/vhosts/$1/httpdocs/$1 [L,R]</li>
</ul>
</li>
<li>A condition to stop CMS software from 	over-riding fullstatus (added before the offending rewriterule)
<ul>
<li>RewriteCond ${REQUEST_URI} !server-status 		[NC]</li>
</ul>
</li>
</ul>
<h2>Bad Examples</h2>
<ul>
<li>Recursive rewrite
<ul>
<li>RewriteRule ^ 		http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]</li>
</ul>
</li>
</ul>
<h2>Gotchas</h2>
<ul>
<li>Some rewrites may conflict with existing 	rewrites provided by many CMS packages (wordpress, drupal, joomla, 	etc).  Check for any existing rewrites in a .htaccess file.</li>
<li>Rewriterule and rewritecond can only be used 	in the following contexts: server config, virtual host, directory, 	.htaccess</li>
</ul>
<h2>Common Troubleshooting</h2>
<ul>
<li>Enable the rewrite logs with RewriteLog and 	RewriteLevel
<ul>
<li>RewriteLog &lt;file path&gt;</li>
<li>RewriteLogLevel 3 # ranges from 0 to 9</li>
</ul>
</li>
<li>Check your regular expressions against a PCRE 	checker (they are very bountiful on the Internet 	[http://tinyurl.com/3hop7xu]).</li>
<li>Utilize curl to test redirects (R), `curl -I 	example.com`</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Battery Life</title>
		<link>http://www.alunduil.com/2011/03/06/android-battery-life/</link>
		<comments>http://www.alunduil.com/2011/03/06/android-battery-life/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 23:00:25 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[battery]]></category>
		<category><![CDATA[juice defender]]></category>
		<category><![CDATA[juice plotter]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=400</guid>
		<description><![CDATA[Recently, I&#8217;ve stumbled across an application in the android market, juice defender, that does exactly what it advertises. The application extends battery life through automated micromanaging of peripherals and software. This combined with another application, juice plotter, allows one to actually experiment with different battery preserving techniques (or different ROMs for the rooted phones). More <a href='http://www.alunduil.com/2011/03/06/android-battery-life/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve stumbled across an application in the android market, <a href="http://latedroid.com/juicedefender">juice defender</a>, that does exactly what it advertises.  The application extends battery life through automated micromanaging of peripherals and software.  This combined with another application, <a href="http://www.appbrain.com/app/juiceplotter/com.latedroid.juiceplotter">juice plotter</a>, allows one to actually experiment with different battery preserving techniques (or different ROMs for the rooted phones).</p>
<p>More specifically, the application behaves much like any other power management software in other Linux installations.  It controls the frequency scaling of the processor (if the phone is rooted), it controls networking interfaces and screens to help conserve power.  All of this functionality can easily be configured and modified for your desired power settings, but the defaults will provide a significant boost to battery life. This is one more useful utility in a long list that allows us to get the most out of our phones.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/03/06/android-battery-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Automation</title>
		<link>http://www.alunduil.com/2011/02/27/android-automation/</link>
		<comments>http://www.alunduil.com/2011/02/27/android-automation/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 23:00:41 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[profile valet]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=394</guid>
		<description><![CDATA[Recently I&#8217;ve found the wonderful Android application, profile valet.  This little application handles location and time based profiles for various settings on your Android device.  It can control things like sound, wifi and bluetooth based on time schedules or location (GPS backed).  Using a utility like this can help prevent the common, &#8220;I forgot to <a href='http://www.alunduil.com/2011/02/27/android-automation/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve found the wonderful Android application, <a href="http://www.appbrain.com/app/profile-valet/com.pushpin.profile">profile valet</a>.  This little application handles location and time based profiles for various settings on your Android device.  It can control things like sound, wifi and bluetooth based on time schedules or location (GPS backed).  Using a utility like this can help prevent the common, &#8220;I forgot to unsilence my phone,&#8221; resulting in missed calls, texts or emails.  It can also be used to control silencing your phone for certain events.  Simply setup a profile for various movie theaters to silence your phone automatically when you enter that area.</p>
<p>By automating the little things in life we can open up our minds to less stress and turn our attention to more fun or important matters.  I know offloading thought has been pushed by the <a href="http://www.amazon.com/Getting-Things-Done-Stress-Free-Productivity/dp/0142000280/ref=sr_1_1?ie=UTF8&amp;qid=1298391597&amp;sr=8-1">&#8220;Getting Things Done&#8221;</a> paradigm but it can be expanded with the smartphone.  It can be expanded to allow our devices to be the tool they were designed to be.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/27/android-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing Gentoo CFLAGS (Part II)</title>
		<link>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/</link>
		<comments>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 23:00:46 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cflags]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=205</guid>
		<description><![CDATA[Introduction As I mentioned las﻿t time, you want to be comfortable with the existing documentation on CFLAGS before going crazy trying to play with. It also helps to have a good understanding of what you&#8217;re doing to the code when you modify these &#8220;sacred&#8221; parameters. Alright, now that the CYA is out of the way <a href='http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>As I mentioned <a href="http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/">las﻿t time</a>, you want to be comfortable with the existing documentation on CFLAGS before going crazy trying to play with.  It also helps to have a good understanding of what you&#8217;re doing to the code when you modify these &#8220;sacred&#8221; parameters.</p>
<p>Alright, now that the CYA is out of the way let&#8217;s take this one step further.  Last time we talked about figuring out which instruction sets your processor understood and how to figure out what `-m` flags would get those instruction sets into the binaries on your system.  This time we&#8217;ll be talking about making sure those same flags are in your use flags (just to be sure they&#8217;re picked up by the system).</p>
<h1>Finding Flag Names</h1>
<p>So how do we find the flags that do what we want?  Well, as always BASH is our friend and can be used to find this answer in a mostly automated fashion:</p>
<pre>. /etc/make.conf &amp;&amp; gcc -Q -c -v ${CFLAGS} --help=target | grep enabled</pre>
<p>This displays the currently enabled flags based on your CFLAGS parameter and allows us to find which flags have use flags with the following one liner:</p>
<pre>gawk '/-m.*/ { print $1 }' | cut -d 'm' --complement -f 1 | xargs -I{} equery h "{}"</pre>
<h1>Conclusion</h1>
<p>Using a little scripting we can extract the necessary information to quickly determine if there are any use flags we should be adding for particular compiler flags that our system might support.  With this last level of optimization beyond the previous time&#8217;s we should be ready to move on to -O3 (for the daring) and watch our machine&#8217;s nose bleed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What are Snapshots?</title>
		<link>http://www.alunduil.com/2011/02/15/what-are-snapshots/</link>
		<comments>http://www.alunduil.com/2011/02/15/what-are-snapshots/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 22:41:27 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[snapshots]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=373</guid>
		<description><![CDATA[Introduction It seems that disk snapshots have become a hot topic and a confusing topic.  I intend to simply outline what snapshots look like in terms of the lower layers of abstraction and nothing more.  Snapshots are built into things like LVM, SAN, etc but I will not be covering those technologies.  Instead, what I <a href='http://www.alunduil.com/2011/02/15/what-are-snapshots/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>It seems that disk snapshots have become a hot topic and a confusing topic.  I intend to simply outline what snapshots look like in terms of the lower layers of abstraction and nothing more.  Snapshots are built into things like LVM, SAN, etc but I will not be covering those technologies.  Instead, what I intend to cover is the abstractions ranging from the disk device to the snapshot.</p>
<h1>The Disk</h1>
<p>A hard disk is typically chopped up into pieces called partitions (and this is the unit I&#8217;ll use as my foundation).  These logical separations of the blocks on a disk allow us to make sure that disks are not over-allocated for one particular purpose or lose access to a system if one partition fills up, etc.  Partitioning is only the beginning.   We are able to take the idea of partitions and extend the idea of a contiguous region of blocks to the strange concept of snapshots as well.</p>
<h1>Writing to Disk</h1>
<p>Using our simplified view of a disk (a contiguous region of blocks) we can see that the simplest way to write data (ignoring filesystems) is to simply take our data one block at a time and place it on the disk.  This is great until we need to remove blocks or update blocks (which is probably why we only use this type of writing for tapes).  We&#8217;ll have to add some logic to this view of disks to handle the complexities of files but for all intensive purposes, disks are simply groups of blocks available for writing and groups of blocks that are already used.  If we want a consistent view of the data at any point it&#8217;s simply a matter of making sure nothing is writing to the disk (partition) we&#8217;re interested in.  This is where snapshots can help us out.</p>
<h1>Snapshots</h1>
<p>A snapshot creates another region of blocks we can write to.  Let me start that again &#8230; when you create a snapshot of some disk (snapshots are not standalone by any means) the following happens:</p>
<ul>
<li>It reserves space for a changelog (or writes that would happen to the disk) in the difference disk</li>
<li>It creates a new way to access the original disk via the snapshot name (which refers to the base disk)</li>
<li>It begins sending all writes to the reserved space for the changelog (depicted in the figure below)</li>
</ul>
<p>Thus, we have the following situation on the disk (again very simplified):</p>
<p><a href="http://www.alunduil.com/wp-content/uploads/2011/02/snapshots.png"><img class="aligncenter size-medium wp-image-375" title="snapshots" src="http://www.alunduil.com/wp-content/uploads/2011/02/snapshots-300x145.png" alt="" width="300" height="145" /></a></p>
<h1>Deleting Snapshots</h1>
<p>Since a snapshot isn&#8217;t a true partition what happens when one of these gets removed?  The obvious is that the snapshot name gets removed so it&#8217;s no longer accessible, but that&#8217;s not going to help rectify the two regions of data we now have on the disk.  This is handled by making the difference disk a literal list of differences.  I find it best to think of it (even though it may not actually be implemented in this fashion) as a queue of block changes or a transaction log for writes to the disk.  With this visualization of the process it makes sense as to what happens when the snapshot is removed:</p>
<ul>
<li>The reference to the base disk is removed</li>
<li>The difference disk is replayed onto the base disk (applying all recorded changes)</li>
</ul>
<p>That&#8217;s all there is to it.  Everything continues as if the snapshot exists until it has been fully replayed and then disk access resumes as normal without the snapshot.</p>
<h1>Conclusion</h1>
<p>Snapshots provide a convenient way to access a frozen image of a disk which is perfect for backups or point in time restores of data.  This is typically used via LVM, virtualbox, SANs, etc and has far-reaching impacts that allow system administration to be easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/15/what-are-snapshots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backing up PostgreSQL with Holland</title>
		<link>http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/</link>
		<comments>http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 01:10:40 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[bacula]]></category>
		<category><![CDATA[holland]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=294</guid>
		<description><![CDATA[Introduction Backups are a subject I return to semi-frequently with a passion to never be in an &#8220;oh shit&#8221; scenario.  Last time I built my backup system, bacula with a postgresql DB backend, I determined that I would move to a common database backup script for all of my databases.  Holland fit this bill perfectly <a href='http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Backups are a subject I return to semi-frequently with a passion to never be in an &#8220;oh shit&#8221; scenario.  Last time I built my backup system, bacula with a postgresql DB backend, I determined that I would move to a common database backup script for all of my databases.  Holland fit this bill perfectly with support for postgres, sqlite and mysql.  This allows one command to backup all of my databases on all of my servers and subsequently creates a much simpler bacula configuration (the database job is defined the same as the catalog job).</p>
<h1>The Solution</h1>
<p>The problem I had when configuring holland to backup postgresql is that there was no example configuration file.  It wasn&#8217;t hard to craft a working default postgres configuration and the following is what I came up with (/etc/holland/backupsets/default.conf:</p>
<pre>[holland:backup]
plugin = pgdump
backups-to-keep = 1
auto-purge-failures = yes
purge-policy = after-backup
estimated-size-factor = 1.0

[pgdump]
role = postgres

[pgauth]
username = postgres</pre>
<h1>Conclusion</h1>
<p>Setting up holland to backup databases is incredibly easy and flexible.  By having a common backup solution for all databases other configurations become easier and processes can be streamlined.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paging Problem Plague</title>
		<link>http://www.alunduil.com/2011/02/01/paging-problem-plague/</link>
		<comments>http://www.alunduil.com/2011/02/01/paging-problem-plague/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 21:21:00 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[panic]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=300</guid>
		<description><![CDATA[In the last couple of months I have been plagued by a problem with the system that hosts this website.  A nice kernel panic followed by a random uptime and a crash.  This is a bit difficult to swallow when the server is around 1200 miles away but a reboot and away it goes again. <a href='http://www.alunduil.com/2011/02/01/paging-problem-plague/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>In the last couple of months I have been plagued by a problem with the system that hosts this website.  A nice kernel panic followed by a random uptime and a crash.  This is a bit difficult to swallow when the server is around 1200 miles away but a reboot and away it goes again.</p>
<p>The actual error is show here:</p>
<pre>﻿Feb 01 14:13:27 [kernel] kernel BUG at mm/filemap.c:128!
Feb 01 14:13:27 [kernel] Modules linked in:
Feb 01 14:13:27 [kernel] Pid: 13604, comm: apache2 Not tainted 2.6.36-hardened-r6 #1 0K8980/Dimension 3000
Feb 01 14:13:27 [kernel] EIP: 0060:[&lt;c105af4f&gt;] EFLAGS: 00010046 CPU: 0
Feb 01 14:13:27 [kernel] EIP is at __remove_from_page_cache+0x44/0x91
Feb 01 14:13:27 [kernel] EAX: 00000000 EBX: c16acf40 ECX: 00000015 EDX: 00000015
Feb 01 14:13:27 [kernel] ESI: de877d7c EDI: ffffffff EBP: 00000015 ESP: dc4abe28
Feb 01 14:13:27 [kernel]  DS: 0068 ES: 0068 FS: 00d8 GS: 0033 SS: 0068
Feb 01 14:13:27 [kernel]  de877d7c c16acf40 c105afbc c16acf40 de877d7c c1061079 c16acf40 00000000
Feb 01 14:13:27 [kernel] &lt;0&gt; c1061123 de877d7c 00000015 00000006 ffffffff 00000000 0000000e 00000000
Feb 01 14:13:27 [kernel] &lt;0&gt; c1641f40 c1641f60 c1641f80 c1641fa0 c173ecc0 c1695de0 c16acf40 c15d2f00
Feb 01 14:13:27 [kernel]  [&lt;c105afbc&gt;] ? remove_from_page_cache+0x20/0x27
Feb 01 14:13:27 [kernel]  [&lt;c1061079&gt;] ? truncate_inode_page+0x6c/0x7d
Feb 01 14:13:27 [kernel]  [&lt;c1061123&gt;] ? truncate_inode_pages_range+0x99/0x23a
Feb 01 14:13:27 [kernel]  [&lt;c10612cd&gt;] ? truncate_inode_pages+0x9/0xc
Feb 01 14:13:27 [kernel]  [&lt;c10fa452&gt;] ? ext4_evict_inode+0x83/0x265
Feb 01 14:13:27 [kernel]  [&lt;c108dab2&gt;] ? evict+0x17/0x7b
Feb 01 14:13:27 [kernel]  [&lt;c108e211&gt;] ? iput+0x182/0x1df
Feb 01 14:13:27 [kernel]  [&lt;c108b58e&gt;] ? d_kill+0x2a/0x43
Feb 01 14:13:27 [kernel]  [&lt;c108c292&gt;] ? dput+0xf3/0xfb
Feb 01 14:13:27 [kernel]  [&lt;c107e289&gt;] ? fput+0x191/0x1b3
Feb 01 14:13:27 [kernel]  [&lt;c106e14f&gt;] ? remove_vma+0x34/0x52
Feb 01 14:13:27 [kernel]  [&lt;c106f26a&gt;] ? __do_munmap+0x257/0x2a8
Feb 01 14:13:27 [kernel]  [&lt;c106f335&gt;] ? sys_munmap+0x49/0x60
Feb 01 14:13:27 [kernel]  [&lt;c1378005&gt;] ? syscall_call+0x7/0xb
Feb 01 14:13:27 [kernel] ---[ end trace 4598df0f375c22c4 ]---
Feb 01 14:13:27 [kernel] kernel BUG at mm/filemap.c:128!Feb 01 14:13:27 [kernel] Modules linked in:Feb 01 14:13:27 [kernel] Pid: 13604, comm: apache2 Not tainted 2.6.36-hardened-r6 #1 0K8980/Dimension 3000               Feb 01 14:13:27 [kernel] EIP: 0060:[&lt;c105af4f&gt;] EFLAGS: 00010046 CPU: 0Feb 01 14:13:27 [kernel] EIP is at __remove_from_page_cache+0x44/0x91Feb 01 14:13:27 [kernel] EAX: 00000000 EBX: c16acf40 ECX: 00000015 EDX: 00000015Feb 01 14:13:27 [kernel] ESI: de877d7c EDI: ffffffff EBP: 00000015 ESP: dc4abe28Feb 01 14:13:27 [kernel]  DS: 0068 ES: 0068 FS: 00d8 GS: 0033 SS: 0068Feb 01 14:13:27 [kernel]  de877d7c c16acf40 c105afbc c16acf40 de877d7c c1061079 c16acf40 00000000Feb 01 14:13:27 [kernel] &lt;0&gt; c1061123 de877d7c 00000015 00000006 ffffffff 00000000 0000000e 00000000Feb 01 14:13:27 [kernel] &lt;0&gt; c1641f40 c1641f60 c1641f80 c1641fa0 c173ecc0 c1695de0 c16acf40 c15d2f00Feb 01 14:13:27 [kernel]  [&lt;c105afbc&gt;] ? remove_from_page_cache+0x20/0x27Feb 01 14:13:27 [kernel]  [&lt;c1061079&gt;] ? truncate_inode_page+0x6c/0x7dFeb 01 14:13:27 [kernel]  [&lt;c1061123&gt;] ? truncate_inode_pages_range+0x99/0x23aFeb 01 14:13:27 [kernel]  [&lt;c10612cd&gt;] ? truncate_inode_pages+0x9/0xcFeb 01 14:13:27 [kernel]  [&lt;c10fa452&gt;] ? ext4_evict_inode+0x83/0x265Feb 01 14:13:27 [kernel]  [&lt;c108dab2&gt;] ? evict+0x17/0x7bFeb 01 14:13:27 [kernel]  [&lt;c108e211&gt;] ? iput+0x182/0x1dfFeb 01 14:13:27 [kernel]  [&lt;c108b58e&gt;] ? d_kill+0x2a/0x43Feb 01 14:13:27 [kernel]  [&lt;c108c292&gt;] ? dput+0xf3/0xfbFeb 01 14:13:27 [kernel]  [&lt;c107e289&gt;] ? fput+0x191/0x1b3Feb 01 14:13:27 [kernel]  [&lt;c106e14f&gt;] ? remove_vma+0x34/0x52Feb 01 14:13:27 [kernel]  [&lt;c106f26a&gt;] ? __do_munmap+0x257/0x2a8Feb 01 14:13:27 [kernel]  [&lt;c106f335&gt;] ? sys_munmap+0x49/0x60Feb 01 14:13:27 [kernel]  [&lt;c1378005&gt;] ? syscall_call+0x7/0xbFeb 01 14:13:27 [kernel] ---[ end trace 4598df0f375c22c4 ]---</pre>
<p>The uprecords for this machine:</p>
<pre>﻿     #               Uptime | System                                     Boot up
----------------------------+---------------------------------------------------
     1    24 days, 20:31:52 | Linux 2.6.32-hardened-r2  Thu Nov 25 20:58:34 2010
     2    18 days, 09:10:28 | Linux 2.6.36-hardened-r6  Sat Jan  8 12:31:38 2011
     3    15 days, 12:41:25 | Linux 2.6.32-hardened-r9  Fri Oct  8 09:48:07 2010
     4    14 days, 03:43:24 | Linux 2.6.32-hardened-r2  Wed Nov  3 11:29:55 2010
     5     9 days, 19:44:59 | Linux 2.6.32-hardened-r2  Sun Oct 24 15:14:10 2010
     6     7 days, 21:49:22 | Linux 2.6.32-hardened-r2  Mon Dec 20 17:31:43 2010
     7     7 days, 17:34:24 | Linux 2.6.36-hardened-r6  Tue Dec 28 15:58:45 2010
     8     7 days, 08:53:26 | Linux 2.6.32-hardened-r2  Thu Nov 18 11:55:57 2010
     9     5 days, 16:58:46 | Linux 2.6.36-hardened-r6  Wed Jan 26 21:43:51 2011
    10     3 days, 00:09:43 | Linux 2.6.36-hardened-r6  Wed Jan  5 12:17:33 2011
----------------------------+---------------------------------------------------
-&gt;  13     0 days, 00:14:46 | Linux 2.6.36-hardened-r6  Tue Feb  1 15:02:26 2011
----------------------------+---------------------------------------------------
1up in     0 days, 00:40:31 | at                        Tue Feb  1 15:57:42 2011
t10 in     2 days, 23:54:58 | at                        Fri Feb  4 15:12:09 2011
no1 in    24 days, 20:17:07 | at                        Sat Feb 26 11:34:18 2011
    up   115 days, 09:00:18 | since                     Fri Oct  8 09:48:07 2010
  down     0 days, 21:28:47 | since                     Fri Oct  8 09:48:07 2010
   %up               99.230 | since                     Fri Oct  8 09:48:07 2010</pre>
<p>In conclusion, I&#8217;m suspecting a hardware issue but if anyone has any ideas as to what might cause this type of problem I&#8217;d be more than happy to hear possible causes and solutions until I get a replacement server built out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/01/paging-problem-plague/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Special Keys in zsh</title>
		<link>http://www.alunduil.com/2011/01/27/special-keys-in-zsh/</link>
		<comments>http://www.alunduil.com/2011/01/27/special-keys-in-zsh/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 02:26:40 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bindkey]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[end]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=288</guid>
		<description><![CDATA[I recently made the plunge and began using zsh in lieu of bash.  I&#8217;ve not regretted the decision in the slightest but there have been minor annoyances that needed to be dealt with.  The simplest annoyance was the special keys (delete, home, page up, page down, etc).  The solution was quite simple and elegant but not completely <a href='http://www.alunduil.com/2011/01/27/special-keys-in-zsh/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I recently made the plunge and began using zsh in lieu of bash.  I&#8217;ve not regretted the decision in the slightest but there have been minor annoyances that needed to be dealt with.  The simplest annoyance was the special keys (delete, home, page up, page down, etc).  The solution was quite simple and elegant but not completely obvious.</p>
<p>The bindings usually are read from the file `/etc/inputrc`by bash but zsh does not do this by default.  There are probably more elegant solutions but a quick brute force solution is to create a bindkeys file out of inputrc:</p>
<pre>gawk '$1 ~ /.*:/ { print "bindkey",$1,$2 }' /etc/inputrc | \
sed -e 's/://g' &gt; ~/.zshrc-bindkeys</pre>
<p>Once this file has been crafted it&#8217;s simply a matter of invoking it from your .zshrc with `source ~/.zshrc-bindkeys`.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/01/27/special-keys-in-zsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mailing Portage Output</title>
		<link>http://www.alunduil.com/2011/01/18/mailing-portage-output/</link>
		<comments>http://www.alunduil.com/2011/01/18/mailing-portage-output/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 23:49:06 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[emerge]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=282</guid>
		<description><![CDATA[Introduction Portage is an amazingly simple and complex piece of technology.  The simplicity in each piece&#8217;s ability to do a specific function comes together in a complex package management system that rivals all other forms of package management (at least in my opinion).  Automating updates is something that admins everywhere do out of necessity.  Heck, <a href='http://www.alunduil.com/2011/01/18/mailing-portage-output/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Portage is an amazingly simple and complex piece of technology.  The simplicity in each piece&#8217;s ability to do a specific function comes together in a complex package management system that rivals all other forms of package management (at least in my opinion).  Automating updates is something that admins everywhere do out of necessity.  Heck, automating everything is an admin&#8217;s life.  Automating portage&#8217;s updates is a bit more harrowing than other package management systems but it isn&#8217;t impossible.</p>
<h1>Problem</h1>
<p>As admins we attempt to simplify the work we actually do by writing scripts and programs to do most of our job for us.  It&#8217;s often been said that systems admins are the only people whose job description is to remove their job responsibilities.</p>
<p>Portage doesn&#8217;t have any default automation for doing nightly or even weekly portage updates but that doesn&#8217;t stop the creative from coming up with their own solution.  A simple but elegant solution is to create a small cron script that runs every day.  The problem comes when you want to read the wonderful output of portage (sometimes these messages can guide you when problems are about to occur) to avert disasters.  If the updates are performed from cron, the output will be preserved in an e-mail to the appropriate user but then we have to sift through all of the output at once.  This also doesn&#8217;t solve the issue if the updates are performed by another utility such as puppet.  These annoying little changes to the problem require a slightly more elegant solution.</p>
<h1>Solution</h1>
<p>The solution is to take advantage of portage&#8217;s logging specifications.  From the make.conf man file:</p>
<ul>
<li>﻿﻿PORTAGE_ELOG_CLASSES</li>
<li>PORTAGE_ELOG_SYSTEM</li>
<li>PORTAGE_ELOG_COMMAND</li>
<li>PORTAGE_ELOG_MAILURI</li>
<li>PORTAGE_ELOG_MAILFROM</li>
<li>PORTAGE_ELOG_MAILSUBJECT</li>
</ul>
<p>Using a combination of these directives in the make.conf file allows us to log the reports from portage to a large number of locations.  If we wanted to simply add mailing output (not the full build output just the messages) we would add the following directives to make.conf:</p>
<pre>PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILFROM="portage@alunduil.com"</pre>
<p>This simply adds the mailing log utility to portage and specifies that the e-mails come from the address portage@alunduil.com.  Of course, much more complex configurations can be crafted to suit any admins&#8217; needs.</p>
<h1>Conclusion</h1>
<p>Letting your servers notify you of possible actions is one way of automating maintenance tasks; making maintenance eventually disappear from your task list. By starting with the tasks that are repeated the most frequently, you can quickly free up time for higher level automation and organization which leads to a cleaner and sturdier infrastructure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/01/18/mailing-portage-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Small Interpreters Using Python</title>
		<link>http://www.alunduil.com/2010/12/15/small-interpreters-using-python/</link>
		<comments>http://www.alunduil.com/2010/12/15/small-interpreters-using-python/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 01:59:41 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bison]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[grammar]]></category>
		<category><![CDATA[lemon]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[pyparsing]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tiny basic]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=254</guid>
		<description><![CDATA[Introduction I know this doesn&#8217;t come up nearly as often as other topics but writing an interpreter (a.k.a. a compiler) can be a very useful concept depending on what exactly you need to do with the input to your program. For example, what if we had a fairly strict data store but we for some <a href='http://www.alunduil.com/2010/12/15/small-interpreters-using-python/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>I know this doesn&#8217;t come up nearly as often as other topics but writing an interpreter (a.k.a. a compiler) can be a very useful concept depending on what exactly you need to do with the input to your program.  For example, what if we had a fairly strict data store but we for some reason wanted to access it using something like SQL?  We&#8217;d have to parse the SQL statements and then find a way to mogrify it until we had something that would allow us to get the data we wanted.  There is an easier way involving a little parsing theory.  For the purposes of this discussion I&#8217;m assuming you are at least somewhat familiar with <a href="http://en.wikipedia.org/wiki/Context-free_grammar">Context Free Grammars</a>.</p>
<h1>Creating the Grammar</h1>
<p>The first step to creating a parser (especially when using a parser generator) is to find or craft a definition for the grammar.  The grammar we&#8217;ll use as an example is the expression grammar from tiny basic.  This simple grammar is safe for LR or LL parsing (which is important if you look at a common definition of a language like SQL).</p>
<h2>Tiny Basic Expression Grammar</h2>
<pre>expression ::= (+|-|ε) term ((+|-) term)*
term ::= factor ((*|/) factor)*
factor ::= number | (expression)</pre>
<h1>Enter pyparsing</h1>
<p>To create a very simple and extensible LL parser I&#8217;ve recently stumbled upon <a href="http://pyparsing.wikispaces.com/">pyparsing</a>.  This simple four production grammar expands to the following pyparsing implementation:</p>
<p>[sourcecode language="python" wraplines="false"]<br />
expr = Forward()<br />
factor = ( Word(nums) | Group(Suppress(&#8216;(&#8216;) + expr + Suppress(&#8216;)&#8217;)) )<br />
term = Group(factor + ZeroOrMore((Literal(&#8216;*&#8217;)|Literal(&#8216;/&#8217;)) + factor))<br />
expr &lt;&lt; Group(Optional(Literal(&#8216;-&#8217;)|Literal(&#8216;+&#8217;)) + term + ZeroOrMore((Literal(&#8216;-&#8217;)|Literal(&#8216;+&#8217;)) + term))<br />
[/sourcecode]</p>
<p>This allows us to turn sentences such as &#8216;<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">5+5*6/3-(47+56)*34</span>&#8216; into an easy to work with list such as: &#8216;<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">[[['5'], &#8216;+&#8217;, ['5', '*', '6', '/', '3'], &#8216;-&#8217;, [[[['47'], &#8216;+&#8217;, ['56']]], &#8216;*&#8217;, &#8217;34&#8242;]]]</span>&#8216;.  There are probably improvements that could be made to this parser so that it auto-collapses expressions and other fun handlers but for the purposes of a simple grammar this will suffice.</p>
<p>Calling the grammar after defining it is a very simple process: <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">`expr.parseString(&#8217;5+5*6/3-(47+56)*34&#8242;)`</span>.</p>
<h1>Testing Parsers an Easier Way</h1>
<p>Sure unit testing should be done (and parsers lend themselves to unit tests very well) but there&#8217;s something satisfying about seeing your sentences get parsed out in real time.  The obvious answer is, &#8220;create a mini-shell like environment.&#8221;  Python also makes this process extremely simple and only requires a few lines of code to get a basically functional shell for your parser (complete with history):</p>
<p>[sourcecode language="python" wraplines="false"]<br />
import rlcompleter<br />
import readline<br />
import so</p>
<p>if not os.access(&quot;.history&quot;, os.F_OK): open(&quot;.history&quot;, &quot;w&quot;).close()<br />
readline.read_history_file(&quot;.history&quot;)<br />
buffer = &quot;&quot;</p>
<p>while True:<br />
    try: line = raw_input(pycolorize.light_blue(&quot;BASIC$ &quot;))<br />
    except EOFError:<br />
        readline.write_history_file(&quot;.history&quot;)<br />
        print<br />
        break</p>
<p>    if line.lower() == &quot;exit&quot; or line.lower() == &quot;quit&quot;:<br />
        readline.write_history_file(&quot;.history&quot;)<br />
        break</p>
<p>    buffer += line<br />
    result = ACTION_ON_BUFFER<br />
    buffer = &quot;&quot;<br />
[/sourcecode]</p>
<h1>Putting It Together</h1>
<p>The complete script for reference purposes:</p>
<p>[sourcecode language="python" wraplines="false"]<br />
import rlcompleter<br />
import readline<br />
import os</p>
<p>from pyparsing import *<br />
import pprint</p>
<p>if not os.access(&quot;.history&quot;, os.F_OK): open(&quot;.history&quot;, &quot;w&quot;).close()<br />
readline.read_history_file(&quot;.history&quot;)</p>
<p>try:<br />
    import pycolorize<br />
except:<br />
    sys.path.append(os.path.join(os.path.dirname(__file__), &quot;vendor&quot;, &quot;pycolorize&quot;))<br />
    import pycolorize</p>
<p>class ExpressionParser(object):<br />
    def __init__(self):<br />
    self._expr = Forward()<br />
    factor = ( Word(nums) | Group(Suppress(&#8216;(&#8216;) + self._expr + Suppress(&#8216;)&#8217;)) )<br />
    term = Group(factor + ZeroOrMore((Literal(&#8216;*&#8217;)|Literal(&#8216;/&#8217;)) + factor))<br />
    self._expr &lt;&lt; Group(Optional(Literal(&#8216;-&#8217;)|Literal(&#8216;+&#8217;)) + term + ZeroOrMore((Literal(&#8216;-&#8217;)|Literal(&#8216;+&#8217;)) + term))</p>
<p>    def _calculate(self, l):<br />
        while any([ isinstance(x, list) for x in l]):<br />
            for n,i in enumerate(l):<br />
                if isinstance(i, list): l[n] = self._calculate(i)<br />
        return str(eval(&quot; &quot;.join(l)))</p>
<p>    def __call__(self, string):<br />
        return self._calculate(self._expr.parseString(string).asList())</p>
<p>buffer = &quot;&quot;</p>
<p>print pycolorize.green(&quot;Enter your SQL commands to tokenize:&quot;)<br />
print pycolorize.green(&quot;Enter a blank line to exit.&quot;)</p>
<p>while True:<br />
    try: line = raw_input(pycolorize.light_blue(&quot;BASIC$ &quot;))<br />
    except EOFError:<br />
        readline.write_history_file(&quot;.history&quot;)<br />
        print<br />
        break</p>
<p>    if line.lower() == &quot;exit&quot; or line.lower() == &quot;quit&quot;:<br />
        readline.write_history_file(&quot;.history&quot;)<br />
        break</p>
<p>    buffer += line<br />
    result = None<br />
    try: result = ExpressionParser()(buffer)<br />
    except ParseBaseException, e:<br />
        buffer = &quot;&quot;<br />
        pycolorize.error(e.line)<br />
        pycolorize.error(&quot; &quot;*(e.col &#8211; 1) + &quot;^&quot;)<br />
        pycolorize.error(str(e))<br />
        continue<br />
    pycolorize.status(&quot;Result: %s&quot;, result)<br />
    buffer = &quot;&quot;<br />
[/sourcecode]</p>
<h1>Conclusion</h1>
<p>Writing LL parsers is a breeze with pyparsing but it must be kept in mind that any grammar that has any left recursion will cause errors that may take some time to find or remove.  Other parser generators (for C and C++) include bison and lemon.  These parser generators are LR parser generators.</p>
<p>By coupling the parser with a small CLI quick checks on new features to the grammar (and by extension the parser) can be a breeze.  Putting this all together with unit tests and proper grammar analysis can lead to a well written and extensible language to be used for whatever purpose you may have in mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/12/15/small-interpreters-using-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached (User agent is rejected)
Database Caching 1/3 queries in 0.006 seconds using memcached
Object Caching 687/687 objects using memcached

Served from: www.alunduil.com @ 2012-02-06 08:36:04 -->
