<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users43</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/43" rel="self"/>
  <title>leighmac</title>
  <updated>Wed Oct 03 01:55:07 -0700 2007</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor234</id>
    <published>2007-10-03T01:55:07-07:00</published>
    <title>[PHP] On ISBN10 to ISBN13</title>
    <content type="html">&lt;p&gt;Oh my goodness Mike you optimized my codes :) I like the loop unrolling implementation very much and the pre compute is brilliant great job!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>leighmac</name>
      <email>leighmac@phpnotepad.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/33-isbn10-to-isbn13/refactors/234" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor186</id>
    <published>2007-10-01T20:58:06-07:00</published>
    <title>[PHP] On Content Page Include</title>
    <content type="html">&lt;p&gt;I cannot get my php codes to highlight.. :( I must need need to include the opening and closing tags I will try again. &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;## php  [php]

&amp;lt;?php

  function content_include($page, $path = '') 
  {
    if (!file_exists($path.$page.'.php') or !preg_match('{^[a-z0-9-_]{1,32}$}', strtolower($page))) 
    {
      # Can't find the page or funky filename must not be allowable
      return false;
    }
    
    include $path.$page.'.php';
    
    return true;
  
   }
   
  
  if(!content_include($_GET['id'], 'pages/')) { include 'pages/no_page_error.php'; };


?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>leighmac</name>
      <email>leighmac@phpnotepad.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/42-content-page-include/refactors/186" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor150</id>
    <published>2007-10-01T07:00:29-07:00</published>
    <title>[PHP] On ISBN10 to ISBN13</title>
    <content type="html">&lt;p&gt;I would write that function like this. I just changed a few things to make it easier to read and use for me and removed the error message out of the function making it more flexible IMO.&lt;/p&gt;

&lt;pre&gt;## Goes in your function lib [php]

function isbn10_to_13($isbn) 
 {
   if (!preg_match('{^[0-9]{10}$}', $isbn)) 
   { 
     # number is not 10 digits
     return false;
   } 
   
   # prefix 978 (bookland flag) to isbn and drop last digit (check digit)
   $isbn =  '978'.substr($isbn,0,9);
       
   $sum_of_digits = 0;
   $digit_postion = 0;
   
   # loop over each isbn digit
   foreach (str_split($isbn) as $digit)
   {
     # multiply each digit by its associated weighting factor (1 or 3)
     # and add them all together 
     $sum_of_digits += $digit * (($digit_postion % 2 == 0) ? 1 : 3);
     $digit_postion ++;
   }
   
   # divide the sum_of_digits by the modulus number (10) to find the remainder
   # and then minus 10 to get the check digit
   $check_digit = 10 - ($sum_of_digits % 10);
    
   # return isbn with check_digit
   return $isbn.$check_digit;    
  }   


## could use it like this in your template [php]

$converted_to_isbn13 = isbn10_to_13(&amp;quot;0901690546&amp;quot;);
 
 if($converted_to_isbn13) {
 
   echo $converted_to_isbn13;
 
 } else {
 
   echo 'Opps please check your digits!';
 
 }&lt;/pre&gt;</content>
    <author>
      <name>leighmac</name>
      <email>leighmac@phpnotepad.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/33-isbn10-to-isbn13/refactors/150" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor145</id>
    <published>2007-09-30T23:05:56-07:00</published>
    <title>[JavaScript] On Rating system for this site</title>
    <content type="html">&lt;p&gt;No worries :), The only things I could suggest to the next refactorer might be to break up the constructor a little bit more.. add a couple of constants for the strings and some sort of error handling.. if no one else posts I'll have a crack at that.&lt;/p&gt;

&lt;pre&gt;## Javascript [javascript]
// my codes did have an error. line 7 should read 
var rating = new Rating('rating_'+id, rating, {&lt;/pre&gt;</content>
    <author>
      <name>leighmac</name>
      <email>leighmac@phpnotepad.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/29-rating-system-for-this-site/refactors/145" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor132</id>
    <published>2007-09-30T08:09:58-07:00</published>
    <title>[JavaScript] On Rating system for this site</title>
    <content type="html">&lt;p&gt;I like your ratings class it's easy to understand :). I'm not good enough at javascript to improve your class. But you might improve your view with something like this.&lt;/p&gt;

&lt;pre&gt;
## Javascript [javascript]

var Rating = Class.create();
  // removed to make post more tidy
};

// Ratings helper for view
function rating_ui(id, rating, title) { 
  var rating = new Rating('rating_'+id, 0, {
    onClick: function(rating) {
      $('rating_'+id+'_spinner').show();
      $('rating_'+id+'_count').hide();
      this.disable();
      new Ajax.Request('/codes/'+title+'/refactors/'+id+';rate', {
        parameters: 'rating=' + rating,
        onComplete: function() {
          $('rating_'+id+'_spinner').hide();
          $('rating_'+id+'_count').show();
        }
      });
    }
  });  
}

## View [html_rails]

&amp;lt;div class=&amp;quot;rating&amp;quot;&amp;gt;
  &amp;lt;span id=&amp;quot;rating_97&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;
  &amp;lt;img alt=&amp;quot;Spinner&amp;quot; class=&amp;quot;spinner&amp;quot; id=&amp;quot;rating_97_spinner&amp;quot; src=&amp;quot;spinner.gif&amp;quot; style=&amp;quot;display:none&amp;quot; /&amp;gt;
  &amp;lt;span id=&amp;quot;rating_97_count&amp;quot; class=&amp;quot;count&amp;quot;&amp;gt;
    No rating. You haven't rated it!
  &amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
  rating_ui(97, 0, '16-extracting-style-from-a-css-file')
&amp;lt;/script&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>leighmac</name>
      <email>leighmac@phpnotepad.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/29-rating-system-for-this-site/refactors/132" rel="alternate"/>
  </entry>
</feed>

