<?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>Jon Fox &#187; Code</title>
	<atom:link href="http://www.jonefox.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonefox.com/blog</link>
	<description>My rants, ramblings, and random thoughts</description>
	<lastBuildDate>Mon, 16 Jan 2012 14:48:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='www.jonefox.com' port='80' path='/blog/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Find the Time to First Byte Using Curl</title>
		<link>http://www.jonefox.com/blog/2011/10/10/find-the-time-to-first-byte-using-curl/</link>
		<comments>http://www.jonefox.com/blog/2011/10/10/find-the-time-to-first-byte-using-curl/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 16:28:14 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[time to first byte]]></category>
		<category><![CDATA[TTFB]]></category>

		<guid isPermaLink="false">http://www.jonefox.com/blog/?p=608</guid>
		<description><![CDATA[I was recently looking for an easy way to find the time to first byte (TTFB) for a given url using curl. I wanted to run some script based tests for a bunch of urls over time. I ended up &#8230; <a href="http://www.jonefox.com/blog/2011/10/10/find-the-time-to-first-byte-using-curl/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was recently looking for an easy way to find the <a href="http://en.wikipedia.org/wiki/Time_To_First_Byte" title="Time To First Byte">time to first byte</a> (TTFB) for a given url using curl.  I wanted to run some script based tests for a bunch of urls over time.  I ended up coming up with the following:<br />
<code>curl -w "Connect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total} \n" -o /dev/null [url to test]</code></p>
<p>This gives you something like the following:<br />
<code>curl -w "Connect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total} \n" -o /dev/null www.google.com<br />
Connect time: 0.402 Time to first byte: 0.453 Total time: 0.475</code></p>
<p>Hope this is useful to someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2011/10/10/find-the-time-to-first-byte-using-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP str_replace_last function</title>
		<link>http://www.jonefox.com/blog/2011/09/26/php-str_replace_last-function/</link>
		<comments>http://www.jonefox.com/blog/2011/09/26/php-str_replace_last-function/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 06:40:44 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[str_replace last]]></category>

		<guid isPermaLink="false">http://www.jonefox.com/blog/?p=595</guid>
		<description><![CDATA[I recently found myself in need of a way to replace the last (and only the last) occurrence of a substring within a string. Basically exactly str_replace, but only on the last occurrence of the needle within the haystack. I &#8230; <a href="http://www.jonefox.com/blog/2011/09/26/php-str_replace_last-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently found myself in need of a way to replace the last (and only the last) occurrence of a substring within a string.  Basically exactly str_replace, but only on the last occurrence of the needle within the haystack.  I came up with this quick solution.  Feedback welcome.</p>
<pre>
function str_replace_last( $search, $replace, $subject ) {
    if ( !$search || !$replace || !$subject )
        return false;

    $index = strrpos( $subject, $search );
    if ( $index === false )
        return $subject;

    // Grab everything before occurence
    $pre = substr( $subject, 0, $index );

    // Grab everything after occurence
    $post = substr( $subject, $index );

    // Do the string replacement
    $post = str_replace( $search, $replace, $post );

    // Recombine and return result
    return $pre . $post;
}
</pre>
<p>Hope someone else finds this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2011/09/26/php-str_replace_last-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to programmatically find the continent from a given city or state</title>
		<link>http://www.jonefox.com/blog/2011/08/24/how-to-programmatically-find-the-continent-from-a-given-city-or-state/</link>
		<comments>http://www.jonefox.com/blog/2011/08/24/how-to-programmatically-find-the-continent-from-a-given-city-or-state/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 03:23:37 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[continent lookup]]></category>

		<guid isPermaLink="false">http://www.jonefox.com/blog/?p=555</guid>
		<description><![CDATA[I recently ran across a somewhat unusual problem. I needed to find a programatic way to convert a string that could be a city or a state name into the continent that the city or state belongs to. I Googled &#8230; <a href="http://www.jonefox.com/blog/2011/08/24/how-to-programmatically-find-the-continent-from-a-given-city-or-state/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently ran across a somewhat unusual problem. I needed to find a programatic way to convert a string that could be a city or a state name into the continent that the city or state belongs to. I Googled around a bit and couldn&#8217;t find an obvious solution, so I thought I&#8217;d write this up in hope of helping the next guy.</p>
<p>What I ended up doing is using the <a title="Yahoo GeoPlanet API" href="http://developer.yahoo.com/geo/geoplanet/guide/api-reference.html#api-summary">Yahoo! GeoPlanet API</a>. This allowed me to do a query of my city or state name and get a place resource, then use that to find the continent that the place resource belongs to.</p>
<p>So first things first, you&#8217;re going to need an app id from Yahoo!, so if you don&#8217;t already have one you&#8217;ll need to <a href="https://developer.apps.yahoo.com/projects/">get one</a>. Then you just need to make a request like the following:<br />
<code>http://where.yahooapis.com/v1/places.q(CITY_OR_STATE)?appid=YOUR_APP_ID</code><br />
Where <code>CITY_OR_STATE</code> is the query term you&#8217;re searching for and <code>YOUR_APP_ID</code> is the Yahoo! app id from above. Then you&#8217;ll get back something like the following:</p>
<pre></pre>
<pre>&lt;places xmlns="http://where.yahooapis.com/v1/schema.rng" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:start="0" yahoo:count="1" yahoo:total="300"&gt;
&lt;place yahoo:uri="http://where.yahooapis.com/v1/place/2488042" xml:lang="en-US"&gt;
&lt;woeid&gt;2488042&lt;/woeid&gt;
&lt;placeTypeName code="7"&gt;Town&lt;/placeTypeName&gt;
&lt;name&gt;San Jose&lt;/name&gt;
&lt;country type="Country" code="US"&gt;United States&lt;/country&gt;
&lt;admin1 type="State" code="US-CA"&gt;California&lt;/admin1&gt;
&lt;admin2 type="County" code=""&gt;Santa Clara&lt;/admin2&gt;
&lt;admin3/&gt;
&lt;locality1 type="Town"&gt;San Jose&lt;/locality1&gt;
&lt;locality2/&gt;
&lt;postal/&gt;
&lt;centroid&gt;
&lt;latitude&gt;37.338470&lt;/latitude&gt;
&lt;longitude&gt;-121.885788&lt;/longitude&gt;
&lt;/centroid&gt;
&lt;boundingBox&gt;
&lt;southWest&gt;
&lt;latitude&gt;37.117840&lt;/latitude&gt;
&lt;longitude&gt;-122.160027&lt;/longitude&gt;
&lt;/southWest&gt;
&lt;northEast&gt;
&lt;latitude&gt;37.555859&lt;/latitude&gt;
&lt;longitude&gt;-121.535393&lt;/longitude&gt;
&lt;/northEast&gt;
&lt;/boundingBox&gt;
&lt;areaRank&gt;6&lt;/areaRank&gt;
&lt;popRank&gt;12&lt;/popRank&gt;
&lt;/place&gt;
&lt;/places&gt;</pre>
<p>You want to grab the <code>woeid</code> (in this case 2488042) for the next part. Next, we need to lookup the continent this place resource belongs to. To do this we make a request like so:<br />
<code>http://where.yahooapis.com/v1/place/THE_WOEID/belongtos.type(29)?appid=YOUR_APP_ID</code><br />
Where <code>THE_WOEID</code> is the woeid we found in the last step (2488042 in this example) and <code>YOUR_APP_ID</code> is your app id again. This should return something like the following:</p>
<pre>
&lt;places xmlns="http://where.yahooapis.com/v1/schema.rng" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:start="0" yahoo:count="1" yahoo:total="1"&gt;
&lt;place yahoo:uri="http://where.yahooapis.com/v1/place/24865672" xml:lang="en-US"&gt;
&lt;woeid&gt;24865672&lt;/woeid&gt;
&lt;placeTypeName code="29"&gt;Continent&lt;/placeTypeName&gt;
&lt;name&gt;North America&lt;/name&gt;
&lt;/place&gt;
&lt;/places&gt;
</pre>
<p>Where <code><name>North America</name></code> is clearly what we want to pull out of it.</p>
<p>I was doing this in PHP, so here&#8217;s a quick and dirty PHP example:</p>
<pre>
function continent_lookup( $search ) {
    if ( strlen( $search ) == 0 )
        return false;

    $search = urlencode( $search );

    $app_id = 'YOUR_APP_ID';

    $res = file_get_contents( "http://where.yahooapis.com/v1/places.q($search)?appid=$app_id" );
    preg_match( "/&lt;woeid&gt;([0-9]+?)&lt;\/woeid&gt;/", $res, $match );

    if ( !$match )
        return false;

    $woeid = $match[1];

    $res = file_get_contents( "http://where.yahooapis.com/v1/place/$woeid/belongtos.type(29)?appid=$app_id" );
    preg_match( "/&lt;name&gt;(.+?)&lt;\/name&gt;/", $res, $match );

    return $match[1];
}
</pre>
<p>Hope this helps someone else out there. Let me know if you have any feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2011/08/24/how-to-programmatically-find-the-continent-from-a-given-city-or-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Detect Transparency In PNG Images</title>
		<link>http://www.jonefox.com/blog/2011/04/15/how-to-detect-transparency-in-png-images/</link>
		<comments>http://www.jonefox.com/blog/2011/04/15/how-to-detect-transparency-in-png-images/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 14:29:52 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://www.jonefox.com/blog/?p=484</guid>
		<description><![CDATA[I recently came across a problem where I needed to check for transparency in PNG images using PHP. After some digging with the help of my partner Josh, we came up with the following php function: function png_has_transparency( $filename ) &#8230; <a href="http://www.jonefox.com/blog/2011/04/15/how-to-detect-transparency-in-png-images/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently came across a problem where I needed to check for transparency in PNG images using PHP.  After some digging with the help of my partner Josh, we came up with the following php function:</p>
<pre>
function png_has_transparency( $filename ) {
    if ( strlen( $filename ) == 0 || !file_exists( $filename ) )
        return false;

    if ( ord ( file_get_contents( $filename, false, null, 25, 1 ) ) &amp; 4 )
        return true;

    $contents = file_get_contents( $filename );
    if ( stripos( $contents, 'PLTE' ) !== false &amp;&amp; stripos( $contents, 'tRNS' ) !== false )
        return true;

    return false;
}</pre>
<p>The first file check:<br />
<code>ord ( file_get_contents( $filename, false, null, 25, 1 ) ) &amp; 4</code><br />
will check for transparency in a 32-bit PNG.  The second check<br />
<code>stripos( $contents, 'PLTE' ) !== false &amp;&amp; stripos( $contents, 'tRNS' ) !== false</code><br />
 works to detect transparency in 8-bit PNG&#8217;s.  Big thanks to <a href="http://camendesign.com/code/uth1_is-png-32bit">this article</a> which expains how these parts work in a bit more detail.</p>
<p>Depending on how likely you are to have transparency (or 32-bit png&#8217;s) you might want to modify this function to only do one file access, but the advantage here is that if it is a 32-bit png with transparency we only need to read in part of the file.  This was faster in my early testing of a sample of our images, but your results may vary.</p>
<p>Hope this helps someone else out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2011/04/15/how-to-detect-transparency-in-png-images/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>One time use email addresses</title>
		<link>http://www.jonefox.com/blog/2011/01/02/one-time-use-email-addresses/</link>
		<comments>http://www.jonefox.com/blog/2011/01/02/one-time-use-email-addresses/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 23:22:21 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Random Ideas]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://jonefox.com/blog/?p=463</guid>
		<description><![CDATA[Recently I threw together a tool to simplify my sign up on other services.  It&#8217;s a script that allows me to use an email address one time, and then ignore all future emails to that address.  I often use it &#8230; <a href="http://www.jonefox.com/blog/2011/01/02/one-time-use-email-addresses/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I threw together a tool to simplify my sign up on other services.  It&#8217;s a script that allows me to use an email address one time, and then ignore all future emails to that address.  I often use it for signing up to new services so that I can get the confirmation email, but not get a bunch of spam / bacon I don&#8217;t really care about.  I set it up with a custom domain so that I can use anything at that domain as an email address.  For example, test1@mycustomdomain.com, test2@mycustomdomain.com, and anotherdumbemail@mycustomdomain.com.</p>
<p>The interesting part of it, though, is that the emails all dump to a PHP script.  This script looks at the email address it was sent to, and checks a database to see if that email address has been seen before or not.  If it hasn&#8217;t, it will forward that email to my &#8220;real&#8221; email address.  If it has, it will ignore it.</p>
<p>This has been super helpful when making test accounts on services too as it&#8217;s easy to get another email address, but I don&#8217;t have to worry about checking a weird email account or getting a bunch of spam afterwards.  Just thought I&#8217;d mention it in case anyone else out there does a lot of this stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2011/01/02/one-time-use-email-addresses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gravatar in Gmail (Update)</title>
		<link>http://www.jonefox.com/blog/2010/01/25/gravatar-in-gmail-update/</link>
		<comments>http://www.jonefox.com/blog/2010/01/25/gravatar-in-gmail-update/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 03:03:21 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[gravatar]]></category>
		<category><![CDATA[greasemonkey]]></category>

		<guid isPermaLink="false">http://jonefox.com/blog/?p=277</guid>
		<description><![CDATA[A while back I wrote a Greasemonkey script to add Gravatars to Gmail. Unfortunately it broke after an update from Gmail and had a few issues I didn&#8217;t like. I recently had a chance to go back through the script &#8230; <a href="http://www.jonefox.com/blog/2010/01/25/gravatar-in-gmail-update/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://jonefox.com/blog/2009/03/14/gravatar-in-gmail/">A while back</a> I wrote a <a href="https://addons.mozilla.org/en-US/firefox/addon/748">Greasemonkey</a> script to add <a href="http://en.gravatar.com/">Gravatars</a> to <a href="http://gmail.com/">Gmail</a>.  Unfortunately it broke after an update from Gmail and had a few issues I didn&#8217;t like.</p>
<p>I recently had a chance to go back through the script though and update it.  It now uses <a href="http://jquery.com/">jQuery</a>, works with the current Gmail structure, and loads Gravatars for all open messages (the last one didn&#8217;t).  It&#8217;s not perfect though.  It will not yet load Gravatars if you click to open a collapsed message in a conversation (only the expanded messages upon first opening will have the Gravatar images loaded).  It works pretty well otherwise, though, and it&#8217;s nice to see faces with my emails again.</p>
<p>I&#8217;ve got a screen shot below if you want to see what it looks like.  If you&#8217;d like to get the script for yourself, I&#8217;ve posted it <a href="http://jonefox.com/blog/download_gravatar_in_gmail.user.js">here</a>.  Just install Greasemonkey, click the link, and choose &#8220;install&#8221; when the popup comes up.  Enjoy.</p>
<p><img style='display:none' src="http://jonefox.com/blog/wp-content/uploads/2009/03/grav_gmail_screen.jpg" alt="Screenshot of Gravatar in Gmail" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2010/01/25/gravatar-in-gmail-update/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Add a custom url shortener to Firefox</title>
		<link>http://www.jonefox.com/blog/2009/11/30/add-a-custom-url-shortener-to-firefox/</link>
		<comments>http://www.jonefox.com/blog/2009/11/30/add-a-custom-url-shortener-to-firefox/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 19:52:12 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[jfox.in]]></category>
		<category><![CDATA[short url]]></category>

		<guid isPermaLink="false">http://jonefox.com/blog/?p=271</guid>
		<description><![CDATA[I recently wrote a post about why I made my own url shortener. I&#8217;m now porting some of my common uses over to use this new shortener (keep life simple, right?). The first thing I wanted to address was adding &#8230; <a href="http://www.jonefox.com/blog/2009/11/30/add-a-custom-url-shortener-to-firefox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a <a href="http://jonefox.com/blog/2009/11/01/my-own-short-urls/">post</a> about why I made my own url shortener.  I&#8217;m now porting some of my common uses over to use this new shortener (keep life simple, right?). The first thing I wanted to address was adding an option to the right-click menu to shorten whatever page I was currently viewing and copy it to the clipboard.  The easiest way I found to do this was to modify an existing Firefox addon called <a href="https://addons.mozilla.org/en-US/firefox/addon/11423">Shorten URL</a>.  It works particularly well because it already supports a TON of shortening services and adding new ones is a breeze.  So how do you do it?</p>
<ol>
<li>First, download <a href="https://addons.mozilla.org/en-US/firefox/addon/11423">the extension</a>.</li>
<li>Next, find your <a href="http://kb.mozillazine.org/Profile_folder_-_Firefox">Firefox profile folder</a>.</li>
<li>In your profile folder, find and open the &#8220;extensions/ShortenURL@loucypher/defaults/preferences&#8221; folder.</li>
<li>You should then find a file named shortenURL_prefs.js &#8211; open it in any text editor.</li>
<li>You should see two large blocks of similar lines repeating &#8211; find the last one in the first block (as of writing this it is <code>pref("extensions.shortenURL.name.145", "w3t.org");</code> and add a new line below it (incrementing the number) and swap out the name w/ whatever you want to reference your url shortener as. (in my case <code>pref("extensions.shortenURL.name.146", "jfox.in");</code></li>
<li>Continue to the end of the file and you should find a matching url line <code>pref("extensions.shortenURL.145", "http://w3t.org/?module=ShortURL&#038;file=Add&#038;mode=API&#038;url=");</code>.  Add a new line below this one incrementing the number again (to match the one in the last step) and adding the url of the page to submit a url to shorten (the url will be appended to the end).  For example: <code>pref("extensions.shortenURL.146", "http://jfox.in/make-tiny.php?url=");</code> (note the example here won&#8217;t actually work because my shortener is private).</li>
<li>Save the file and restart Firefox.  Now go to Tools->Add-ons, find ShortenURL in the list and select &#8220;preferences&#8221;.  You should now be able to find your custom shortener in the list using the name you provided above (in my case jfox.in).  Select your preference and enjoy!</li>
</ol>
<p>A quick trailing note:  This all assumes that your shortener has an interface that allows a url to be passed as a GET parameter and returns the shortened url in plain text as a result of that request.  This is straight forward to implement, but worth mentioning.  You should now be able to shorten simply by right-clicking and selecting the &#8220;Shorten this page URL&#8221; option (which will also copy the short url to your clipboard and put it in the location bar).  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2009/11/30/add-a-custom-url-shortener-to-firefox/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>My own short URLs</title>
		<link>http://www.jonefox.com/blog/2009/11/01/my-own-short-urls/</link>
		<comments>http://www.jonefox.com/blog/2009/11/01/my-own-short-urls/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 16:32:19 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[jfox.in]]></category>
		<category><![CDATA[short url]]></category>

		<guid isPermaLink="false">http://jonefox.com/blog/?p=249</guid>
		<description><![CDATA[A little while ago I setup my own short URL service on http://jfox.in. I already know there are tons of free services that already do this and there are even a few open source alternatives of projects aimed at this &#8230; <a href="http://www.jonefox.com/blog/2009/11/01/my-own-short-urls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A little while ago I setup my own short URL service on http://jfox.in.  I already know there are tons of free services that already do this and there are even a few open source alternatives of projects aimed at this kind of thing&#8230;so why then did I decide to write my own?  There are actually a couple reasons:</p>
<ul>
<li>Full control of the data &#8211; I can get at it wherever, however, and whenever I want to.  I can also move it into different formats and systems at will.</li>
<li>Full control over the service &#8211; I can add whatever features I want in whatever interface I want and not have to worry about the 15 other features I&#8217;ll never use that clutter up my UI.</li>
<li>Full control over the URLs themselves &#8211; I don&#8217;t have to worry about the domain shutting down, remapping my short URLs some time in the future, or what type of header redirect they&#8217;re using to make sure I get my Google juice.</li>
<li>It was fun &#8211; Perhaps the biggest reason I wanted to do this was because it&#8217;s such a simple project and it was kind of a fun exercise for me.</li>
</ul>
<p>Anyone that is code savvy and is considering doing this &#8211; whatever your reasons &#8211; I definitely recommend doing it.  It was simple and something I enjoyed, and it gives me the control I want in such a simple application.  Not every problem makes sense to roll your own solution for, but this is one that does in my mind since it&#8217;s so simple.</p>
<p>I honestly wouldn&#8217;t be surprised if we see more web services offering their own custom URLs.  It allows a bit more brand recognition and all the control issues I mention above.  It also seems that short URL services aren&#8217;t going away anytime soon.</p>
<p>Do you have any thoughts on the merits of short URL services?  Have you written your own or considered doing so?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2009/11/01/my-own-short-urls/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Lorem Ipsum Post Generator WordPress Plugin</title>
		<link>http://www.jonefox.com/blog/2009/08/30/lorem-ipsum-post-generator-wordpress-plugin/</link>
		<comments>http://www.jonefox.com/blog/2009/08/30/lorem-ipsum-post-generator-wordpress-plugin/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 21:39:59 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[lorem ipsum]]></category>
		<category><![CDATA[test posts]]></category>
		<category><![CDATA[wordpress plugin]]></category>

		<guid isPermaLink="false">http://jonefox.com/blog/?p=194</guid>
		<description><![CDATA[I&#8217;m constantly working with test blogs for IntenseDebate. Often, I need new posts and/or comments to give me some data to play with while testing new features, debugging old ones, or just to show something off. Instead of creating endless &#8230; <a href="http://www.jonefox.com/blog/2009/08/30/lorem-ipsum-post-generator-wordpress-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m constantly working with test blogs for <a href="http://intensedebate.com">IntenseDebate</a>.  Often, I need new posts and/or comments to give me some data to play with while testing new features, debugging old ones, or just to show something off.  Instead of creating endless posts and comments of &#8220;testing 123&#8243; and &#8220;another random test post&#8221;, I decided to throw together a quick WordPress plugin that will generate the posts for me using <a href="http://lipsum.com/">Lorem Ipsum</a> text.  It has a couple options, mainly the number of posts to create, a min and max number of paragraphs per post, and a min and max number of comments per post.  I find it really useful for generating some test content quickly.  I&#8217;ve posted a screenshot below.  It&#8217;s nothing beautiful, but I thought it might be useful to someone else out there.  I&#8217;ve posted the plugin <a href="http://downloads.wordpress.org/plugin/lorem-ipsum-post-generator.zip">here</a> if you want to check it out.<br />
<img class="size-medium wp-image-195" title="Lorem Ipsum Post Generator Plugin Screenshot" src="http://jonefox.com/blog/wp-content/uploads/2009/08/loremipsum-screen-300x192.jpg" alt="Screenshot of the Lorem Ipsum Post Generate Plugin" width="300" height="192" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2009/08/30/lorem-ipsum-post-generator-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Internet Explorer and the innerHTML Property</title>
		<link>http://www.jonefox.com/blog/2009/05/21/internet-explorer-and-the-innerhtml-property/</link>
		<comments>http://www.jonefox.com/blog/2009/05/21/internet-explorer-and-the-innerhtml-property/#comments</comments>
		<pubDate>Thu, 21 May 2009 06:19:47 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[browser crash]]></category>
		<category><![CDATA[innerHTML]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://jonefox.com/blog/?p=181</guid>
		<description><![CDATA[Recently while helping a friend deal with the joys of cross-browser JavaScript when working with widgets, I was reminded of a painful quirk in how Intenert Explorer handles the innerHTML property of DOM elements in some cases.Â  In particular, DOM &#8230; <a href="http://www.jonefox.com/blog/2009/05/21/internet-explorer-and-the-innerhtml-property/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently while helping a friend deal with the joys of cross-browser JavaScript when working with widgets, I was reminded of a painful quirk in how Intenert Explorer handles the innerHTML property of DOM elements in some cases.Â  In particular, DOM elements that are part of a table, or are a child to a table (no matter how many levels deep), can&#8217;t have the innerHTML property set at run time.Â  Doing so produces a completely unhelpful error message and crashes the rendering engine.Â  This is not only true for tables, but unfortunately happens with several other HTML elements in regard to Internet Explorer.</p>
<p>So, how does one get around this unfortunate problem?Â  Well, the best method I&#8217;ve found is to set the innerHTML property when the element is not yet attached to the DOM or is attached in a &#8220;safe&#8221; place (usually at the BODY tag).Â  To make this process simpler, I generalized this into a function that creates a new DOM node of the same type, preserves any attributes I care about, sets the innerHTML property, and replaces the original node in the DOM with this new node having the desired innerHTML.Â  Here&#8217;s the function for reference:</p>
<pre>
function replace_html(el, html) {
	if( el ) {
                var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
                var newEl = document.createElement(oldEl.nodeName);

                // Preserve any properties we care about (id and class in this example)
                newEl.id = oldEl.id;
                newEl.className = oldEl.className;

                //set the new HTML and insert back into the DOM
                newEl.innerHTML = html;
                if(oldEl.parentNode)
        	        oldEl.parentNode.replaceChild(newEl, oldEl);
                else
		        oldEl.innerHTML = html;

                //return a reference to the new element in case we need it
                return newEl;
	}
};
</pre>
<p>Hopefully this function will help someone out there work around this problem a little faster than I originally did.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonefox.com/blog/2009/05/21/internet-explorer-and-the-innerhtml-property/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>

