<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:refactormycode.com,2007:users159</id>
  <link type="application/atom+xml" href="http://refactormycode.com/users/159" rel="self"/>
  <title>Meir</title>
  <updated>Sun Oct 28 10:21:35 +0000 2007</updated>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor614</id>
    <published>2007-10-28T10:21:35+00:00</published>
    <title>[PHP] On Resolving TinyURLS to the desination URL</title>
    <content type="html">

&lt;pre&gt;&amp;lt;?php

$url     = 'http://tinyurl.com/'.$_GET['n'];
$headers = get_headers($url, true);

echo $headers['Location'][0];

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Meir</name>
      <email></email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/111-resolving-tinyurls-to-the-desination-url/refactors/614" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor455</id>
    <published>2007-10-17T16:46:59+00:00</published>
    <title>[PHP] On Random password</title>
    <content type="html">&lt;p&gt;My new code is faster, a simple benchmark test:&lt;/p&gt;

&lt;pre&gt;Meir:

&amp;lt;?php

function random_password($length = 6)
{
	$characters = implode('', array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)));
	$characters = str_repeat(str_shuffle($characters), $length &amp;gt; 62 ? ceil($length/62) : 1);
	return substr($characters, 0, $length);
}

$start = array_sum(explode(' ', microtime()));

for ($i = 0; $i &amp;lt; 10000; $i++) {
	random_password(100);
}

$end   = array_sum(explode(' ', microtime()));
$final = $end - $start;

echo number_format($final, 4, '.', '').' seconds'; // 0.5664 seconds

?&amp;gt;

richardhealy:

&amp;lt;?php

function random_password($length = 6)
{
	while (strlen($key) &amp;lt; $length) $key .= rand(0,1) ? chr(rand(48, 57)) : chr(rand(97, 122));
	return $key;
}

$start = array_sum(explode(' ', microtime()));

for ($i = 0; $i &amp;lt; 10000; $i++) {
	random_password(100);
}

$end   = array_sum(explode(' ', microtime()));
$final = $end - $start;

echo number_format($final, 4, '.', '').' seconds'; // 3.3504 seconds

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Meir</name>
      <email></email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/90-random-password/refactors/455" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Code90</id>
    <published>2007-10-17T12:14:40+00:00</published>
    <updated>2008-08-16T16:49:28+00:00</updated>
    <title>[PHP] Random password</title>
    <content type="html">&lt;p&gt;:)&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php

function random_password($length = 6)
{
	$characters = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
	shuffle($characters);
	return implode('', array_slice($characters, 0, $length));
}

echo random_password();

?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Meir</name>
      <email>no-email@refactormycode.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/90-random-password" rel="alternate"/>
  </entry>
</feed>
