<?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>Matthew Gruman &#187; Programming</title>
	<atom:link href="http://matthewgruman.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewgruman.com</link>
	<description>Matthew Gruman&#039;s Personal Site</description>
	<lastBuildDate>Mon, 12 Mar 2012 01:58:15 +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>New design for the Excuse Rolodex</title>
		<link>http://matthewgruman.com/new-design-for-the-excuse-rolodex/</link>
		<comments>http://matthewgruman.com/new-design-for-the-excuse-rolodex/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 03:03:58 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=713</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://excuserolodex.net"><img src="http://matthewgruman.com/wp-content/uploads/2011/03/Screen-shot-2011-03-01-at-7.02.24-PM.png" alt="Excuse Rolodex" title="Excuse Rolodex" width="520" height="542" class="alignnone size-full wp-image-714" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/new-design-for-the-excuse-rolodex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gruman Design and Development</title>
		<link>http://matthewgruman.com/gruman-design-and-development/</link>
		<comments>http://matthewgruman.com/gruman-design-and-development/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 23:54:12 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=707</guid>
		<description><![CDATA[I&#8217;ve redesigned my portfolio.]]></description>
			<content:encoded><![CDATA[<p><a href="http://grumandd.com"><img src="images/grumandd.png" /></a></p>
<p>I&#8217;ve redesigned <a href="http://grumandd.com">my portfolio</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/gruman-design-and-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serial commas and PHP</title>
		<link>http://matthewgruman.com/serial-commas-and-php/</link>
		<comments>http://matthewgruman.com/serial-commas-and-php/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 00:54:19 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[harvard comma]]></category>
		<category><![CDATA[oxford comma]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[serial comma]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=475</guid>
		<description><![CDATA[I love serial commas (putting a comma before &#8220;and&#8221; in a list. I.e. one, two, and three). People call them old-fashioned and clunky, but they really help with clarity (see this article for an example). The thing I don&#8217;t like about serial commas is trying to automate their formatting. I can&#8217;t find examples anywhere, so [...]]]></description>
			<content:encoded><![CDATA[<p>I love serial commas (putting a comma before &#8220;and&#8221; in a list. I.e. one, two, and three). People call them old-fashioned and clunky, but they really help with clarity (see <a href="http://www.languagehat.com/archives/001365.php">this article</a> for an example).</p>
<p>The thing I don&#8217;t like about serial commas is trying to automate their formatting. I can&#8217;t find examples anywhere, so here&#8217;s my PHP code to do it. The way I use it is a while() loop after querying a database, but it will work with any loop (i.e. a foreach&#8217;d array). $num_authors is the total number of records. $count_authors is set to 1 before the loop.</p>
<h3>The code</h3>
<p><strong>Update:</strong> Charismatic Programmer posted a much better way to do this in the comments section. This is their method:</p>
<pre>
function serial_comma($array)
{
     $size = sizeof($array);
     switch($size)
     {
          case 0:
          case 1:
               return reset($array);
          case 2:
               return join(' and ', $array);
          default:
               return join(', ', array_slice($array, 0, $size – 1)).', and '.$array[$size - 1];
     }
}

Example:

$array = array('Anthony Bourdain', 'Mario Batali', 'Thomas Keller');
echo serial_comma($array);

Produces:

Anthony Bourdain, Mario Batali, and Thomas Keller
</pre>
<h3>The old code</h3>
<pre>
if ($num_authors == 1)
{
	echo $author;
}
else
{
	if ($num_authors > $count_authors)
	{
		if (($count_authors + 1) == $num_authors)
		{
			if ($num_authors == 2)
			{
				echo "$author and ";
			}
			else
			{
				echo "$author, and ";
			}
		}
		else
		{
			echo "$author, ";
		}
	}
	elseif ($num_authors == $count_authors)
	{
		echo $author;
	}
      	else
	{
		// error message
	}
	$count_authors++;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/serial-commas-and-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Friendly Dates with MySQL and PHP</title>
		<link>http://matthewgruman.com/friendly-dates-with-mysql-and-php/</link>
		<comments>http://matthewgruman.com/friendly-dates-with-mysql-and-php/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 22:22:47 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.matthewgruman.com/?p=399</guid>
		<description><![CDATA[$when = date('F j, Y', strtotime($datetime)); The above code, where the &#8216;$datetime&#8217; variable is a MySQL datetime stamp, will output a humanized date use PHP&#8217;s date(); function.]]></description>
			<content:encoded><![CDATA[<p><code>$when = date('F j, Y', strtotime($datetime));</code></p>
<p>The above code, where the &#8216;$datetime&#8217; variable is a MySQL datetime stamp, will output a humanized date use PHP&#8217;s <a href="http://ca3.php.net/date">date();</a> function.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/friendly-dates-with-mysql-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display age based on birthday PHP script</title>
		<link>http://matthewgruman.com/display-age-based-on-birthday-php-script/</link>
		<comments>http://matthewgruman.com/display-age-based-on-birthday-php-script/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 22:42:31 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.matthewgruman.com/?p=389</guid>
		<description><![CDATA[I was looking for a way to keep the About section up to date and came across this one from Dzone that works really well: function birthday ($birthday) { list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff &#60; 0) $year_diff--; elseif (($month_diff==0) &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a way to keep the About section up to date and came across this one from <a href="http://snippets.dzone.com/posts/show/1310">Dzone</a> that works really well:</p>
<p><code>function birthday ($birthday)<br />
       {<br />
       list($year,$month,$day) = explode("-",$birthday);<br />
       $year_diff  = date("Y") - $year;<br />
       $month_diff = date("m") - $month;<br />
       $day_diff   = date("d") - $day;<br />
       if ($month_diff &lt; 0) $year_diff--;<br />
       elseif (($month_diff==0) &amp;&amp; ($day_diff &lt; 0)) $year_diff--;<br />
       return $year_diff;<br />
       }</code></p>
<p>You can activate it with:</p>
<p><code>echo birthday("YYYY-MM-DD");</code></p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/display-age-based-on-birthday-php-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Random Post Widget</title>
		<link>http://matthewgruman.com/random-post-widget/</link>
		<comments>http://matthewgruman.com/random-post-widget/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 19:27:04 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[random post]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=271</guid>
		<description><![CDATA[I added a &#8220;Random Post&#8221; widget to the sidebar today. I spent a couple minutes at the WordPress Widgets site, but I couldn&#8217;t find anything I liked so I made my own in PHP that is stupidly simple. I defined the randomPost() function in wp-includes/functions.php because I knew it was being included already. You can [...]]]></description>
			<content:encoded><![CDATA[<p>I added a &#8220;Random Post&#8221; widget to the sidebar today. I spent a couple minutes at the <a href="http://codex.wordpress.org/Plugins/WordPress_Widgets">WordPress Widgets</a> site, but I couldn&#8217;t find anything I liked so I made my own in <acronym title="PHP Hypertext Processor">PHP</acronym> that is stupidly simple.</p>
<p>I defined the randomPost() function in wp-includes/functions.php because I knew it was being included already. You can put it anywhere, or just dump the code directly onto your page.</p>
<h3>Random Post Code</h3>
<p><code>function randomPost() {<br />
&lt;div class="side-sec pages"&gt;<br />
&lt;h3&gt;Random Post&lt;/h3&gt;<br />
&lt;?php<br />
// Get ID, Title, Post, and Date from WordPress DB<br />
$query = "SELECT ID, post_title, post_content, post_date FROM wp_posts WHERE post_type='post' ORDER BY RAND() LIMIT 1";<br />
$result = mysql_query($query);<br />
// Use $row for grabbed content<br />
$row = mysql_fetch_array($result);<br />
// Take only the first 150 characters and get rid of HTML from post<br />
$content = substr(strip_tags($row[2]), 0, 150);<br />
// Display using relative dates<br />
echo '&lt;p&gt;&lt;a href="?p='.$row[0].'"&gt;'.$row[1].'&lt;/a&gt; '.lastfm_relative($row[3]).'&lt;/p&gt;<br />
&lt;p&gt;'.$content.' [...]&lt;/p&gt;';<br />
?&gt;<br />
&lt;/div&gt;<br />
}</code></p>
<p>Since I already use the <a href="http://rick.jinlabs.com/code/lastfm">Last.fm for WordPress</a> plugin, I used their relative time function: lastfm_relative(). If you don&#8217;t have/want that plugin, here is the code for the function.</p>
<h3>Relative Time Function</h3>
<p><code>function lastfm_relative($time) {<br />
    $time_orig = strtotime($time);<br />
    $diff = $just = time()-$time_orig;<br />
    $months = floor($diff/2592000);<br />
    $diff -= $months*2419200;<br />
    $weeks = floor($diff/604800);<br />
    $diff -= $weeks*604800;<br />
    $days = floor($diff/86400);<br />
    $diff -= $days*86400;<br />
    $hours = floor($diff/3600);<br />
    $diff -= $hours*3600;<br />
    $minutes = floor($diff/60);<br />
    $diff -= $minutes*60;<br />
    $seconds = $diff;<br />
    // Variables defined<br />
	if ($just&lt;=0) {<br />
		return 'Just Now!';<br />
	} else {<br />
	    if ($months&gt;0) {<br />
	        // over a month old, just show date (yyyy/mm/dd format)<br />
	        return 'on '.date('Y/m/d', $time_orig);<br />
	    } else {<br />
	        if ($weeks&gt;0) {<br />
	            // weeks and days<br />
	            $relative_date .= ($relative_date?', ':'').$weeks.' '.__('week').($weeks&gt;1?'s':'');<br />
	            $relative_date .= $days&gt;0?($relative_date?', ':'').$days.' '.__('day').($days&gt;1?'s':''):'';<br />
	        } elseif ($days&gt;0) {<br />
	            // days and hours<br />
	            $relative_date .= ($relative_date?', ':'').$days.' '.__('day').($days&gt;1?'s':'');<br />
	            $relative_date .= $hours&gt;0?($relative_date?', ':'').$hours.' '.__('hour').($hours&gt;1?'s':''):'';<br />
	        } elseif ($hours&gt;0) {<br />
	            // hours and minutes<br />
	            $relative_date .= ($relative_date?', ':'').$hours.' '.__('hour').($hours&gt;1?'s':'');<br />
	            $relative_date .= $minutes&gt;0?($relative_date?', ':'').$minutes.' '.__('minute').($minutes&gt;1?'s':''):'';<br />
	        } elseif ($minutes&gt;0) {<br />
	            // minutes only<br />
	            $relative_date .= ($relative_date?', ':'').$minutes.' '.__('minute').($minutes&gt;1?'s':'');<br />
	        } else {<br />
	            // seconds only<br />
	            $relative_date .= ($relative_date?', ':'').$seconds.' '.__('second').($seconds&gt;1?'s':'');<br />
	        }<br />
	    }<br />
	}<br />
    // show relative date and add proper verbiage<br />
    return $relative_date.' ago';<br />
}</code></p>
<p>And that&#8217;s it. The relative time function is by far the most complex part of this whole operation. There&#8217;s no validation or verification &#8212; it assumes that there are posts ready to be grabbed, that your database is accessible, etc. You can see it working on the right side of this page.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/random-post-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dictionary Design</title>
		<link>http://matthewgruman.com/dictionary-design/</link>
		<comments>http://matthewgruman.com/dictionary-design/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 02:06:44 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[dictionary]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=229</guid>
		<description><![CDATA[Drafting Process It&#8217;s rare for me to do any kind of digital work without a paper/pencil or whiteboard next to me for jot notes, drafts, and calculations. I&#8217;ve been redeveloping the entry system for a dictionary that&#8217;s going to be used by hundreds of students around the world for the next seven years, and eventually [...]]]></description>
			<content:encoded><![CDATA[<h3>Drafting Process</h3>
<p>It&#8217;s rare for me to do any kind of digital work without a paper/pencil or whiteboard next to me for jot notes, drafts, and calculations. I&#8217;ve been redeveloping the entry system for a dictionary that&#8217;s going to be used by hundreds of students around the world for the next seven years, and eventually as the public digital front end. It&#8217;s very important to me that I get this right.</p>
<p>Draft 1 was just a quicky to make sure I could get everything I wanted, so there was no drawing. Now that is IS working, it&#8217;s time to think about usability and aesthetics &#8212; the two most important aspects, to me, of any website &#8212; and that means it&#8217;s time to grab a marker.</p>
<h3>Draft 2</h3>
<p><img src="/images/draft_2.jpg" class="centered" alt="Wire frame whiteboard drawing of a website" /></p>
<p>Draft 2 was an attempt to streamline the dictionary&#8217;s entry system, but failed when it came down to semantics. The back-end was ridiculously elaborate and difficult. A system does not work when the person who created it can&#8217;t figure out how to use it properly.</p>
<h3>Draft 3</h3>
<p><img src="/images/draft_3.jpg" class="centered" alt="Wire frame whiteboard drawing of a website" /></p>
<p>Draft 3 looks a little cramped from the wire frame, but it&#8217;s very intuitive and slick &#8212; this is it for now. Also, it has big ass Submit and Cancel buttons. Failing something awful, the final product will probably be very similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/dictionary-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Goodbye To Do List</title>
		<link>http://matthewgruman.com/goodbye-to-do-list/</link>
		<comments>http://matthewgruman.com/goodbye-to-do-list/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 00:50:33 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=224</guid>
		<description><![CDATA[I&#8217;ve gotten rid of the To Do List on the right side of this website. I realize that I&#8217;m not the type of person who responds well to pressure &#8212; internal or external &#8212; as motivation. With the exception of the first week, I was only adding things that I didn&#8217;t really care about (i.e. [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve gotten rid of the To Do List on the right side of this website. I realize that I&#8217;m not the type of person who responds well to pressure &#8212; internal or external &#8212; as motivation. With the exception of the first week, I was only adding things that I didn&#8217;t really care about (i.e. whether or not I&#8217;ll finish a book within the alloted time) or I could make vague enough not to matter (i.e. &#8220;The Web 2.0 Project&#8221;; what does that even mean?!). And in truth, most of the things I do I either CAN&#8217;T or WON&#8217;T tell people about until they&#8217;re actually done.
</p>
<p>If anyone remembers and wants it, send me an email. It&#8217;s simple PHP and MySQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/goodbye-to-do-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Social Network Apps</title>
		<link>http://matthewgruman.com/social-network-apps/</link>
		<comments>http://matthewgruman.com/social-network-apps/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 17:09:59 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=216</guid>
		<description><![CDATA[The big loser? Well, anyone who writes apps for social networks, pretty much by definition. Valleywag.]]></description>
			<content:encoded><![CDATA[<blockquote><p>
The big loser? Well, anyone who writes apps for social networks, pretty much by definition.
</p></blockquote>
<p><a href="http://valleywag.com/tech/developer-relations/facebook-throws-platform-at-rivals-pokes-google-333174.php">Valleywag</a>.</com></p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/social-network-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Audiogalaxy</title>
		<link>http://matthewgruman.com/audiogalaxy/</link>
		<comments>http://matthewgruman.com/audiogalaxy/#comments</comments>
		<pubDate>Tue, 23 Oct 2007 22:30:30 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://matthewgruman.com/?p=152</guid>
		<description><![CDATA[Remember Audiogalaxy? That was pretty much the glory days of p2p, eh? I don&#8217;t know why I was thinking of them today, but I came across this very interesting article written by one of the original programmers back in 2002 (when the RIAA took them down).]]></description>
			<content:encoded><![CDATA[<p>Remember Audiogalaxy? That was pretty much the glory days of <acronym title="Peer To Peer">p2p</acronym>, eh? I don&#8217;t know why I was thinking of them today, but I came across <a href="http://www.kuro5hin.org/story/2002/6/21/171321/675">this very interesting</a> article written by one of the original programmers back in 2002 (when the <acronym title="Recording Industry Association of America">RIAA</acronym> took them down).</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewgruman.com/audiogalaxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

