<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Generating UUIDs with CakePHP</title>
	<atom:link href="http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:12:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-98259</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Mon, 14 Jul 2008 15:00:17 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-98259</guid>
		<description>@Peter: It looks like they use a hash function to generate such IDs, but I don&#039;t know which hash function they actually use...</description>
		<content:encoded><![CDATA[<p>@Peter: It looks like they use a hash function to generate such IDs, but I don&#8217;t know which hash function they actually use&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-97920</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 11 Jul 2008 17:32:07 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-97920</guid>
		<description>Hi,  

Do you know how YouTube is getting their unique id?
http://www.youtube.com/watch?v=_RSaYVgd7yk
More hash??

Any help would be appreciated.  Thanks.</description>
		<content:encoded><![CDATA[<p>Hi,  </p>
<p>Do you know how YouTube is getting their unique id?<br />
<a href="http://www.youtube.com/watch?v=_RSaYVgd7yk" rel="nofollow">http://www.youtube.com/watch?v=_RSaYVgd7yk</a><br />
More hash??</p>
<p>Any help would be appreciated.  Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-76708</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sun, 23 Mar 2008 16:42:01 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-76708</guid>
		<description>@PD: Thanks for your explanations!</description>
		<content:encoded><![CDATA[<p>@PD: Thanks for your explanations!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PD</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-76432</link>
		<dc:creator>PD</dc:creator>
		<pubDate>Sat, 22 Mar 2008 18:42:50 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-76432</guid>
		<description>@Yevgeny:  It&#039;s not that the 36-char format isn&#039;t URL safe; it&#039;s all ascii letters, numbers, &amp; dashes, so it&#039;s inherently URL safe.  It&#039;s just long.

The 22-char format comes from running a few operations on it.  First, you do a quick str_replace to pull the &quot;-&quot;&#039;s out.  They&#039;re always in the same place, so why have them there?

Then, you can run &quot;pack(&#039;H*&#039;,$string)&quot; on the thing, where $string is the result of the str_replace.  That will code the ASCII down to a much shorter binary value.  However, that binary is most definitely *not* URL safe; it&#039;s binary.

So, you do a base64_encode on the thing.  That results in a new ASCII string, 24 characters in length.  The last two characters will always be &quot;==&quot; padding, however, because of the size of the binary you get from pack().

Finally, you can get 22 characters by rtrimming those &#039;=&#039; chars out.

All in all, looks kinda like rtrim(base64_encode(pack(&#039;H*&#039;,r(&#039;-&#039;,&#039;&#039;,$uuid))),&#039;=&#039;)
where $uuid is your original 36-char uuid.

None of those opperations are lossy, so you can always reverse back and get the same UUID again:
unpack(&#039;H*&#039;, base64_decode($shortuuid . &#039;==&#039;))
will give you back the original UUID, but without the dashes.  It&#039;s easy enough to put those back in, by chunking that string into groups of 4, and combining the first 2 and last 3 elements of the array, and joining that result with dashes.  Or maybe a quick preg_replace.</description>
		<content:encoded><![CDATA[<p>@Yevgeny:  It&#8217;s not that the 36-char format isn&#8217;t URL safe; it&#8217;s all ascii letters, numbers, &amp; dashes, so it&#8217;s inherently URL safe.  It&#8217;s just long.</p>
<p>The 22-char format comes from running a few operations on it.  First, you do a quick str_replace to pull the &#8220;-&#8221;&#8216;s out.  They&#8217;re always in the same place, so why have them there?</p>
<p>Then, you can run &#8220;pack(&#8216;H*&#8217;,$string)&#8221; on the thing, where $string is the result of the str_replace.  That will code the ASCII down to a much shorter binary value.  However, that binary is most definitely *not* URL safe; it&#8217;s binary.</p>
<p>So, you do a base64_encode on the thing.  That results in a new ASCII string, 24 characters in length.  The last two characters will always be &#8220;==&#8221; padding, however, because of the size of the binary you get from pack().</p>
<p>Finally, you can get 22 characters by rtrimming those &#8216;=&#8217; chars out.</p>
<p>All in all, looks kinda like rtrim(base64_encode(pack(&#8216;H*&#8217;,r(&#8216;-&#8217;,&#8221;,$uuid))),&#8217;=')<br />
where $uuid is your original 36-char uuid.</p>
<p>None of those opperations are lossy, so you can always reverse back and get the same UUID again:<br />
unpack(&#8216;H*&#8217;, base64_decode($shortuuid . &#8216;==&#8217;))<br />
will give you back the original UUID, but without the dashes.  It&#8217;s easy enough to put those back in, by chunking that string into groups of 4, and combining the first 2 and last 3 elements of the array, and joining that result with dashes.  Or maybe a quick preg_replace.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-10812</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 28 Aug 2007 13:23:51 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-10812</guid>
		<description>@Yevgeny: I&#039;m sorry, but I don&#039;t know the answer to your question... It&#039;s the first time I hear about this 22 character format ;-)</description>
		<content:encoded><![CDATA[<p>@Yevgeny: I&#8217;m sorry, but I don&#8217;t know the answer to your question&#8230; It&#8217;s the first time I hear about this 22 character format ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yevgeny Tomenko</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-10803</link>
		<dc:creator>Yevgeny Tomenko</dc:creator>
		<pubDate>Tue, 28 Aug 2007 07:19:28 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-10803</guid>
		<description>@cakebaker: I have one question. May be you know that in rails exists plugin that make same thing for ror projects(http://tools.assembla.com/breakout/wiki/FreeSoftware).
But it manipulate with 22 length url sage uuid instead of 36 bytes as in cake. So why 22 buty is more url safe than 36?</description>
		<content:encoded><![CDATA[<p>@cakebaker: I have one question. May be you know that in rails exists plugin that make same thing for ror projects(http://tools.assembla.com/breakout/wiki/FreeSoftware).<br />
But it manipulate with 22 length url sage uuid instead of 36 bytes as in cake. So why 22 buty is more url safe than 36?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhimanyu Grover</title>
		<link>http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/comment-page-1/#comment-10747</link>
		<dc:creator>Abhimanyu Grover</dc:creator>
		<pubDate>Tue, 21 Aug 2007 03:16:04 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/08/20/generating-uuids-with-cakephp/#comment-10747</guid>
		<description>Nice and handy.. Thanks :)</description>
		<content:encoded><![CDATA[<p>Nice and handy.. Thanks :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

