<?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>phoenixheart - portfolio &#38; more &#187; twitter</title>
	<atom:link href="http://www.phoenixheart.net/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phoenixheart.net</link>
	<description>phoenixheart - portfolio &#38; more</description>
	<lastBuildDate>Wed, 23 Mar 2011 09:47:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<script type="text/javascript">
if (typeof Meebo == "undefined") {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){

	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'phoenixheartnet_bo16we'});	}</script>	<item>
		<title>Write your own URL shortener</title>
		<link>http://www.phoenixheart.net/2009/06/write-your-own-url-shortener/</link>
		<comments>http://www.phoenixheart.net/2009/06/write-your-own-url-shortener/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 11:53:37 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[url shorten]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=305</guid>
		<description><![CDATA[With Twitter and its 140 characters limit leading all the trends, URL shortening services are in extremely high demand. We have seen TinyURL in the past, now Bit.ly, Is.gd, Tr.im and dozens of others are joining the party to share the cake. Honestly saying, to me they&#8217;re all the same (except for ➡.ws for its [...]]]></description>
			<content:encoded><![CDATA[<p>With Twitter and its 140 characters limit leading all the trends, URL shortening services are in extremely high demand. We have seen <a href="http://tinyurl.com">TinyURL</a> in the past, now <a href="http://bit.ly">Bit.ly</a>, <a href="http://is.gd">Is.gd</a>, <a href="http://tr.im">Tr.im</a> and dozens of others are joining the party to share the cake. Honestly saying, to me they&#8217;re all the same (except for <a href="http://➡.ws">➡.ws</a> for its cool name). With that being said however, it is interesting how they are doing it out there &#8211; what mechanism / algorithm / buzzword-here?</p>
<p>I curiously did some &#8220;research&#8221;es (well, another buzzword), and it seems in order to create the shorten URLs they are following the same steps:</p>
<ol>
<li>Insert the original (long) URL into the database</li>
<li>Get the insert ID. If the URL already exists, take its row ID. Let&#8217;s say we got 123456.</li>
<li>Convert the ID 123456 into something even shorter, let&#8217;s say &#8220;am4k&#8221;</li>
<li>Make use of Apache&#8217;s mod_rewrite so that any request to <em>http://host.com/am4k</em> will reach <em>http://host.com/redir_script.php?code=am4k</em> instead.</li>
<li>In redir_script.php the value &#8220;am4k&#8221; is converted back into base10&#8242;s 123456 and the corresponding URL is queried back from database</li>
<li>If a URL is found, redirect the request to it.</li>
</ol>
<p>It is simple enough&#8230; except for step 3 and 4. Which conversion is there, and how is the .htaccess written? <span id="more-305"></span></p>
<p>So I did some other <em>buzzword-here</em>, and it turned out <a href="http://en.wikipedia.org/wiki/Base36">base36 encoding</a> is taking place. According to Wikipedia, &#8220;the choice of 36 is convenient in that the digits can be represented using the <a class="mw-redirect" title="Hindu-Arabic numerals" href="http://en.wikipedia.org/wiki/Hindu-Arabic_numerals">Arabic numerals</a> 0-9 and the <a title="Latin alphabet" href="http://en.wikipedia.org/wiki/Latin_alphabet">Latin letters</a> A-Z&#8221;. There is a handy conversion table too:</p>
<table style="border:1px solid #ccc">
<tbody>
<tr align="right">
<th>Decimal</th>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
</tr>
<tr align="right">
<th>Base 36</th>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>A</td>
<td>B</td>
<td>C</td>
<td>D</td>
<td>E</td>
<td>F</td>
<td>G</td>
<td>H</td>
</tr>
<tr>
<td colspan="19"></td>
</tr>
<tr align="right">
<th>Decimal</th>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
<td>29</td>
<td>30</td>
<td>31</td>
<td>32</td>
<td>33</td>
<td>34</td>
<td>35</td>
</tr>
<tr>
<th>Base 36</th>
<td>I</td>
<td>J</td>
<td>K</td>
<td>L</td>
<td>M</td>
<td>N</td>
<td>O</td>
<td>P</td>
<td>Q</td>
<td>R</td>
<td>S</td>
<td>T</td>
<td>U</td>
<td>V</td>
<td>W</td>
<td>X</td>
<td>Y</td>
<td>Z</td>
</tr>
</tbody>
</table>
<p>Even better, PHP takes only one line of code to convert between decimal and base36, as shown on the same Wiki page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$base_36</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ZAQFG&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Sample Base 36 Number</span>
<span style="color: #000088;">$decimal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;7654321&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Sample Decimal Number</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base_36</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Outputs $base_36 converted to decimal</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decimal</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Outputs $decimal converted to base 36</span></pre></td></tr></table></div>

<p>In our example, <em>123456</em> will be converted into its tidy equivalent base36 <em>2n9c</em> (not <em>am4k</em>, my very bad).</p>
<p>As for the mod_rewrite thing, as I am not a .htaccess master, I copied this thing that has been working perfectly so far from <a href="http://www.codeigniter.com">CodeIgniter</a> forum:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RewriteEngine On
RewriteBase <span style="color: #339933;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Checks to see if the user is attempting to access a valid file,
</span><span style="color: #666666; font-style: italic;">#such as an image or css document, if this isn't true it sends the
</span><span style="color: #666666; font-style: italic;">#request to redir.php.
</span>RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>f
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>d
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ redir<span style="color: #339933;">.</span>php?code<span style="color: #339933;">=</span>$<span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#91;</span>L<span style="color: #009900;">&#93;</span>
&nbsp;</pre></td></tr></table></div>

<p>With this, all of the hardest parts are done, leave the remains being simple MySQL database, queries and HTML form handling. To save you from getting boring, I&#8217;ll omit it.</p>
<p><a href="http://u.phoenixheart.net/" class="demo">Instead, let&#8217;s see a demo here</a><a href="http://u.phoenixheart.net/source.zip" class="download" rel="nofollow">The source code of the demo are can be downloaded from the same server</a><br />
<br class="clear" /></p>
<img style='display:none' id="post-305-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/06/write-your-own-url-shortener/',title:'Write your own URL shortener',tweet:'With Twitter and its 140 characters limit leading all the trends, URL shortening services are in ext',description:'With Twitter and its 140 characters limit leading all the trends, URL shortening services are in ext'})"><script type='text/javascript'>document.getElementById("post-305-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/06/write-your-own-url-shortener/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Code snippet #1 &#8211; Get Latest Tweet</title>
		<link>http://www.phoenixheart.net/2009/05/code-snippet-1-get-latest-tweet/</link>
		<comments>http://www.phoenixheart.net/2009/05/code-snippet-1-get-latest-tweet/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:29:41 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=271</guid>
		<description><![CDATA[Ok so I&#8217;m following some guy&#8217;s recommendation (sorry, I really forgot his name as well as his blog address) to try to post something useful even when I don&#8217;t have anything to blog about. How about a series of code snippets? To some they are old but to the others they may help &#8211; for [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so I&#8217;m following some guy&#8217;s recommendation (sorry, I really forgot his name as well as his blog address) to try to post something useful even when I don&#8217;t have anything to blog about. How about a series of code snippets? To some they are old but to the others they may help &#8211; for example to myself two months later that is.</p>
<div class="snipper-name">
<h3>Code Snippet #1 &#8211; Get Latest Tweet</h3>
</div>
<div class="snipper-purpose">
<h3>Purpose</h3>
<ul>
<li>Get your latest tweet from Twitter to show up instead of an unconvincing &#8220;Follow Me&#8221; link -or-</li>
<li>Display your idol&#8217;s latest tweet to wow your readers</li>
</ul>
</div>
<div class="snipper-require">
<h3>Requirements</h3>
<ul>
<li>A Twitter account. Don&#8217;t have one? Head <a href="http://twitter.com/signup">here</a> or <a href="http://www.iliveunderarock.com/">here</a></li>
</ul>
</div>
<p><span id="more-271"></span></p>
<div class="snipper-code">
<h3>The Code</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// the function</span>
<span style="color: #009933; font-style: italic;">/**
 * @desc Get latest tweet from a Twitter account
 * @param string The account's username
 * @return string The tweet
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_latest_tweet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://search.twitter.com/search.atom?q=from:<span style="color: #006699; font-weight: bold;">$username</span>&amp;rpp=1&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;content type=&quot;html&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;/content&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// now use it</span>
<span style="color: #000088;">$my_username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Phoenixheart'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> get_latest_tweet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</div>
<img style='display:none' id="post-271-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/05/code-snippet-1-get-latest-tweet/',title:'Code snippet #1 &#8211; Get Latest Tweet',tweet:'Ok so I&#8217;m following some guy&#8217;s recommendation (sorry, I really forgot his name as well a',description:'Ok so I&#8217;m following some guy&#8217;s recommendation (sorry, I really forgot his name as well a'})"><script type='text/javascript'>document.getElementById("post-271-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/05/code-snippet-1-get-latest-tweet/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>To twitter or not to twitter</title>
		<link>http://www.phoenixheart.net/2009/02/to-twitter-or-not-to-twitter/</link>
		<comments>http://www.phoenixheart.net/2009/02/to-twitter-or-not-to-twitter/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 02:50:51 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Blahblahblah]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=221</guid>
		<description><![CDATA[Like almost everyone here, I have my Twitter account too, which I created long ago. Thing is, I don&#8217;t exactly know what&#8217;s it about (what a shame). Thaya he told me that it&#8217;s some kind of chatting, just less annoying and more useful, but still I don&#8217;t understand how people can keep a web page [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">L</span>ike almost everyone here, I have <a href="https://twitter.com/Phoenixheart">my Twitter account</a> too, which I created long ago. Thing is, I don&#8217;t exactly know what&#8217;s it about (what a shame). <a href="https://twitter.com/madeinthayaland">Thaya</a> he told me that it&#8217;s some kind of chatting, just less annoying and more useful, but still I don&#8217;t understand how people can keep a web page open like 8 hours a day and type in such as &#8220;I&#8217;m reading this {TinyURL}&#8221;, &#8220;I&#8217;m listening to this {TinyURL}&#8221; <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So recently I see more and more people are following me on Twitter. This is like that, maybe, I should seriously start twittering and let them know that I should start twittering and let them know that I should start&#8230; oh well.</p>
<p>By having someone &#8220;following&#8221; you and reading your updates, kind of, make you feel more important. I don&#8217;t think I can get used to it (easily).</p>
<p>But what do you think? Are you <a href="https://twitter.com/Phoenixheart">following me</a> on Twitter? <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img style='display:none' id="post-221-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/02/to-twitter-or-not-to-twitter/',title:'To twitter or not to twitter',tweet:'Like almost everyone here, I have my Twitter account too, which I created long ago. Thing is, I don&',description:'Like almost everyone here, I have my Twitter account too, which I created long ago. Thing is, I don&'})"><script type='text/javascript'>document.getElementById("post-221-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/02/to-twitter-or-not-to-twitter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 2/17 queries in 0.007 seconds using disk
Object Caching 336/374 objects using disk

Served from: www.phoenixheart.net @ 2012-02-04 02:41:32 -->
