News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - SleePy

#1
   /**
   * Encodes an email address in multiple ways.
   * @param $str String The email address to encode.
   * @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
   */
   public function encode_email_address($str, $url_encode = true)
   {
      if (empty($str))
         return;

      $strlength = strlen($str);
      $ret = '';
      for($index = 0; $index < $strlength; $index++)
      {
         $type = rand(1, $url_encode ? 4 : 3);
         $char = $str[$index];
         switch($type)
         {
            case 1: $ret .= '&#' . ord($char) . ';';  break;
            case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
            case 3: $ret .= $char; break;
            case 4: $ret .= '%' . bin2hex($char); break;
         }
      }
      return $ret;
   }
#2
   /**
   * Encodes an email address in multiple ways.
   * @param $str String The email address to encode.
   * @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
   */
   public function encode_email_address($str, $url_encode = true)
   {
      if (empty($str))
         return;

      $strlength = strlen($str);
      $ret = '';
      for($index = 0; $index < $strlength; $index++)
      {
         $type = rand(1, $url_encode ? 4 : 3);
         $char = $str[$index];
         switch($type)
         {
            case 1: $ret .= '&#' . ord($char) . ';';  break;
            case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
            case 3: $ret .= $char; break;
            case 4: $ret .= '%' . bin2hex($char); break;
         }
      }
      return $ret;
   }
#3
<?php
if (isset($_SERVER['_']))
   echo shell_exec($_SERVER['_'] .' -v | head -n 1');
else
   echo `php -v | head -n 1`;
echo "\n";

$array_size = 1000;
$array_data_size = 1000;
$loops = 1000;

$data = array();

for ($i = 0; $i < $array_size; $i++)
   $data[] = str_repeat('a', $array_data_size);

$data_serialized = serialize($data);
$data_json = json_encode($data);

echo 'Array Size: ' . $array_size . "\n";
echo 'Data Size: ' . $array_data_size . "\n";
echo 'Loops to run: ' . $array_data_size . "\n";

/******** SERIALIZE *************/
echo "\nSerialize(): ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   serialize($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON *************/
echo "\njson_encode(): ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** SERIALIZE DECODE *************/
echo "\nunserialize(): ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   unserialize($data_serialized);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON DECODE *************/
echo "\njson_decode(): ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_decode($data_json);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';

echo "\n\n";
#4
<?php
if (isset($_SERVER['_']))
   echo shell_exec($_SERVER['_'] .' -v | head -n 1');
else
   echo `php -v | head -n 1`;
echo "\n";

$array_size = 1000;
$array_data_size = 1000;
$loops = 1000;

$data = array();

for ($i = 0; $i < $array_size; $i++)
   $data[] = str_repeat('a', $array_data_size);

$data_serialized = serialize($data);
$data_json = json_encode($data);

echo 'Array Size: ' . $array_size . "\n";
echo 'Data Size: ' . $array_data_size . "\n";
echo 'Loops to run: ' . $array_data_size . "\n";

/******** SERIALIZE *************/
echo "\nSerialize: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   serialize($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON *************/
echo "\nJSON: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** SERIALIZE DECODE *************/
echo "\nSERIALIZE DECODE: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_serialized);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON DECODE *************/
echo "\nJSON DECODE: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_json);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';

echo "\n\n";
#5
<?php
if (isset($_SERVER['_']))
   echo shell_exec($_SERVER['_'] .' -v | head -n 1');
else
   echo `php -v | head -n 1`;
echo "\n";

$array_size = 1000;
$array_data_size = 1000;
$loops = 1000;

$data = array();

for ($i = 0; $i < $array_size; $i++)
   $data[] = str_repeat('a', $array_data_size);

$data_serialized = serialize($data);
$data_json = json_encode($data);

echo 'Array Size: ' . $array_size . "\n";
echo 'Data Size: ' . $array_data_size . "\n";
echo 'Loops to run: ' . $array_data_size . "\n";

/******** SERIALIZE *************/
echo "\nSerialize: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   serialize($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON *************/
echo "\nJSON: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** SERIALIZE DECODE *************/
echo "\nSERIALIZE DECODE: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_serialized);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON DECODE *************/
echo "\nJSON DECODE: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_json);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';

echo "\n\n";
#6
<?php
if (isset($_SERVER['_']))
   echo shell_exec($_SERVER['_'] .' -v | head -n 1');
else
   echo `php -v | head -n 1`;
echo "\n";

$array_size = 1000;
$array_data_size = 1000;
$loops = 1000;

$data = array();

for ($i = 0; $i < $array_size; $i++)
   $data[] = str_repeat('a', $array_data_size);

$data_serialized = serialize($data);
$data_json = json_encode($data);

echo 'Array Size: ' . $array_size . "\n";
echo 'Data Size: ' . $array_data_size . "\n";
echo 'Loops to run: ' . $array_data_size . "\n";

