<?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>Josh Duff</title>
	<atom:link href="http://joshduff.com/feed" rel="self" type="application/rss+xml" />
	<link>http://joshduff.com</link>
	<description>A guy with a web site</description>
	<lastBuildDate>Sat, 21 Aug 2010 22:28:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>On Growing as a Programmer (I think)</title>
		<link>http://joshduff.com/248/on-growing-as-a-programmer-i-think</link>
		<comments>http://joshduff.com/248/on-growing-as-a-programmer-i-think#comments</comments>
		<pubDate>Sat, 21 Aug 2010 22:28:04 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=248</guid>
		<description><![CDATA[I keep hoping that some day, I will look back at code I wrote over a year prior without once thinking &#034;man, I was young and stupid back then&#034;. That day has not arrived yet. Perhaps I should be consoled by the fact that the reason I&#039;m looking at these prior works now isn&#039;t because [...]]]></description>
			<content:encoded><![CDATA[<p>I keep hoping that some day, I will look back at code I wrote over a year prior without once thinking &#034;man, I was young and stupid back then&#034;.  That day has not arrived yet.</p>
<p>Perhaps I should be consoled by the fact that the reason I&#039;m looking at these prior works now isn&#039;t because they broke in front of a customer.  This time, at least.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/248/on-growing-as-a-programmer-i-think/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL wrapper class (PHP)</title>
		<link>http://joshduff.com/232/mysql-wrapper-class-php</link>
		<comments>http://joshduff.com/232/mysql-wrapper-class-php#comments</comments>
		<pubDate>Mon, 26 Jul 2010 23:07:46 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=232</guid>
		<description><![CDATA[I&#039;m not saying that this is the best implementation of a MySQL wrapper class for PHP. I&#039;m not advocating its use in production code. However, this is what I&#039;ve used in most scripts I&#039;ve thrown together in the last few years &#8211; I hate having to throw a mysql_error call after every query, y&#039;know? &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;m not saying that this is the best implementation of a MySQL wrapper class for PHP.  I&#039;m not advocating its use in production code.</p>
<p>However, this is what I&#039;ve used in most scripts I&#039;ve thrown together in the last few years &#8211; I hate having to throw a mysql_error call after every query, y&#039;know?</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CLIENT_LONG_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MySQLWrapper
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$server_port</span>	<span style="color: #339933;">=</span>		<span style="color: #0000ff;">'localhost:3306'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$database</span> 		<span style="color: #339933;">=</span>		<span style="color: #0000ff;">'whatever'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$username</span> 		<span style="color: #339933;">=</span>		<span style="color: #0000ff;">'a username'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$password</span> 		<span style="color: #339933;">=</span>		<span style="color: #0000ff;">'a password'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$force_long_password</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$db_object</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$server_port</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$database</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$force_long_password</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server_port</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$server_port</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$database</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">force_long_password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$force_long_password</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server_port</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> Connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_object</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mysql_ping</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_object</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$db_object</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server_port</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">force_long_password</span> ? CLIENT_LONG_PASSWORD <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Select database failed for <span style="color: #006699; font-weight: bold;">$this-&gt;database</span>: <span style="color: #006699; font-weight: bold;">$result</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> Disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_object</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> Execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Query failed: <span style="color: #006699; font-weight: bold;">$result</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Teh query itself: <span style="color: #006699; font-weight: bold;">$query</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You may find this slightly better than using PHP&#039;s MySQL functions straight out of the box.  Or not.  Who can say?</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/232/mysql-wrapper-class-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>This program has no useful purpose, so I posted it on my blog</title>
		<link>http://joshduff.com/235/this-program-has-no-useful-purpose-so-i-posted-it-on-my-blog</link>
		<comments>http://joshduff.com/235/this-program-has-no-useful-purpose-so-i-posted-it-on-my-blog#comments</comments>
		<pubDate>Mon, 26 Jul 2010 23:06:56 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=235</guid>
		<description><![CDATA[Look, this is just dumb. I don&#039;t even know why I felt like writing this. This script will keep a certain percentage of the tables in your MySQL database locked. It will lock the first N% of your database, and then move forward one table at a time, locking the next table in line and [...]]]></description>
			<content:encoded><![CDATA[<p>Look, this is just dumb.</p>
<p>I don&#039;t even know why I felt like writing this.</p>
<p>This script will keep a certain percentage of the tables in your MySQL database locked.  It will lock the first N% of your database, and then move forward one table at a time, locking the next table in line and releasing the lock on the one at the end of the tail.</p>
<p>Why would someone use this script?  For benchmarking some completely unrealistic scenario?  To decrease database efficiency for no good reason?  Who can say.</p>
<p>Note: you&#039;ll get to lock/release tables a lot more quickly if you run this script locally.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$percentage_of_database_to_lock</span> <span style="color: #339933;">=</span> <span style="color:#800080;">.25</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./shared/mysql.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mysql</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MySQLWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server_port</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'host:3306'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'some_db'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'some_user'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'some_pass'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mysql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Execute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SHOW TABLES'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tables</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tables</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$tables_to_lock</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$percentage_of_database_to_lock</span> <span style="color: #339933;">*</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables_to_lock</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$cycles</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$start_at</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'LOCK TABLE'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tables_so_far</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables_so_far</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$tables_to_lock</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$next_index</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start_at</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$tables_so_far</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$next_index</span> <span style="color: #339933;">&gt;=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$next_index</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$next_index</span> <span style="color: #339933;">-</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #000088;">$query</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'`'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$tables</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$next_index</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'` WRITE, '</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$tables_so_far</span><span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$mysql</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Execute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$start_at</span><span style="color: #339933;">++;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_at</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$start_at</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Cycle &quot;</span> <span style="color: #339933;">.</span> <span style="color: #339933;">++</span><span style="color: #000088;">$cycles</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Dependencies: <a href="http://joshduff.com/232">MySQLWrapper</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/235/this-program-has-no-useful-purpose-so-i-posted-it-on-my-blog/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Profanities and other funny words</title>
		<link>http://joshduff.com/203/profanities-and-other-funny-words</link>
		<comments>http://joshduff.com/203/profanities-and-other-funny-words#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:11:49 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=203</guid>
		<description><![CDATA[I recently did a quick audit of the source code I help maintain/develop for the company I work for.  By which I mean, I spent the last part of a Friday searching through our code for funny words. I decided to open up by looking for traditional profanities &#8211; a commonly-accepted method of gauging the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently did a quick audit of the source code I help maintain/develop for <a href="http://wikido.isoftdata.com/index.php/ISoft_Data_Systems">the company I work for</a>.  By which I mean, I spent the last part of a Friday searching through our code for funny words.</p>
<p>I decided to open up by looking for traditional profanities &#8211; a commonly-accepted method of gauging the state of a project (see: <a href="http://www.vidarholen.net/contents/wordcount/">profanities in the Linux kernel, graphed over time</a> and <a href="http://www.kuro5hin.org/story/2004/2/15/71552/7795">a quick look at the Win2k source</a>).</p>
<p>Below, I provide a list of my findings, with a few examples.  Enjoy a look at the source code of a functioning product with many users!</p>
<p><em>Disclaimer: if any of the words that you are about to read will offend you, then don&#039;t read them.</em></p>
<h1>The classics</h1>
<p>I started off by looking for looking for the current English classics:</p>
<p><strong>Fuck</strong>: 6 times.<br />
Example:</p>
<pre>// If they had any unsaved changes, they're pretty much fucked, because
// this customer has apparently been modified by another screen.</pre>
<p><strong>Shit</strong>: 10</p>
<pre>// For now, I believe that all the data is updated on the fly, so saving first is not
// necessary, but maybe we should just for shits and giggles</pre>
<p><strong>Crap</strong>: 22<br />
The expletive for the more vocabulary-sensitive programmer!</p>
<pre>//!!! It was late, we were tired, so I hacked this crap together !!!</pre>
<p><!-- wut --></p>
<pre>// What the crap does this button do? - I disabled it because I think that this button
// is misleading and confusing</pre>
<p><strong>Hell</strong>: 1</p>
<pre>// If it wasn't any of the valid options, then get the hell out</pre>
<h1>Insults</h1>
<p>It&#039;s usually another programmer&#039;s fault.</p>
<p><strong>Stupid</strong>: 75<br />
The code is stupid, the users are stupid, other developers are stupid.  According to the comments, at least.</p>
<pre>// Clear out year if it is a stupid number</pre>
<p><!-- wut --></p>
<pre>// Here we tell the user they are stupid when they do stupid things
// If the user forgets to specify a table, gently remind them that it's a good idea,
// then return</pre>
<p><!-- wut --></p>
<pre>// When you minimize, it tells you you're size 0 now.  That seems stupid, ignore it</pre>
<p><!-- wut --></p>
<pre>// Die, stupid message boxes</pre>
<p><!-- wut --></p>
<pre>TRACE("Stupid quickbooks.\n");</pre>
<p><!-- wut --></p>
<pre>IQBBasePtr stupid = response-&gt;GetDetail();
TRACE("Response Type: %d\n", (int)stupid-&gt;Type-&gt;GetValue());
InterpretResponse(stupid);</pre>
<p><!-- wut --></p>
<pre>// Thigs are different (stupid) without this flag.  I don't currently support its omission</pre>
<p><strong>Dumb</strong>: 17</p>
<pre>// There was some seriously wacky code here earlier including a really dumb memory leak.
// I tested my changes and they seem to work fine, nevertheless, I wasn't able
// to fully understand what this code was attempting to do so I may have missed
// some obscure feature.</pre>
<p><strong>Retarded</strong>: 4</p>
<pre>// Because CStrings are retarded and don't do well with binary data, we have to copy the
// data in to the query in a rather inconvenient manner.</pre>
<p><strong>Idiot</strong>: 2</p>
<pre>// Else politely inform the user that they are an idiot</pre>
<p><strong>Hack</strong>: 6</p>
<pre>// Look at the first part of the label to find the operation (this is a sort of
// dirty hack so that) we don't have to change the database.</pre>
<h1>Incredulity</h1>
<p>Really?</p>
<p><strong>Why</strong>: 84<br />
The only word with a higher count than &#034;stupid&#034; &#8211; there is always more for a programmer to learn.  Or speculate on.  Or rage at.</p>
<pre>//!!! For some reason ODBC crashes at this point if you've already done a query !!!
//!!! I can't really figure out why !!!</pre>
<p><!-- wut --></p>
<pre>// Not sure why we would want to do bitwise operations...</pre>
<p><!-- wut --></p>
<pre>// WHy doesn't this exist?</pre>
<p><!-- wut --></p>
<pre>// I don't see why we'd do this</pre>
<p><!-- wut --></p>
<pre>// CRH asks: Why do we use Format() instead of "="? Can't we assume that it's slower?
// JDD Answers: what Formats?  What are you talking about?  You crazy, Charles!</pre>
<p><!-- wut --></p>
<pre>// Removed 2006.02.17 - This makes it so that negative balances show up positive.
// I am not sure sure why it was ever here.</pre>
<p><!-- wut --></p>
<pre>// This doesn't seem to work.  I'm not sure why</pre>
<p><strong>wtf</strong>: 25<br />
Often heard expressed verbally by developers reading code.</p>
<pre>catch (...)
{
	TRACE("Seriously, wtf\n");
	// sic vita est
}</pre>
<p><!-- wut --></p>
<pre>// Sort the incoming files alphabetically (windows sometimes reverses the order (wtf?)</pre>
<h1>Random</h1>
<p><strong>Ridiculous</strong>: 2<br />
When three syllables just isn&#039;t enough.</p>
<pre>// Make the quantity not have ridiculous decimal places</pre>
<p><strong>Pants</strong>: 3<br />
That&#039;s right, and all 3 times inside of a static string, too!</p>
<pre>strPCProductCode = GetInitSetting(__MASTERWND, "session", "productcode", "pants");</pre>
<p>That fourth argument is the default value, returned if there is no existing setting with that name.  So&#8230; yeah.</p>
<p><strong>lol</strong>: 3</p>
<pre>// lol xor
if ((bPaid || bUnpaid) &amp;&amp; !(bPaid &amp;&amp; bUnpaid))</pre>
<p><strong>lulz</strong>: 1</p>
<pre>// Half implemented, lulz</pre>
<h1>A few other gems</h1>
<p>Ebonics?</p>
<pre>// If shift was already depressed, fo' real, don't screw that up</pre>
<p>Obvious mental deterioration:</p>
<pre>// A grape typed this line in:
//9</pre>
<p>And&#8230; uh&#8230; this was at the bottom of a header file&#8230;</p>
<pre>// Standardized code makes him happy!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                        ;;
;;        ;;;;;;;;        ;;
;;       ;;      ;;       ;;
;;      ;; ;;  ;; ;;      ;;
;;      ;;        ;;      ;;
;;      ;;    ;   ;;      ;;
;;      ;;        ;;      ;;
;;      ;; ;;;;;; ;;      ;;
;;       ;;  ;;  ;;       ;;
;;        ;;;;;;;;        ;;
;;                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

// Non-Standardized code makes him sad!
// And keeps him up all night, screaming
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                        ;;
;;        ;;;;;;;;        ;;
;;       ;;;    ;;;       ;;
;;      ;; /*\/*\ ;;      ;;
;;      ;; \_/\_/ ;;      ;;
;;      ;;   ^^   ;;      ;;
;;      ;; /****\ ;;      ;;
;;      ;; \****/ ;;      ;;
;;       ;;      ;;       ;;
;;        ;;;;;;;;        ;;
;;                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;</pre>
<p>8-|</p>
<h1>So, yeah&#8230;</h1>
<p>Found any entertaining metadata in code?  Link me!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/203/profanities-and-other-funny-words/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sandwich war crimes: the Dirty Mother</title>
		<link>http://joshduff.com/200/dirty-mother</link>
		<comments>http://joshduff.com/200/dirty-mother#comments</comments>
		<pubDate>Mon, 24 May 2010 08:57:31 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Personal stupidity]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=200</guid>
		<description><![CDATA[For those attending a university, the end of a semester is a time of much rejoicing.  During my last semesters at such an institution, I took place in an end-of-year celebratory tradition involving a ridiculous sandwich. In some issue of Maxim (November 2005?) there was an article featuring absurd sandwich-based foods.  So ridiculous were these [...]]]></description>
			<content:encoded><![CDATA[<p>For those attending a university, the end of a semester is a time of much rejoicing.  During my last semesters at such an institution, I took place in an end-of-year celebratory tradition involving a ridiculous sandwich.</p>
<p>In some issue of Maxim (November 2005?) there was an article featuring absurd sandwich-based foods.  So ridiculous were these edibles that some fraternity brothers of mine decided that the consumption of one such sandwich would make a fitting end-of-semester celebration.</p>
<p>I was unable to find the original article online, but found the ingredients <a href="http://www.ntxalliance.com/index.php?action=printpage;topic=3970.0">here</a>.  I post them here for posterity.</p>
<h2>The Dirty Mother</h2>
<blockquote><p>&#034;Use two slices of buttery Texas toast as bookends, and slap together a sausage patty, hash browns, and three generous chops of ham, separating each layer with a slice of cheddar cheese. Throw two fried eggs in the mix, and comfort them with four strips of crispy bacon. A splash of ketchup or Worcestershire sauce is your choice, but tons of S&amp;P is mandatory.&#034;</p></blockquote>
<p>We would usually go to IHOP, order the ingredients individually, and assemble the sandwiches ourselves.  The braver souls in the group would purchase fries as a side dish.</p>
<p>These memories are making me hungry.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/200/dirty-mother/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Run a query for every table in a database</title>
		<link>http://joshduff.com/189/run-a-query-for-every-table-in-a-database</link>
		<comments>http://joshduff.com/189/run-a-query-for-every-table-in-a-database#comments</comments>
		<pubDate>Wed, 17 Feb 2010 20:16:12 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=189</guid>
		<description><![CDATA[Ever wished you could run a dangerous query like DROP TABLE or TRUNCATE against every table in a database in a single query? No? Well, how about something like CHECK or REPAIR table, then? If you ever find yourself in the rare situation where you need to run the same query across every table in [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wished you could run a dangerous query like DROP TABLE or TRUNCATE against every table in a database in a single query?</p>
<p>No?</p>
<p>Well, how about something like CHECK or REPAIR table, then?</p>
<p>If you ever find yourself in the rare situation where you need to run the same query across every table in a database, this procedure might make your life easier:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`p<span style="color: #008080; font-weight: bold;">_</span>run<span style="color: #008080; font-weight: bold;">_</span>for<span style="color: #008080; font-weight: bold;">_</span>each<span style="color: #008080; font-weight: bold;">_</span>table`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">IN</span> strDatabase <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">IN</span> strOperation <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #FF00FF;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">DETERMINISTIC</span>
<span style="color: #990099; font-weight: bold;">BEGIN</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> strQuery <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> strTable <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> bDone <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #008080;">0</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> TableCursor CURSOR FOR
		<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">`TABLE<span style="color: #008080; font-weight: bold;">_</span>NAME`</span>
		<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`information<span style="color: #008080; font-weight: bold;">_</span>schema`</span>.<span style="color: #008000;">`TABLES`</span>
		<span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`TABLE<span style="color: #008080; font-weight: bold;">_</span>SCHEMA`</span> <span style="color: #CC0099;">=</span> strDatabase <span style="color: #CC0099; font-weight: bold;">AND</span> TABLE_TYPE <span style="color: #CC0099;">=</span> <span style="color: #008000;">'BASE TABLE'</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> CONTINUE <span style="color: #990099; font-weight: bold;">HANDLER</span> FOR <span style="color: #CC0099; font-weight: bold;">NOT</span> FOUND <span style="color: #990099; font-weight: bold;">SET</span> bDone <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span>
&nbsp;
	OPEN TableCursor<span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #000099;">REPEAT</span>
		FETCH TableCursor <span style="color: #990099; font-weight: bold;">INTO</span> strTable<span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #990099; font-weight: bold;">SET</span> @QueryThatWasPassedIn <span style="color: #CC0099;">:=</span> <span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">&#40;</span>
			<span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">&#40;</span>strOperation<span style="color: #000033;">,</span> <span style="color: #008000;">'{?database}'</span><span style="color: #000033;">,</span> strDatabase<span style="color: #FF00FF;">&#41;</span>
			<span style="color: #000033;">,</span> <span style="color: #008000;">'{?table}'</span><span style="color: #000033;">,</span> strTable<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
		PREPARE Statement <span style="color: #990099; font-weight: bold;">FROM</span> @QueryThatWasPassedIn<span style="color: #000033;">;</span>
		EXECUTE Statement<span style="color: #000033;">;</span>
	UNTIL bDone <span style="color: #009900;">END</span> <span style="color: #000099;">REPEAT</span><span style="color: #000033;">;</span>
&nbsp;
	CLOSE TableCursor<span style="color: #000033;">;</span>
	DEALLOCATE PREPARE Statement<span style="color: #000033;">;</span>
<span style="color: #009900;">END</span>$$
DELIMITER <span style="color: #000033;">;</span></pre></div></div>

<h1>Useage</h1>
<p>The procedure takes two parameters.  The first one is the name of the database whose tables you want to run the query for.</p>
<p>The second is the query you would like to run.  The strings &#034;{?database}&#034; and &#034;{?table}&#034; will be replaced with the database and table names.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> p_run_for_each_table<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'databasename'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'SELECT * FROM {?database}.{?table}'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<h1>What queries you can run</h1>
<p>You should be able to use any queries that can be run in a prepared statement &#8211; you can find the list about two-thirds of the way down <a href="http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html">this page</a>.</p>
<p>As of MySQL 5.1, you can run these queries: &#034;ALTER TABLE, CALL, COMMIT, CREATE INDEX, CREATE TABLE, DELETE, DO, DROP INDEX, DROP TABLE, INSERT, RENAME TABLE, REPLACE, SELECT, SET, UPDATE, and most SHOW statements.&#034;</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/189/run-a-query-for-every-table-in-a-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logical errors in queries: DO NOT WANT</title>
		<link>http://joshduff.com/173/logical-errors-in-queries-do-not-want</link>
		<comments>http://joshduff.com/173/logical-errors-in-queries-do-not-want#comments</comments>
		<pubDate>Wed, 03 Feb 2010 03:17:58 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=173</guid>
		<description><![CDATA[During my career developing database-driven software (teehee, I&#039;m a professional) I&#039;ve noted that the most horrific query errors are the logical ones &#8211; queries that parse correctly, and return reasonable-looking data, but make wrong assumptions about how different parts of the query relate to each other. One particular error that I&#039;ve seen time and time [...]]]></description>
			<content:encoded><![CDATA[<p>During my career developing database-driven software (teehee, I&#039;m a professional) I&#039;ve noted that the most horrific query errors are the logical ones &#8211; queries that parse correctly, and return reasonable-looking data, but make wrong assumptions about how different parts of the query relate to each other.</p>
<p>One particular error that I&#039;ve seen time and time again (even from people who have been writing queries for a while) can occur when summarizing data from multiple tables that have a one-to-many relationship.</p>
<p>&#8230;In other words, it could occur in queries written for most database-driven software.</p>
<h2>Solution: fix the problem by writing about it!</h2>
<p>I wrote <a href="http://wikido.isoftdata.com/index.php/The_GROUPing_pitfall">a page documenting</a> the cause of the logical error, doing my best to warn people against letting it slip into their own code.</p>
<p>I attempted to write it so it would be easy to read, possibly even entertaining (a lofty goal for a manual on writing database queries, perhaps) &#8211; there is some colorful language and plenty of juvenile humor mixed with the tech-speak.</p>
<p>The doc itself is part of the wiki of the company where I work.  I don&#039;t write a ton of documentation for our developers or customers (certainly not as much as I should), but whenever I do, I get this awesome feeling of usefulness.  Oh, and pride.  Sometimes, I feel so proud, that I feel compelled to link other people (who have no relationship to my company) to what I wrote!  Ridiculous, I know.</p>
<p>Remember: if you write queries, it is your responsibility to guarantee that they return true and accurate data!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/173/logical-errors-in-queries-do-not-want/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert blocks of text to sentence case</title>
		<link>http://joshduff.com/156/convert-blocks-of-text-to-sentence-case</link>
		<comments>http://joshduff.com/156/convert-blocks-of-text-to-sentence-case#comments</comments>
		<pubDate>Thu, 21 Jan 2010 01:31:28 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=156</guid>
		<description><![CDATA[You know what I hate? Paragraphs of capital (or all lowercase) letters. The other day a coworker was looking to beautify a large quantity of data spread across some MySQL tables.  I created this function to make his life easier: DELIMITER $$ CREATE FUNCTION `f_sentence_case`&#40;strInput TEXT, nMinimumLength INT&#41; RETURNS TEXT DETERMINISTIC BEGIN &#160; DECLARE result [...]]]></description>
			<content:encoded><![CDATA[<p>You know what I hate?  Paragraphs of capital (or all lowercase) letters.</p>
<p>The other day a coworker was looking to beautify a large quantity of data spread across some MySQL tables.  I created this function to make his life easier:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">FUNCTION</span> <span style="color: #008000;">`f<span style="color: #008080; font-weight: bold;">_</span>sentence<span style="color: #008080; font-weight: bold;">_</span>case`</span><span style="color: #FF00FF;">&#40;</span>strInput <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #000033;">,</span> nMinimumLength <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">RETURNS</span> <span style="color: #999900; font-weight: bold;">TEXT</span>
<span style="color: #990099; font-weight: bold;">DETERMINISTIC</span>
<span style="color: #990099; font-weight: bold;">BEGIN</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">DECLARE</span> result <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> LastSpace <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> NextSpace <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> NextSlash <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> Word <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> NewSentence <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> PreviousCharacter <span style="color: #000099;">CHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> TrimmedWord <span style="color: #999900; font-weight: bold;">TEXT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> NumberOfSpaces <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> Swap <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">SET</span> strInput <span style="color: #CC0099;">:=</span> <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span>strInput<span style="color: #000033;">,</span> <span style="color: #008000;">' '</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">SET</span> result <span style="color: #CC0099;">:=</span> <span style="color: #008000;">''</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">SET</span> LastSpace <span style="color: #CC0099;">:=</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">SET</span> NextSpace <span style="color: #CC0099;">:=</span> <span style="color: #000099;">LOCATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">' '</span><span style="color: #000033;">,</span> strInput<span style="color: #000033;">,</span> LastSpace <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">SET</span> NextSlash <span style="color: #CC0099;">:=</span> <span style="color: #000099;">LOCATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'/'</span><span style="color: #000033;">,</span> strInput<span style="color: #000033;">,</span> LastSpace <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">SET</span> NextSpace <span style="color: #CC0099;">:=</span> <span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">LEAST</span><span style="color: #FF00FF;">&#40;</span>NextSlash<span style="color: #000033;">,</span> NextSpace<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span><span style="color: #000033;">,</span> <span style="color: #000099;">GREATEST</span><span style="color: #FF00FF;">&#40;</span>NextSlash<span style="color: #000033;">,</span> NextSpace<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #000099;">LEAST</span><span style="color: #FF00FF;">&#40;</span>NextSlash<span style="color: #000033;">,</span> NextSpace<span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
	label1: WHILE NextSpace <span style="color: #990099; font-weight: bold;">DO</span>
&nbsp;
		<span style="color: #990099; font-weight: bold;">SET</span> Word <span style="color: #CC0099;">:=</span> SUBSTR<span style="color: #FF00FF;">&#40;</span>strInput<span style="color: #000033;">,</span> LastSpace<span style="color: #000033;">,</span> NextSpace <span style="color: #CC0099;">-</span> LastSpace<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> PreviousCharacter <span style="color: #CC0099;">:=</span> SUBSTR<span style="color: #FF00FF;">&#40;</span>strInput<span style="color: #000033;">,</span> LastSpace <span style="color: #CC0099;">-</span> <span style="color: #008080;">1</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> NewSentence <span style="color: #CC0099;">:=</span> LastSpace <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span> <span style="color: #CC0099; font-weight: bold;">OR</span> <span style="color: #FF00FF;">&#40;</span>NewSentence <span style="color: #CC0099; font-weight: bold;">AND</span> PreviousCharacter <span style="color: #CC0099;">=</span> <span style="color: #008000;">' '</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">OR</span> PreviousCharacter <span style="color: #000099;">IN</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'.'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'!'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'?'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #990099; font-weight: bold;">SET</span> TrimmedWord <span style="color: #CC0099;">:=</span> <span style="color: #000099;">LTRIM</span><span style="color: #FF00FF;">&#40;</span>Word<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> NumberOfSpaces <span style="color: #CC0099;">:=</span> <span style="color: #000099;">LENGTH</span><span style="color: #FF00FF;">&#40;</span>Word<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">-</span> <span style="color: #000099;">LENGTH</span><span style="color: #FF00FF;">&#40;</span>TrimmedWord<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> Word <span style="color: #CC0099;">:=</span> TrimmedWord<span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># Make it lowercase if it is all uppercase</span>
		<span style="color: #990099; font-weight: bold;">SET</span> Word <span style="color: #CC0099;">:=</span> <span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">LENGTH</span><span style="color: #FF00FF;">&#40;</span>Word<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">&gt;=</span> nMinimumLength <span style="color: #CC0099; font-weight: bold;">AND</span> Word <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #CC0099; font-weight: bold;">REGEXP</span> <span style="color: #008000;">'[0-9]'</span><span style="color: #000033;">,</span> 
			<span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span>NewSentence<span style="color: #000033;">,</span>
				<span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">UCASE</span><span style="color: #FF00FF;">&#40;</span>SUBSTR<span style="color: #FF00FF;">&#40;</span>Word<span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #000099;">LCASE</span><span style="color: #FF00FF;">&#40;</span>SUBSTR<span style="color: #FF00FF;">&#40;</span>Word<span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #000033;">,</span> <span style="color: #000099;">LENGTH</span><span style="color: #FF00FF;">&#40;</span>Word<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">-</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
				<span style="color: #000099;">LCASE</span><span style="color: #FF00FF;">&#40;</span>Word<span style="color: #FF00FF;">&#41;</span>
			<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> 
			Word<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #990099; font-weight: bold;">SET</span> result <span style="color: #CC0099;">:=</span> <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span>result<span style="color: #000033;">,</span> <span style="color: #000099;">REPEAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">' '</span><span style="color: #000033;">,</span> NumberOfSpaces<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> Word<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #990099; font-weight: bold;">SET</span> Swap <span style="color: #CC0099;">:=</span> LastSpace<span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> LastSpace <span style="color: #CC0099;">:=</span> NextSpace<span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> NextSpace <span style="color: #CC0099;">:=</span> <span style="color: #000099;">LOCATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">' '</span><span style="color: #000033;">,</span> strInput<span style="color: #000033;">,</span> Swap <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> NextSlash <span style="color: #CC0099;">:=</span> <span style="color: #000099;">LOCATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'/'</span><span style="color: #000033;">,</span> strInput<span style="color: #000033;">,</span> Swap <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
		<span style="color: #990099; font-weight: bold;">SET</span> NextSpace <span style="color: #CC0099;">:=</span> <span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">LEAST</span><span style="color: #FF00FF;">&#40;</span>NextSlash<span style="color: #000033;">,</span> NextSpace<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span><span style="color: #000033;">,</span> <span style="color: #000099;">GREATEST</span><span style="color: #FF00FF;">&#40;</span>NextSlash<span style="color: #000033;">,</span> NextSpace<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #000099;">LEAST</span><span style="color: #FF00FF;">&#40;</span>NextSlash<span style="color: #000033;">,</span> NextSpace<span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #009900;">END</span> WHILE label1<span style="color: #000033;">;</span>
&nbsp;
RETURN result<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">END</span>$$
DELIMITER <span style="color: #000033;">;</span></pre></div></div>

<h1>What it does</h1>
<p>It seems to perform generally as I hoped it would; which is to say that it formats text to be sentence case.</p>
<p>More specifically, it alters all the &#034;words&#034; (a set of non-numeric, non-whitespace characters) that are longer than the specified minimum length.</p>
<p>It changes the words to be all lowercase, unless they happen to be the first word after a punctuation mark (in which case the first character of the word is made uppercase).</p>
<h1>Useage</h1>
<p>To clean up a field so that it is formatted in sentence case (ignoring all words with less than 3 characters), simply run this query:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #008000;">`table`</span> <span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #008000;">`field`</span> <span style="color: #CC0099;">=</span> f_sentence_case<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`field`</span><span style="color: #000033;">,</span> <span style="color: #008080;">3</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>Other than that, my only specs for the query were for it to be functional and hopefully not break my brain when I went back to read it later.  If anyone has any significant improvements to it, let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/156/convert-blocks-of-text-to-sentence-case/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running my first campaign!</title>
		<link>http://joshduff.com/145/running-my-first-campaign</link>
		<comments>http://joshduff.com/145/running-my-first-campaign#comments</comments>
		<pubDate>Thu, 14 Jan 2010 15:41:37 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Geekery]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=145</guid>
		<description><![CDATA[Less than a year ago, I jumped off the high-board of nerdiness into the deep end of the role-playing pool &#8211; and ran my very first campaign. I wanted a fun campaign (duh) with rules and story that would be hard for me to mess up.  For most of the campaign, the only players were [...]]]></description>
			<content:encoded><![CDATA[<p>Less than a year ago, I jumped off the high-board of nerdiness into the deep end of the role-playing pool &#8211; and ran my very first campaign.</p>
<p>I wanted a fun campaign (duh) with rules and story that would be hard for me to mess up.  For most of the campaign, the only players were two good friends with solid role-playing experience, so I was able to rely on the players to contribute a good amount of quality.</p>
<h1>The story</h1>
<p>I took a stab at running an old-west campaign, borrowing every western-movie trope I could think of.  The PCs played <a href="http://tvtropes.org/pmwiki/pmwiki.php/Main/TheGunslinger">gunslinging</a> lawmen for hire, riding into a town oppressed by a gang of n&#039;er-do-wells populated with plenty of tobacco-spitting, expendable, no-good <a href="http://tvtropes.org/pmwiki/pmwiki.php/Main/Outlaw">outlaws</a> to gun down.</p>
<p>Without going into too much detail: the players cleaned out a counterfeiting operation in an old widow&#039;s basement, were recruited to clean up the town, used aggressive negotiations to get rid of gang members harassing the mayor&#039;s house, and stopped another group of enforcers who were coercing money from some water-starved farmers.</p>
<p>Back in town, they took over the town prison, had a gun fight in a booby-trapped house, escaped just as it blew sky high, confronted the aristocratic gang leader on the porch of his ranch house, and finished with a gun battle on main street.</p>
<h1>The system</h1>
<p>At the recommendation of an experienced GM, I used the <a href="http://error420.com/documents/Boot%20Hill%202nd%20Edition.pdf">Boot Hill (second edition) rules</a>, a creation of <a href="http://en.wikipedia.org/wiki/Gary_Gygax">Gary Gygax</a> and <a href="http://en.wikipedia.org/wiki/Brian_Blume">Brian Blume</a>.</p>
<p>I was looking for super-lightweight rules, so I didn&#039;t even use the full rules set described by the Boot Hill book &#8211; the only dice rolling during the campaign happened during combat.  Boot Hill gun combat is simple:</p>
<ul>
<li>The fastest draw (based on weapon speed and personal speed) goes first</li>
<li>Roll percentile dice (based on your weapon, personal accuracy, and a relatively short list of modifiers) to see if you hit:</li>
</ul>
<p style="text-align: center;"><a href="http://joshduff.com/wp-content/uploads/2010/01/Hit-determination-chart.jpg"><img class="size-medium wp-image-146  aligncenter" title="Boot Hill hit determination chart" src="http://joshduff.com/wp-content/uploads/2010/01/Hit-determination-chart-231x300.jpg" alt="" width="231" height="300" /></a></p>
<ul>
<li>Roll percentile dice on a wound chart to see where you hit:</li>
</ul>
<p style="text-align: center;"><a href="http://joshduff.com/wp-content/uploads/2010/01/Wound-chart.jpg"><img class="size-full wp-image-147 aligncenter" title="Boot Hill wound chart" src="http://joshduff.com/wp-content/uploads/2010/01/Wound-chart.jpg" alt="" width="325" height="289" /></a></p>
<p>Mortal wounds kill you.</p>
<p>Any wound at all gives you a -5% chance at getting to shoot first, and also to hitting the other guy.</p>
<p>Once your strength drops below 50% of what it is normally (which can often be done with a single serious wound), you start getting -20% to shooting first, and hitting.</p>
<p>It&#039;s a simple system, but one that facilitates characters dying pretty often.  A couple good rolls, and a single shot can permanently take out any character &#8211; even if he just rolled into town with a new bandanna and a pocket full of hit points.</p>
<h2>Wait, easy character death?</h2>
<p>I wanted my players to enjoy a good old-fashioned movie version of the wild west.  They were supposed to play the heroes &#8211; the guys who go flying through bar windows and come up swinging!</p>
<p>I wanted quick and dirty combat, but I wanted my PCs to be a bit more survivable.  I tried a few things to counteract the cheapness of life:</p>
<h3>Giving the PCs slightly better stats</h3>
<p>Standard nerfing &#8211; most of my NPCs would drop below half strength after one serious wound (which severely limits a character for the rest of the combat).  The player characters could took at least two (non-mortal) wounds before things got really sticky.</p>
<h3>Making healing much more trivial than the rules suggested</h3>
<p>According to the rules, healing is a fairly slow process, taking days or weeks to recover from any sort of combat wound.  My player characters needed to be able to get into gun battles every few hours &#8211; they could be rejuvenated by a good night&#039;s sleep, or the restorative powers of a <a href="http://tvtropes.org/pmwiki/pmwiki.php/Main/ApronMatron">kindly old lady</a>&#039;s stew.</p>
<h3>Adding a new game mechanic</h3>
<p>I decided to take a hint from the awesome and successful video game <em>Left 4 Dead</em>.  In that universe, survivor characters who go down are immobilized, but can still fire handguns until their teammates pull them up (or the zombies fill up at the brain buffet).</p>
<p>Any time one of the PCs took mortal damage, I did something similar &#8211; instead of the characters dying, they dropped to the ground and could fire their handguns at a reduced rate.  If another player made it over to them and used a round to pull them up, that character could enter the fray with some of their strength restored.</p>
<p>It wasn&#039;t a mechanic that saw a lot of use, but it turned several potential defeats into narrow victories.  I was happy with this &#8211; narrowly beating the baddies is a lot more exhilarating than seeing one side gun down the other like dogs.</p>
<h1>Also, I&#039;m a noob</h1>
<p>I found it a highly enjoyable experience, but there were weak spots.  The campaign was fairly light on dialog, which isn&#039;t necessarily a bad thing &#8211; I just wish I were better at having a conversation in character, and thinking on my feet.</p>
<p>My weaknesses were most evident in the final session, where my PCs held the big baddy in prison and were looking around for a way to prove his guilt (they were lawful, after all) or uncover the next plot hook.</p>
<p>I left them wandering around looking for a clue far too long before I initiated the next action for them to deal with.  They grilled the prisoner for some time (good roleplaying, at least), looking for the magic words that would advance the plot.  Blah.</p>
<h1>I think I might try this again</h1>
<p>I was very glad to have such great (and forgiving) roleplayers in my campaign.  When the GM is fresh, there&#039;s a lot less room for noobs or troublemakers.</p>
<p>I&#039;m definitely sold on lightweight rules sets, especially when going for a more cinematic feel.  The less of a barrier there is between the players and the cool things they want their characters to do, the better.</p>
<p>I have a suspicion that we might try this (noobs GMs practicing with friends) again sometime soon &#8211; if you have any suggestions for easy-to-pick-up gaming systems, or good scenarios for some one-shot sessions, then surrender your knowledge to my gaping mind-hole!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/145/running-my-first-campaign/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sleep &quot;schedule&quot;</title>
		<link>http://joshduff.com/141/sleep-schedule</link>
		<comments>http://joshduff.com/141/sleep-schedule#comments</comments>
		<pubDate>Mon, 28 Dec 2009 13:28:35 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Personal stupidity]]></category>

		<guid isPermaLink="false">http://joshduff.com/?p=141</guid>
		<description><![CDATA[A week ago, I used up a stretch of vacation time to indulge in a week of personal productivity (and video gaming).  During this stretch of time (from one Saturday to the next Sunday) I managed to sleep one less times than there were nights. That is to say, I did not sleep when it [...]]]></description>
			<content:encoded><![CDATA[<p>A week ago, I used up a stretch of vacation time to indulge in a week of personal productivity (and video gaming).  During this stretch of time (from one Saturday to the next Sunday) I managed to sleep one less times than there were nights.</p>
<p>That is to say, I did not sleep when it was dark &#8211; I slept when I felt tired enough to do so.  This happened to occur less often than nighttime.  To see a similar sleep schedule displayed in a handy timeline, check out <a href="http://xkcd.com/320/">this XKCD comic</a>.</p>
<p>Over Christmas weekend (4 days), I tried the same thing &#8211; I fell asleep very late the evening of the first day, very early the morning of third day, and again the afternoon of the fourth day.</p>
<p>This is the end of that experiment &#8211; over 4 days, I have slept 3 times.  As I go to work right now, I have already been awake for 8 hours.  I will probably feel like sleeping not long after I leave work.</p>
<p>The odd sleep schedule has some benefits: it&#039;s not hard to fall asleep (because my bed time is defined by when I feel sleepy), and depending on my sleep patterns, there is the possibility of actually spending less time sleeping every week.</p>
<p>The abnormal waking hours definitely felt odd at times, though I feel that I started to get used to them a bit.  I&#039;m considering trying a similar schedule over the course of a work week some time.  If I do, I will report back with my findings.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduff.com/141/sleep-schedule/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.060 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-03 18:38:35 -->
