<?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>Nerd &#187; php</title>
	<atom:link href="http://nerd.vasilis.nl/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://nerd.vasilis.nl</link>
	<description>Vasilis van Gemert</description>
	<lastBuildDate>Mon, 09 May 2011 07:51:38 +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>Using Twitter feeds to feed your Fever</title>
		<link>http://nerd.vasilis.nl/using-twitter-feeds-to-feed-your-fever/</link>
		<comments>http://nerd.vasilis.nl/using-twitter-feeds-to-feed-your-fever/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 18:47:15 +0000</pubDate>
		<dc:creator>Vasilis</dc:creator>
				<category><![CDATA[app]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[nerd]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://nerd.vasilis.nl/?p=85</guid>
		<description><![CDATA[Shaun Inman redefined the feed reader with his brilliant application Fever. The best thing about it, apart from the brilliant user interface, the beautiful layout, the usability, the feel of a native app, is the fact that you can actually use high volume feeds without reading them. The idea is that a link gets more [...]<p><a href="http://nerd.vasilis.nl/using-twitter-feeds-to-feed-your-fever/">Using Twitter feeds to feed your Fever</a> is a post from: <a href="http://nerd.vasilis.nl">Nerd</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shauninman.com/">Shaun Inman</a> redefined the feed reader with his brilliant application <a href="http://feedafever.com/">Fever</a>. The best thing about it, apart from the brilliant user interface, the beautiful layout, the usability, the feel of a native app, is the fact that you can actually <a href="http://feedafever.com/#demo">use high volume feeds</a> without reading them. The idea is that a link gets more interesting when more feeds link to it. So fever has this section called Heat where all these interesting articles are shown.<br />
<span id="more-85"></span></p>
<p>In order to make this work you need many high volume feeds on the same subject. What better place than Twitter for this purpose? I copypasted/wrote a simple script that finds all URL&#8217;s in a <a href="http://twitter.com/statuses/user_timeline/7694572.rss">twitter feed</a>, follows the 301 or 302 redirects until it gets the 200 header, places this URL in a new feed item.</p>
<p>You&#8217;ll need to install <a href="http://nerd.vasilis.nl/code/twitter-feed-fever.zip">this php script</a> somewhere on a server, optionally change some texts around line number 329 and then add this URL as a spark to Fever:</p>
<p>http://yourdomain.com/dir-of-choice/?feed=http://nerd.vasilis.nl/feed/</p>
<p>You should replace <em>http://nerd.vasilis.nl/feed/</em> with the feed you really want to add.<br />
Now if someone can write a bookmarklet that actually lists all linked feeds in a document and gives you the option to copy them, or directly submit them to fever, I&#8217;d be happy to post it here. </p>
<p><em>Go ahead and laugh at my code, I know it sucks. But let me know how to improve it, I&#8217;m willing to learn.</em></p>
<p><a href="http://nerd.vasilis.nl/using-twitter-feeds-to-feed-your-fever/">Using Twitter feeds to feed your Fever</a> is a post from: <a href="http://nerd.vasilis.nl">Nerd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nerd.vasilis.nl/using-twitter-feeds-to-feed-your-fever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A better small URL generator: fitting URL</title>
		<link>http://nerd.vasilis.nl/a-better-small-url-generator-fitting-url/</link>
		<comments>http://nerd.vasilis.nl/a-better-small-url-generator-fitting-url/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 19:28:55 +0000</pubDate>
		<dc:creator>Vasilis</dc:creator>
				<category><![CDATA[nerd]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://nerd.vasilis.nl/?p=31</guid>
		<description><![CDATA[The last few weeks I used my small URL generator a lot. I even bought a new, smaller, domain for it to make it a bit more useful. For Twitter it&#8217;s perfect. But when using it in e-mails I got some complaints. People are happy that all links are clickable (some mail programs cut of [...]<p><a href="http://nerd.vasilis.nl/a-better-small-url-generator-fitting-url/">A better small URL generator: fitting URL</a> is a post from: <a href="http://nerd.vasilis.nl">Nerd</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The last few weeks I used my <a href="http://nerd.vasilis.nl/creating-small-url-generator/">small URL generator</a> a lot. I even bought a new, smaller, domain for it to make it a bit more useful. For Twitter it&#8217;s perfect. But when using it in e-mails I got some complaints. People are happy that all links are clickable (some mail programs cut of every line after an x-amount of characters, leaving many long URL&#8217;s unclickable) but there was no information about the link left in the new, small URL. So I decided to change the script.</p>
<p><span id="more-31"></span></p>
<p>There are now two bookmarklets to call it. One is for <a href="javascript:location.href='http://example.com/a/fitting-url.php?url='%20+%20encodeURIComponent(location.href)" title="drag and drop to your bookmark bar">twit</a>ter and will return a simple small URL. The other one is for e-<a href="javascript:location.href='http://example.com/a/fitting-url.php?url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title)" title="drag and drop to your bookmark bar">mail</a> and will return a url that consists of the title of the page you&#8217;re linking to but it&#8217;s smaller than 66 characters in total, which seems to be enough. (Replace &#8216;http://example.com/a/fitting-url.php&#8217; to your domain and your script name and location in these bookmarklets).</p>
<p>Now, what the script does is first it checks to see if the title is given. If no title, the script assumes you need a small URL. It will check if the original URL is smaller than the result. If so it will return the original URL, selected, ready for you to copy. If not, it will generate a new small URL, write it to the .htacces and return it, selected, ready for you to copy.</p>
<p>If there is a title given the script assumes that you want a URL for e-mail. It will check if the original URL is smaller than 66 characters (the amount of characters I decided to use, you can change that in the script). If so it will return the original URL, selected, ready for you to copy.<br />
If not it will remove all non-alphanumeric characters from the title, convert it to lowerspace, replace spaces with dashes and add it to your domain name, write it to the .htacces and return it, selected, ready for you to copy. And yes, there is a check in here to see if a URL already exists. The URL it returns will always be unique. This is because some sites have lousy titles, like a long sitename at the beginning of a title or the same title on every page.</p>
<p>Enough talking. You can download the <a href="http://vasilis.nl/nerd/code/fitting-url.zip">fitting url script</a> here. Put the script and the a.htaccess (rename it to .htacces) in a directory of your choice, edit the first three lines of fitting-url.php, rename the scriptlets as needed and you&#8217;re ready to go.<br />
I wouldn&#8217;t make the URL to the script available to the public. Being able to change a .htaccess file seems a bit like a security issue&#8230;</p>
<p>Please do leave feedback and don&#8217;t hesitate to correct my PHP. I&#8217;m not a coder, I use google to write scripts.</p>
<p><a href="http://nerd.vasilis.nl/a-better-small-url-generator-fitting-url/">A better small URL generator: fitting URL</a> is a post from: <a href="http://nerd.vasilis.nl">Nerd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nerd.vasilis.nl/a-better-small-url-generator-fitting-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating my own small URL generator</title>
		<link>http://nerd.vasilis.nl/creating-small-url-generator/</link>
		<comments>http://nerd.vasilis.nl/creating-small-url-generator/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 18:22:41 +0000</pubDate>
		<dc:creator>Vasilis</dc:creator>
				<category><![CDATA[nerd]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://nerd.vasilis.nl/?p=1</guid>
		<description><![CDATA[UPDATE: check out the extended version of this script: fitting URL. Since I started twittering a few days ago, and Twitter allows just a few letters for each tweet, the need arose for a small URL generator, a service that replaces a long URL (like http://vasilis.nl/fotos/digitaal/kiki/kiki-2009/in-de-hangmat-05-09018.jpg/) with a small one (like http://vasilis.nl/a/6). I tried two [...]<p><a href="http://nerd.vasilis.nl/creating-small-url-generator/">Creating my own small URL generator</a> is a post from: <a href="http://nerd.vasilis.nl">Nerd</a></p>
]]></description>
			<content:encoded><![CDATA[<p>UPDATE: check out the extended version of this script: <a href="http://nerd.vasilis.nl/a-better-small-url-generator-fitting-url/">fitting URL</a>.</p>
<p>Since I started twittering a few days ago, and Twitter allows just a few letters for each tweet, the need arose for a small URL generator, a service that replaces a long URL (like <a href="http://vasilis.nl/fotos/digitaal/kiki/kiki-2009/in-de-hangmat-05-09018.jpg/">http://vasilis.nl/fotos/digitaal/kiki/kiki-2009/in-de-hangmat-05-09018.jpg/</a>) with a small one (like <a href="http://vasilis.nl/a/6">http://vasilis.nl/a/6</a>). I tried two services (<a href="http://tinyurl.com">tinyurl.com</a> and <a href="http://tr.im">tr.im</a>) but both didn&#8217;t work as I wanted them to work, which is strange because I don&#8217;t want much. Fortunately I&#8217;m a nerd so I just wrote my own short URL service. I&#8217;ll explain what I did so you don&#8217;t have to figure out how to write your own. The other reason I write this blogpost is that I hope somebody will explain me if things can be done easier or more secure: I&#8217;m just googling for solutions, I&#8217;m no programmer. And I really hope that somebody with a math knob can help me count with the base 64 system I choose to use.</p>
<p><span id="more-1"></span></p>
<p><a href="http://nerd.vasilis.nl/code/tinyurl.zip">Here&#8217;s the code</a> for people who rather read code than words.</p>
<p>Put the htacces file and a php file in a directory on your server, make sure that the htaccess file is writable (you probably don&#8217;t want it too writable though) and call the php file like this: http://example.com/a/tinyurl.php<span style="color:red;">?tinyurl=http://www.verylongurl.com/</span></p>
<p>What does this code do? It reads the content of the .htaccess file, reads a commented number inside it, adds 1 to that number, assigns a unique letter/number combination to the URL you want to shorten, writes a redirect rule in htaccess-language and adds that to the original htaccess file. It gives back the new URL in a textfield with all text selected and focus on it. That&#8217;s all I want.</p>
<p>First check if a URL is given<br />
<code><br />
&lt;?php<br />
$redirecturl = $_GET['tinyurl'];<br />
if($redirecturl){<br />
</code><br />
These symbols are allowed, 64 in total<br />
<code><br />
$nummers = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','_');<br />
</code><br />
Get the content of the .htacces file<br />
<code><br />
$oldfile = file_get_contents('.htaccess');<br />
</code><br />
By exploding on &#8216;#&#8217; we get very usefull chunks of data<br />
<code><br />
$aantallinks = explode('#', $oldfile);<br />
</code><br />
$aantallinks[1] is the current number used for the math further on. We need to add 1 for that math<br />
<code><br />
$numlinks = ($aantallinks[1]+1);<br />
</code><br />
Here&#8217;s some math abracadabra. Hope somebody can make a less messier function out of it <sup>(1</sup><br />
<code><br />
if($numlinks>count($nummers)){<br />
$aantalcijfers = floor($numlinks/count($nummers));<br />
$tweedecijfer = ($numlinks-($aantalcijfers*count($nummers)));<br />
$newurl =  $nummers[$aantalcijfers].$nummers[$tweedecijfer];<br />
}<br />
else{<br />
$newurl = $nummers[$aantallinks[1]];<br />
}<br />
</code><br />
The math blob ends here, I can get back to explaining</p>
<p>Here we start writing the new content for the .htacces file<br />
First the coded number we need for the math blob:<br />
<code><br />
$newfile = '#'.$numlinks.'#'."\n";<br />
</code><br />
Next we write back the old redirects<br />
<code><br />
$newfile.= $aantallinks[2]."\n";<br />
</code><br />
Here&#8217;s the new redirect<br />
<code><br />
$newfile.= 'Redirect 301 /a/'.$newurl.' '.$redirecturl;<br />
</code><br />
And here we write the new content into the .htacces file<br />
<code><br />
file_put_contents('.htaccess',$newfile);<br />
</code><br />
Create the feedback HTML<br />
<code><br />
echo '&lt;input type="text" value="http://vasilis.nl/a/'.$newurl.'" id="deinput">';<br />
</code><br />
Some script to select the new URL so you only need to copy it.<br />
<code><br />
echo '&lt;script type="text/javascript">document.getElementById("deinput").select();document.getElementById("deinput").focus();&lt;/script>';<br />
}<br />
</code><br />
Functional code ends here.<br />
The script ends with a disfunctional else statement which makes sure nothing happens when nu URL is given<br />
<code><br />
else{<br />
}<br />
 ?><br />
</code></p>
<p>Now, in an empty .htacces file just write down this:<br />
<code><br />
#0#<br />
</code></p>
<p><sup>(1</sup> My programming and math skills end here. This math blob generates a url with one or two symbols, I don&#8217;t understand how to make it add an extra symbol if necessary (for instance after 64&#215;64=4096 URL&#8217;s). In other words, I want http://vasilis.nl/a/__ to be followed by http://vasilis.nl/a/000 but I don&#8217;t know how to do it.</p>
<p><a href="http://nerd.vasilis.nl/creating-small-url-generator/">Creating my own small URL generator</a> is a post from: <a href="http://nerd.vasilis.nl">Nerd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nerd.vasilis.nl/creating-small-url-generator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