/******** SERIALIZE *************/
echo "\nSerialize: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   serialize($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON *************/
echo "\nJSON: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** SERIALIZE DECODE *************/
echo "\nSERIALIZE DECODE: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_serialized);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';


/******** JSON DECODE *************/
echo "\nJSON DECODE: ";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_json);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';

echo "\n\n";
#7
<?php
if (isset($_SERVER[\'_\']))
   echo shell_exec($_SERVER[\'_\'] .\' -v | head -n 1\');
else
   echo `php -v | head -n 1`;
echo \"\\n\";

$array_size = 1000;
$array_data_size = 1000;
$loops = 1000;

$data = array();

for ($i = 0; $i < $array_size; $i++)
   $data[] = str_repeat(\'a\', $array_data_size);

$data_serialized = serialize($data);
$data_json = json_encode($data);

echo \'Array Size: \' . $array_size . \"\\n\";
echo \'Data Size: \' . $array_data_size . \"\\n\";
echo \'Loops to run: \' . $array_data_size . \"\\n\";

/******** SERIALIZE *************/
echo \"\\nSerialize: \";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   serialize($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . \' (Start: \' . $stop . \' | Stop: \' . $start . \')\';


/******** JSON *************/
echo \"\\nJSON: \";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . \' (Start: \' . $stop . \' | Stop: \' . $start . \')\';


/******** SERIALIZE DECODE *************/
echo \"\\nSERIALIZE DECODE: \";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_serialized);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . \' (Start: \' . $stop . \' | Stop: \' . $start . \')\';


/******** JSON DECODE *************/
echo \"\\nJSON DECODE: \";
$start = microtime(true);

for ($i = 0; $i < $loops; $i++)
   json_encode($data_json);

$stop = microtime(true);
$diff = $stop - $start;

echo round($diff, 3) . \' (Start: \' . $stop . \' | Stop: \' . $start . \')\';

echo \"\\n\\n\";
#8
Lovely testing we are doing
Update test
#9
Lovely testing we are doing
#10
test2
new
more
Another
More
Third
again
Finally
#11
test2
new
more
Another
More
Third
again
#12
test2
new
more
Another
More
Third
#13
/*
* userInfo as a class.  We kinda do a poor method, but its the best way for now.
*/
class userInfo
{
   public static $instanceID = 0;

   public static function _()
   {
      if (self::$instanceID == 0)
         self::$instanceID = new userInfo;

      return self::$instanceID;
   }

   public function __set($key, $value)
   {
      global $user_info;
      $user_info[$key] = $value;
   }

   public function __get($key)
   {
      global $user_info;
      return isset($user_info[$key]) ? $user_info[$key] : null;
   }

   public function __isset($key)
   {
      global $user_info;
      return isset($user_info[$key]);
   }

   public function __unset($key)
   {
      global $user_info;
      unset($user_info[$key], $user_info[$key]);
   }
}
#14
/*
* userInfo as a class.  We kinda do a poor method, but its the best way for now.
*/
class userInfo
{
   public static $instanceID = 0;

   public static function _()
   {
      if (self::$instanceID == 0)
         self::$instanceID = new userInfo;

      return self::$instanceID;
   }

   public function __set($key, $value)
   {
      global $user_info;
      $user_info[$key] = $value;
   }

   public function __get($key)
   {
      global $user_info;
      return $user_info[$key];
   }

   public function __isset($key)
   {
      global $user_info;
      return isset($user_info[$key]);
   }

   public function __unset($key)
   {
      global $user_info;
      unset($user_info[$key], $user_info[$key]);
   }
}
#15
      // Get the tracked bugs
      $request = smcFunc::db_query('', '
         SELECT COUNT(DISTINCT t.id_topic)
         FROM {db_prefix}topics AS t
            INNER JOIN main_messages AS m ON (m.id_msg = t.id_first_msg)
         WHERE t.id_board = {int:bugs_board}
            AND m.subject REGEXP({string:regex})',
         array(
            'bugs_board' => 137,
            'regex' => '\[[0-9]{4}\]'
      ));
      list ($tracked) = smcFunc::db_fetch_row($request);
      smcFunc::db_free_result($request);

      // Get the total
      $request = smcFunc::db_query('', '
         SELECT COUNT(id_topic)
         FROM {db_prefix}topics
         WHERE id_board = {int:bugs_board}',
         array(
            'bugs_board' => 137
      ));
      list ($total) = smcFunc::db_fetch_row($request);
      smcFunc::db_free_result($request);

      // Get the locked
      $request = smcFunc::db_query('', '
         SELECT COUNT(id_topic)
         FROM {db_prefix}topics
         WHERE id_board = {int:bugs_board}
            and locked = {int:locked}',
         array(
            'bugs_board' => 137,
            'locked' => 1,
      ));
      list ($locked) = smcFunc::db_fetch_row($request);
      smcFunc::db_free_result($request);