<?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>drew &#187; WebDev</title>
	<atom:link href="http://drewjoh.com/blog/category/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://drewjoh.com/blog</link>
	<description>Words on your display.</description>
	<lastBuildDate>Sat, 16 Jan 2010 07:13:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Time Based UUID Function (GUID)</title>
		<link>http://drewjoh.com/blog/2009/07/php-time-based-uuid-function-guid/</link>
		<comments>http://drewjoh.com/blog/2009/07/php-time-based-uuid-function-guid/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 21:50:27 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[guid]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[primary key]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://drewjoh.com/blog/?p=74</guid>
		<description><![CDATA[
			
				
			
		
In my desire to find the &#8220;right&#8221; UUID function to use in my application, I grew to like the MySQL UUID() results produced because they are partially time based.  But I didn&#8217;t like that I have to make a database call every time I want a new UUID.  I didn&#8217;t find any similar functionality [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2009%2F07%2Fphp-time-based-uuid-function-guid%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2009%2F07%2Fphp-time-based-uuid-function-guid%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>In my desire to find the &#8220;right&#8221; <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier" target="_self">UUID</a> function to use in my application, I grew to like the <a href="http://dev.mysql.com/doc/refman/5.1/en/miscellaneous-functions.html#function_uuid" target="_self">MySQL UUID()</a> results produced because they are partially time based.  But I didn&#8217;t like that I have to make a database call every time I want a new UUID.  I didn&#8217;t find any similar functionality in PHP or from user based PHP functions, so here&#8217;s my efforts.</p>
<p>It clocks in at 100,000 results in about 1.36 seconds on my 2.8Ghz Intel iMac.</p>
<pre class="brush: php;">function uuid()
{
	// Time based PHP Unique ID
	$uid = uniqid(NULL, TRUE);
	// Random SHA1 hash
	$rawid = strtoupper(sha1(uniqid(rand(), true)));
	// Produce the results
	$result = substr($uid, 6, 8);
	$result .= substr($uid, 0, 4);
	$result .= substr(sha1(substr($uid, 3, 3)), 0, 4);
	$result .= substr(sha1(substr(time(), 3, 4)), 0, 4);
	$result .= strtolower(substr($rawid, 10, 12));
	// Return the result
	return $result;
}
</pre>
<p>We produce results looking like this:</p>
<blockquote><p>
1f8fec61-4a6f-9bd5-7f8e-e12325c464c3<br />
1f8fed49-4a6f-9bd5-7f8e-d665dedc0297<br />
1f8fee17-4a6f-9bd5-7f8e-29d1ce3e9e30<br />
1f8feef2-4a6f-9bd5-7f8e-8ce03bebdbdf<br />
1f8fefc7-4a6f-9bd5-7f8e-c22fbedb5390
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://drewjoh.com/blog/2009/07/php-time-based-uuid-function-guid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Converting Ticks to a Timestamp</title>
		<link>http://drewjoh.com/blog/2009/05/converting-ticks-to-a-timestamp/</link>
		<comments>http://drewjoh.com/blog/2009/05/converting-ticks-to-a-timestamp/#comments</comments>
		<pubDate>Sat, 02 May 2009 21:12:39 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[ticks]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://drewjoh.com/blog/?p=57</guid>
		<description><![CDATA[
			
				
			
		
I recently had to deal with a SQLite database that stored the timestamps as ticks.  Having to first research what a tick is, I created a simple function that will convert a tick value to a timestamp or MySQL datetime value since I couldn&#8217;t find anyone else who had done such a thing yet.
You can [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2009%2F05%2Fconverting-ticks-to-a-timestamp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2009%2F05%2Fconverting-ticks-to-a-timestamp%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently had to deal with a SQLite database that stored the timestamps as ticks.  Having to first <a href="http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx">research </a>what a <a href="http://www.flickr.com/photos/eastpole/2299787549/">tick is</a>, I created a simple function that will convert a tick value to a timestamp or MySQL datetime value since I couldn&#8217;t find anyone else who had done such a thing yet.</p>
<p>You can <a href="http://drewjoh.com/downloads/ticks_to_timestamp.zip">download it here</a>.</p>
<p>The only tricky part (aside from figuring out what a tick is) was calculating the number of ticks between 0001-01-01 to 1970-01-01. Also of note: a tick is apparently a popular way to store date/time values for Microsoft.</p>
]]></content:encoded>
			<wfw:commentRss>http://drewjoh.com/blog/2009/05/converting-ticks-to-a-timestamp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bug with Adobe Flash on Mac when uploading files to a redirected URL</title>
		<link>http://drewjoh.com/blog/2008/09/bug-with-adobe-flash-on-mac-when-uploading-files-to-a-redirected-url/</link>
		<comments>http://drewjoh.com/blog/2008/09/bug-with-adobe-flash-on-mac-when-uploading-files-to-a-redirected-url/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 07:00:34 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://drewjoh.com/blog/?p=37</guid>
		<description><![CDATA[
			
				
			
		
Just spent almost the entire day trying to figure out what I was doing wrong when trying out many different flash multi-file uploading widgets. All of them would give me a 302 redirect http error, even when testing locally.
So after much searching and reading and studying&#8230; and finally testing this on my Windows machine (which [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2008%2F09%2Fbug-with-adobe-flash-on-mac-when-uploading-files-to-a-redirected-url%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2008%2F09%2Fbug-with-adobe-flash-on-mac-when-uploading-files-to-a-redirected-url%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Just spent almost the entire day trying to figure out what I was doing wrong when trying out <a href="http://swfupload.org/">many</a> <A href="http://digitarald.de/project/fancyupload/2-0/showcase/photoqueue/">different</a> <a href="http://www.element-it.com/MultiPowUpload.aspx">flash</a> multi-file uploading widgets. All of them would give me a 302 redirect http error, even when testing locally.</p>
<p>So after much searching and reading and studying&#8230; and finally testing this on my Windows machine (which works fine); I&#8217;ve decided this is a bug in Flash 9 for Mac.</p>
<p>There&#8217;s not a problem when it&#8217;s uploaded to a script directly which returns a 200 OK header response first. But when you use a framework that uses mod_rewrite for every URL, it&#8217;s not easy to get around that.</p>
<p>If anyone else has had experience with this I&#8217;d love to hear from you. Very frustrating! Maybe it&#8217;s fixed in the Flash 10 beta?  Maybe it&#8217;s not a bug; it&#8217;s a &#8220;feature&#8221;, right?</p>
<p><a href='http://drewjoh.com/blog/wp-content/uploads/2008/09/picture-1.png'><img src="http://drewjoh.com/blog/wp-content/uploads/2008/09/picture-1-300x208.png" alt="" title="flash-redirect-error-1" width="300" height="208" class="alignnone size-medium wp-image-38" /></a><a href='http://drewjoh.com/blog/wp-content/uploads/2008/09/picture-2.png'><img src="http://drewjoh.com/blog/wp-content/uploads/2008/09/picture-2-300x208.png" alt="" title="flash-redirect-error-2" width="300" height="208" class="alignnone size-medium wp-image-39" /></a></p>
<p><strong>UPDATE:</strong> I went ahead and installed Flash10 hoping for the best, but with no luck.  I was able to contact someone at Adobe who told me the Flash scripts will have to be recompiled in Flash10 to see if Flash10 would help.  So installing Flash10 on my computer won&#8217;t make the scripts any different.</p>
]]></content:encoded>
			<wfw:commentRss>http://drewjoh.com/blog/2008/09/bug-with-adobe-flash-on-mac-when-uploading-files-to-a-redirected-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect all but used subdomains to primary domain using mod_rewrite and CodeIgniter</title>
		<link>http://drewjoh.com/blog/2008/09/redirect-all-but-used-subdomains-to-primary-domain-using-mod_rewrite-and-codeigniter/</link>
		<comments>http://drewjoh.com/blog/2008/09/redirect-all-but-used-subdomains-to-primary-domain-using-mod_rewrite-and-codeigniter/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 20:10:12 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ci]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[subdomain]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://drewjoh.com/blog/?p=35</guid>
		<description><![CDATA[
			
				
			
		
I was recently playing with mod_rewrite and wanting a couple of subdomains to act as subdomains, but all others to redirect back to my site without the leading &#8220;www&#8221;. For example:
www.example.com => example.com
bad.example.com => example.com
api.example.com => api.example.com
Not being a regular expression or mod_rewrite expert (or any resemblance of such), this was a bit of a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2008%2F09%2Fredirect-all-but-used-subdomains-to-primary-domain-using-mod_rewrite-and-codeigniter%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2008%2F09%2Fredirect-all-but-used-subdomains-to-primary-domain-using-mod_rewrite-and-codeigniter%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I was recently playing with mod_rewrite and wanting a couple of subdomains to act as subdomains, but all others to redirect back to my site without the leading &#8220;www&#8221;. For example:</p>
<p>www.example.com => example.com<br />
bad.example.com => example.com<br />
api.example.com => api.example.com</p>
<p>Not being a regular expression or mod_rewrite expert (or any resemblance of such), this was a bit of a challenge. But I did it with the help of a <a href="http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/">mod_rewrite</a> and <a href="http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/">regular expression</a> cheat sheet, as well as the excellent <a href="http://httpd.apache.org/docs/2.0/misc/rewriteguide.html">Apache URL Rewriting Guide</a>.</p>
<p>So here it is for anyone else that could benefit. Just replace the bold parts with your own subdomains (and example with your domain).</p>
<p><strong>Redirect without leading www</strong>:<br />
<code># Redirect deleting leading www to root domain if no specified subdomain is used<br />
RewriteCond %{HTTP_HOST} !^(<strong>subdomain1</strong>|<strong>subdomain2</strong>)\.example\.com$ [NC]<br />
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]<br />
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]<br />
</code></p>
<p><strong>Redirect with leading www:</strong><br />
<code># Redirect adding leading www to root domain if no subdomain is specified<br />
RewriteCond %{HTTP_HOST} !^(<strong>subdomain1</strong>|<strong>subdomain2</strong>|www)\.example\.com$ [NC]<br />
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<br />
</code></p>
<p>If you&#8217;re using <a href="http://codeigniter.com/">CodeIgniter</a> and <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a> for pretty URLs, you&#8217;ll need to be sure to add these subdomains to the list of directories that can be accessed directly.<br />
<code># CodeIgniter writing<br />
RewriteCond $1 !^(index\.php|images|robots\.txt|css|user_files|<strong>subdomain1</strong>|<strong>subdomain2</strong>)<br />
RewriteRule ^(.*)$ /index.php/$1 [L]<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://drewjoh.com/blog/2008/09/redirect-all-but-used-subdomains-to-primary-domain-using-mod_rewrite-and-codeigniter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Serving a large file through PHP without hitting memory_limit</title>
		<link>http://drewjoh.com/blog/2008/09/serving-a-large-file-through-php-without-hitting-memory_limit/</link>
		<comments>http://drewjoh.com/blog/2008/09/serving-a-large-file-through-php-without-hitting-memory_limit/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 05:44:15 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WebDev]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://drewjoh.com/blog/?p=34</guid>
		<description><![CDATA[
			
				
			
		
Ran into a little problem hitting the memory limit for PHP when serving 100MB+ files through a script like:
$file = @fopen($filename,"r");
if ($file)
{
    while(!feof($file))
        {
            print(fread($file, 1024*4));
            flush();
 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2008%2F09%2Fserving-a-large-file-through-php-without-hitting-memory_limit%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdrewjoh.com%2Fblog%2F2008%2F09%2Fserving-a-large-file-through-php-without-hitting-memory_limit%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Ran into a little problem hitting the memory limit for PHP when serving 100MB+ files through a script like:</p>
<p><code>$file = @fopen($filename,"r");<br/><br />
if ($file)<br />
{<br />
    while(!feof($file))<br />
        {<br />
            print(fread($file, 1024*4));<br />
            flush();<br />
            ob_flush();<br />
        }<br />
    @fclose($file);<br />
}</code></p>
<p>Found that you need to call ob_flush() as well as flush() since flush() has <a href="http://us3.php.net/manual/en/function.flush.php">no effect on the buffering scheme of your web server</a>.</p>
<p>Just thought I&#8217;d throw that out there for anyone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://drewjoh.com/blog/2008/09/serving-a-large-file-through-php-without-hitting-memory_limit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
